Problem with saving table in a method

Please login with a confirmed email address before reporting spam

Hi everyone, I'm currently working on creating small scripts using methods in the Application Builder to simplify the export of data in the Model Builder. I call the equivalent method in the Model Builder to get it running.

Right now, I'm trying to save a table using the following script and ran into two issues:

model.result().evaluationGroup().create("eg10", "EvaluationGroup"); model.result().evaluationGroup("eg10").set("data", "dset1"); model.result().evaluationGroup("eg10").label("Iron Losses"); model.result().evaluationGroup("eg10").create("int1", "IntSurface"); model.result().evaluationGroup("eg10").feature("int1").label("Surface Iron Losses"); model.result().evaluationGroup("eg10").feature("int1").set("intvolume", true); model.result().evaluationGroup("eg10").feature("int1").selection().named("sel15"); model.result().evaluationGroup("eg10").feature("int1").set("expr", new String[]{"rmm.Qh"}); model.result().evaluationGroup("eg10").feature("int1").set("descr", new String[]{"Volumetric loss density, electromagnetic"}); model.result().evaluationGroup("eg10").feature("int1").set("unit", new String[]{"W/m"}); model.result().evaluationGroup("eg10").feature("int1").setIndex("expr", "rmm.Qh*L", 0); model.result().evaluationGroup("eg10").feature("int1").setIndex("descr", "P_iron_MOD", 0); model.result().evaluationGroup("eg10").run();
//model.result().evaluationGroup("eg10").save("Z:\Simulationsergebnisse\Iron_losses.txt");
//model.result().evaluationGroup("eg10").save("C:\Users\kzt\Documents\Iron_losses.txt");
//model.result().evaluationGroup("eg10").save("C:\Temp\Iron_losses.txt");

1.) Everything works fine up to the last commented-out line. Unfortunately, I can’t save to any of the specified directories and I always get the following error:

"Cannot open file for writing. - Filename: Z:\Simulationsergebnisse\Iron_losses.txt (with all the other paths as well) - Table: Iron Losses"

However, I can manually save to the paths via mouse click.

2.) Is there an alternative to the following line?

"model.result().evaluationGroup("eg10").feature("int1").selection().named("sel15");"

I’d like to use the name of the selection instead of the index number 15. When I add or remove selections, the index changes, so "15" may no longer refer to the correct selection.

Best regards and many thanks in advance for your help!

Tobias Zeller


2 Replies Last Post Apr 29, 2025, 5:07 a.m. EDT
Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 hours ago Apr 29, 2025, 2:39 a.m. EDT
  1. For security reasons, methods by default have limited access to the file system. You can change this in Preferences > Methods and Java Libraries > File system access.
  2. The argument to selection().named() is the tag of a selection. This is the tag that you used when creating the selection (or was it created for you at some point)? In the former case, you can store the selection a variable, let's call it SEL, and pass SEL.tag() as argument to selection().named().
1. For security reasons, methods by default have limited access to the file system. You can change this in Preferences > Methods and Java Libraries > File system access. 2. The argument to selection().named() is the tag of a selection. This is the tag that you used when creating the selection (or was it created for you at some point)? In the former case, you can store the selection a variable, let's call it SEL, and pass SEL.tag() as argument to selection().named().

Please login with a confirmed email address before reporting spam

Posted: 3 hours ago Apr 29, 2025, 5:07 a.m. EDT
  1. For security reasons, methods by default have limited access to the file system. You can change this in Preferences > Methods and Java Libraries > File system access.
  2. The argument to selection().named() is the tag of a selection. This is the tag that you used when creating the selection (or was it created for you at some point)? In the former case, you can store the selection a variable, let's call it SEL, and pass SEL.tag() as argument to selection().named().

Dear Mr. Andersson, First of all, thank you very much for your reply. Unfortunately, I still have one remaining question.

  1. I’m not entirely sure how to interpret your answer. Is the tag the same as the label?

In my case, I have nearly 20 different selections (see attachment), and “sel15,” which is the 15th selection, is the one I need. If the label is not the tag, is there a way to change or view the tag of a selection? Additionally, when I create a new explicit selection, I don’t see an option for assigning a "tag."

If I determine my tag name—for example, if the tag name is “test”—what would my code look like? Would it be something like this? "model.result().evaluationGroup("eg10").feature("int1").selection().test.tag();"

Best regards and thanks a lot Tobias Zeller

>1. For security reasons, methods by default have limited access to the file system. You can change this in Preferences > Methods and Java Libraries > File system access. >2. The argument to selection().named() is the tag of a selection. This is the tag that you used when creating the selection (or was it created for you at some point)? In the former case, you can store the selection a variable, let's call it SEL, and pass SEL.tag() as argument to selection().named(). Dear Mr. Andersson, First of all, thank you very much for your reply. Unfortunately, I still have one remaining question. 2. I’m not entirely sure how to interpret your answer. Is the tag the same as the label? In my case, I have nearly 20 different selections (see attachment), and “sel15,” which is the 15th selection, is the one I need. If the label is not the tag, is there a way to change or view the tag of a selection? Additionally, when I create a new explicit selection, I don’t see an option for assigning a "tag." If I determine my tag name—for example, if the tag name is “test”—what would my code look like? Would it be something like this? "model.result().evaluationGroup("eg10").feature("int1").selection().test.tag();" Best regards and thanks a lot Tobias Zeller

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.