简体   繁体   中英

How can I control HFSS from Spyder?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM