EM API (1) 用Python来叫醒你的HFSS!!!

2023-06-30T16:53:00

{dotted startColor="#ff6c6c" endColor="#1989fa"/}
文末附代码!!!文末附代码!!!文末附代码!!!文末附代码!!! *

Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {$_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID")} | Select-Object -ExpandProperty PSChildName 

这个Powershell脚本直接在Powershell上运行,可以查到所有软件的ProgID。如果想要将结果放在txt文档里面检索的话,也可以运行下面的代码(注意修改输出的地址路径)。可以用类似的方法调用其他软件,如CST, Excel, Word等等!

Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {$_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID")} | Select-Object -ExpandProperty PSChildName |Out-File -FilePath 想要的输出路径\output.txt

from win32com import client

oAnsoftApp = client.Dispatch('AnsoftHfss.HfssScriptInterface')
oDesktop = oAnsoftApp.GetAppDesktop()
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
oProject.InsertDesign('HFSS', 'HFSSDesign1', 'DrivenModal1', '')
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oEditor = oDesign.SetActiveEditor("3D Modeler")
oModule = oDesign.GetModule('BoundarySetup')

将上述代码复制到python命令行里直接运行就可以调用HFSS建立一个新的Design。后续也可以利用下面的代码关闭HFSS。
注意:如果运行不了,很有可能是因为没有安装win32com库,请先安装!

oDesktop = oAnsoftApp.GetAppDesktop()
oDesktop.QuitApplication()

oAnsoftApp = client.Dispatch(' Ansoft.ElectronicsDesktop')
oAnsoftApp = client.Dispatch(' Ansoft.ElectronicsDesktop.2022.1')
oAnsoftApp = client.Dispatch(' Ansoft.ElectronicsDesktop.2020.2')
oAnsoftApp = client.Dispatch(' Ansoft.ElectronicsDesktop.2019.3')
oAnsoftApp = client.Dispatch(' Ansoft.ElectronicsDesktop.2019.2')

{bilibili bvid="BV1Dj411S733" page=""/}

{bilibili bvid="BV1bP411i7Xh" page=""/}


{bilibili bvid="BV1X14y127WR" page=""/}

本文代码下载链接
百度网盘链接: EM API 代码 提取码:bkm7
GitHub 链接:EM API 代码

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »