Photonics

Photonics

Topics related to Lumerical and more.

How to add script to structure group in script

    • mwhitby
      Subscriber

      I'm working on scripting a simulation. Within the structure group edit window there is a tab for Script. I would like to add script to that script tab within my master script for the program where the structure group is defined. I've tried just putting the script I want under the part where I define the structure group and the user properties with no set commands or anything, also I've tried putting set("script", the script that I want); under the part where I define the structure group and the user properties. I have construction group selected in the code too.

    • Guilin Sun
      Ansys Employee
      Usually you can either directly modify an existing structure group, or write new script in the master file. Seldom people amend the script in the structure every time you run the master file. While it seems easier using scripting, I personally prefer to directly use/modify the structure group, manually check the material fittings and also make sure the structure is what you expect. There are chances that some structure/settings are not complete and it might be difficult to find the issue. When you have hundreds of line, maintaining it can also be challenge.

      Please refer some examples:
      addstructuregroup - Script command
      adduserprop - Script command
      Structure Groups - Simulation object
    • mwhitby
      Subscriber
      My main goal is to script the whole program in the master file so that I can run it in a loop to update some parameters. I think I may need to put the script in the master file in order for the loops to run and update the structures with the new parameters each time (I have built in some ways to ensure the geometry is valid from the new parameters). If I wanted to do this how would I go about it?
      Originally I tried:
      addstructuregroup;
      set("name","strt_wvg");
      deleteall;
      then posted all of my script here with no special anything.

      However, after I ran the code and checked in the edit box I did not see the script there and I got errors from running the script. Then I tried to put the script into a set command but that didn't work either. Do you have any suggestions on how to get this to work? Thank you!

    • Guilin Sun
      Ansys Employee
      Unfortunately it does not work that way. Please refer the links above. For example, the script inside the group should be "myscript" like this
      addstructuregroup;
      adduserprop("radius",2,0.5e-6);
      myscript = "addcircle; \n";
      myscript = myscript + "copy(1e-6); \n";
      myscript = myscript + "selectall; \n";
      myscript = myscript + "set(\"radius\",radius);";
      set("name","dimer");
      set("script",myscript);
      If you only need to change some parameters in the structure group, it might be better to directly access such parameters directly using the master script, for well established groups. For example:
      setnamed("mygroup","parameter_name",parameter_value)

      In addition, you may need to get more information for the existing groups.
    • mwhitby
      Subscriber
      Thanks for your help!
Viewing 4 reply threads
  • The topic ‘How to add script to structure group in script’ is closed to new replies.