Ansys Learning Forum Forums Discuss Simulation Photonics getindex is not a valid function or variable name Reply To: getindex is not a valid function or variable name

Amrita Pati
Ansys Employee

Hi Rabeeya,

The user-defined scripting option in the Optimization Utility has limited capabilities similar to the scripting options within model, analysis, and structure groups. Some functions won't work from within these environments. 

I believe there is a workaround, but I haven't tested it fully myself. You can try and let me know if there are any issues. The getindex script works within "model", the root class in the objects tree. 

  1. You can edit "model".
  2. Go to "Analysis" and then "Variables".
  3. In the Results section, define a varaible called "n".
  4. Copy and paste the getindex commands in the Analysis-->Script of "model".
  5. Now model should return "n" as a result after FDTD is run:
  6. Moving on to the optimization task, in the "Figures of merit", you can select "n" as shown below, in addition to any other result you might have:
  7. Next, you can use this "n" in the user defined fom section directly. A random code is shown as an example below:

Please feel free to let me know if you have any questions.

Regards,
Amrita