Electronics

Electronics

Topics related to HFSS, Maxwell, SIwave, Icepak, Electronics Enterprise and more.

Questions about Python Scripting in Ansys Electronics Desktop Products

    • mabdelraziq
      Subscriber

      Greetings all,

      I would like to use Python to interface with ANSYS Maxwell 3D to change parameters, run simulations, and acquire the simulations results. I will be running an optimization algorithm in Python so, this algorithm will need to actively change the model parameters based on the old simulation results (iterative process basically).

      Based on my current knowledge, I can go to tools and start recording a script in Python 2. Then, I can open my project and run the script which will do the same actions that I recorded. Also, I know that there is a scripting guide with a list of functions.


      However, I have the following questions:

      1. I recorded a simple .py script that changes the model's parameters values, analyzes the model, and saves some results. However, I cannot run the script since I need to install the ScriptEnv library (I tried to run the script I saved from the command window using the following line: >>python scriptname.py)
      2. I have installed the latest version of Python 2 (Python 2.7.18) and could not install ScriptEnv

      The following screenshots would help illustrate my questions:

    • Praneeth
      Forum Moderator

      Did you try running the sample script using the "run script" option in the tools menu?
      All the very best.
    • mabdelraziq
      Subscriber

      I ran the .py script from ANSYS and it ran successfully changing the model parameter as it is supposed to. However, why cannot I run this script externally in a Python 2 IDE for example, or on the Windows command line?
    • jdmac
      Subscriber
      a couple of things:
      It looks like you're trying to use Python to execute the script. HFSS scripts are in IronPython, not Python. IronPython is compiled C# code, not C. It's syntactically identical to Python but with different modules. For example, there's no numpy or scipy in IronPython, but you do have access to the whole .NET framework which is powerful for app development. On the command line make sure you're executing IronPython, which can be found in the AnsysEM install directory: AnsysEM\AnsysEM21.1\Win64\ common\IronPython\ipy64.exe.
      When you execute external scripts, make sure you append these 2 locations to your Python path: sys.path.append('path_to_install\\AnsysEM\\AnsysEM21.1\\Win64') and sys.path.append('path_to_install\\AnsysEM\\AnsysEM21.1\\Win64'\\PythonFiles\\DesktopPlugin'). The second location is where ScriptEnv.py is located.
      When executing externally you need to include the year version number in the initialization statement.: ScriptEnv.Initialize("Ansoft.ElectronicsDesktop.2021.1"). Executed internally, EM Suite doesn't need the version, ScriptEnv.Initialize("Ansoft.ElectronicsDesktop") suffices, but you do need this in order to run externally.
      After calling ScriptEnv.Initialize, you should have the oAnsoftApplication and oDesktop objects in your global scope.
      Be sure to call the Shutdown function when your script exits in order to release the COM object. Otherwise your script will lock your instance of EM Suite for about 20 minutes (you won't be able to close the project). Shutdown() releases the COM object, and once it's released, it can't be obtained again by that IronPython process (not even on another thread). You will probably want to copy out the text from ScriptEnv.Shutdown and make your own shutdown function, as the default Shutdown() closes the application, and you don't want that.

    • Ashishkumar Gupta
      Subscriber

      I am facing similar issue in MATLAB with actxserver(progid). which tells me progid is invalid. 

      I am using ANsys EDT student version 2022.2 .

      I tried using 'Ansoft.ElectronicsDesktop.2022.2', 'Ansoft.ElectronicsDesktop.2022', 'Ansoft.ElectronicsDesktopStudent.2022', 'Ansoft.ElectronicsDesktop', 'Ansoft.ElectronicsDesktopStudent' but none of them seems to work. 

      Please help me out!!!

    • lar var
      Subscriber

      challenges that I cannot overcome. it is beyond my control.

       

      Pizza Tower

    • larry larryellison
      Subscriber

      Based on your knowledge and I wonder why you don't try with a scripting tutorial with a list of functions? 

       geometry dash bloodbath

       

                                                 

                                                                                                                                                        

       

Viewing 6 reply threads
  • The topic ‘Questions about Python Scripting in Ansys Electronics Desktop Products’ is closed to new replies.