我试图通过将VB脚本转换为Python来使用Python控制CST Studio。代码如下:
import win32com.client
import comtypes
import win32com.client.gencache
import os
import os.path
import datetime
from CSTModel import DefaultUnits, DefineFrequencyRange, MeshInitiator, DefineBoundary, DefineBackGroundMaterial
cst = win32com.client.Dispatch("CSTStudio.Application")
mws= cst.NewMWS()
DefaultUnits(mws)
DefineFrequencyRange(mws,4,8)
这是CSTModel.py中的DefaultUnits(mws)和DefineFrequencyRange(mws)。
def DefaultUnits(mws):
# define default units (Default selection)
Units = mws.Units
Units.Geometry("um")
Units.Frequency("GHz")
Units.Time('ns')
Units.TemperatureUnit('Kelvin')
Units.Voltage('V')
Units.Current('A')
Units.Resistance('Ohm')
Units.Conductance('S')
Units.Capacitance('PikoF')
Units.Inductance('NanoH')
# FREQUENCY RANGE----------------------------
def DefineFrequencyRange(mws,frange1,frange2):
# Define the simulated frequency range
solver = mws.solver()
solver.FrequencyRange(str(frange1),str(frange2))
MeshSettings = mws.MeshSettings()
MeshSettings.SetMeshType('Hex')
MeshSettings.Set('Version','1%')
Mesh = mws.Mesh()
Mesh.MeshType('PBA')
我通过转换VB脚本创建了自己的CSTModel模块。 DefaultUnits(mws)可以正常工作。但是,DefineFrequencyRange(mws,4,8)无法工作,并且出现以下错误:
Traceback (most recent call last):
File "C:\Users\Minh Tran\Desktop\pycst\Python2CST\CST.py", line 13, in <module>
DefineFrequencyRange(mws,4,8)
File "C:\Users\Minh Tran\Desktop\pycst\Python2CST\CSTModel.py", line 805, in DefineFrequencyRange
solver = mws.solver()
File "C:\Users\Minh Tran\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 197, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
有人知道该问题的解决方案或建议吗? 如果您能帮助我,我将不胜感激。