1

I am trying to control, HFSS from the Python editor Spyder.

I tried the following but it gave me the error

`# -*- coding: utf-8 -*-
"""
Created on Wed Jun 01 16:53:18 2022

@author: Owner_Local
"""
import sys
sys.path.append("C://Program Files//AnsysEM//AnsysEM21.1//Win64//PythonFiles//DesktopPlugin//")

# Activate HFSS enviroment
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oModule = oDesign.GetModule("ReportSetup")`

error: import error: "no module named clr".

I understand that the ScriptEnv.py asks for a clr library, but I have no idea where to find it. It is supposed to be provided by Ansys, so I am reluctant to install it myself and create an additional mess. So, anybody has a script that works? All I need is get access to an open HFSS file.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Robert
  • 49
  • 3
  • I'm not sure if this will work, but you can try adding the following line to your code: import clr This will import the CLR (Common Language Runtime) library, which is required for ScriptEnv.py to work. – Mohamed Elgazar Oct 16 '22 at 10:15

1 Answers1

0

You can try the following code to control HFSS.

from win32com import client

oApp = client.Dispatch("Ansoft.ElectronicsDesktop.2022.1")
oDesktop = oApp.GetAppDesktop()
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
oDesign = oProject.InsertDesign("HFSS", "HFSSDesign1", "HFSS Terminal Network", "")
oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.CreateCylinder(
   [
      "NAME:CylinderParameters",
      "XCenter:="       , "0mm",
      "YCenter:="       , "-0.3mm",
      "ZCenter:="       , "0mm",
      "Radius:="    , "0.282842712474619mm",
      "Height:="    , "0.8mm",
      "WhichAxis:="     , "Z",
      "NumSides:="      , "0"
   ], 
   [
      "NAME:Attributes",
      "Name:="      , "Cylinder1",
      "Flags:="     , "",
      "Color:="     , "(143 175 143)",
      "Transparency:="   , 0,
      "PartCoordinateSystem:=", "Global",
      "UDMId:="     , "",
      "MaterialValue:="  , "\"vacuum\"",
      "SurfaceMaterialValue:=", "\"\"",
      "SolveInside:="       , True,
      "ShellElement:="   , False,
      "ShellElementThickness:=", "0mm",
      "IsMaterialEditable:=" , True,
      "UseMaterialAppearance:=", False,
      "IsLightweight:="  , False
   ])

Build Cylinder in HFSS

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 26 '22 at 00:59