728x90
반응형
Python의 win32com을 이용하여 CST STUDIO SUITE를 제어할 수 있는 예제를 올려둔다. 하기 예제는 변수를 등록하는 방법과 재질을 등록하는 법이 포함되어 있다. CST STUDIO SUITE을 잘 이용한다면 History에서 나온 내용들을 복사해서 하기 코드에 등록하면 된다.
This is an example of controlling CST STUDIO SUITE using Python's win32com. The example below includes how to register a variable and how to register a material. If you are familiar with CST STUDIO SUITE, you can copy the contents from the History and register them in the code below.
import time
import sys
#import win32com.client # : 동작안함
from win32com import client
# CST STUDIO SUITE 시작
oCSTApp = client.Dispatch("CSTStudio.Application")
#print(oCSTApp)
#help(oCSTApp)
# new EMS Project
oProject = oCSTApp.NewEMS()
#print(oProject)
#help(oProject)
#ParameterDefineString = 'Sub Main () \nStoreParameter("offset","3") \nEnd Sub'
#oProject.Schematic.executevbacode(ParameterDefineString)
# Save Path & File Name for Project
pName = "저장 경로 + 저장 파일명"
oProject._FlagAsMethod("SaveAs")
oProject.SaveAs(pName,'False')
# Add Variable
ss_x = 10
oProject._FlagAsMethod("StoreParameter")
oProject.StoreParameter("ss_x", str(ss_x))
# Add New Material
print("Define Material")
setMaterialFerrite = """
With Material
.Reset
.Name "Ferrite"
.Folder ""
.Rho "0.0"
.ThermalType "Normal"
.ThermalConductivity "0"
.SpecificHeat "0", "J/K/kg"
.DynamicViscosity "0"
.Emissivity "0"
.MetabolicRate "0.0"
.VoxelConvection "0.0"
.BloodFlow "0"
.MechanicsType "Unused"
.FrqType "all"
.Type "Normal"
.MaterialUnit "Frequency", "kHz"
.MaterialUnit "Geometry", "mm"
.MaterialUnit "Time", "s"
.MaterialUnit "Temperature", "Celsius"
.Epsilon "1"
.Mu "3000"
.Sigma "0"
.TanD "0.0"
.TanDFreq "0.0"
.TanDGiven "False"
.TanDModel "ConstTanD"
.EnableUserConstTanDModelOrderEps "False"
.ConstTanDModelOrderEps "1"
.SetElParametricConductivity "False"
.ReferenceCoordSystem "Global"
.CoordSystemType "Cartesian"
.SigmaM "0"
.TanDM "0.0"
.TanDMFreq "0.0"
.TanDMGiven "False"
.TanDMModel "ConstTanD"
.EnableUserConstTanDModelOrderMu "False"
.ConstTanDModelOrderMu "1"
.SetMagParametricConductivity "False"
.DispModelEps "None"
.DispModelMu "None"
.DispersiveFittingSchemeEps "Nth Order"
.MaximalOrderNthModelFitEps "10"
.ErrorLimitNthModelFitEps "0.1"
.UseOnlyDataInSimFreqRangeNthModelEps "False"
.DispersiveFittingSchemeMu "Nth Order"
.MaximalOrderNthModelFitMu "10"
.ErrorLimitNthModelFitMu "0.1"
.UseOnlyDataInSimFreqRangeNthModelMu "False"
.UseGeneralDispersionEps "False"
.UseGeneralDispersionMu "False"
.NLAnisotropy "False"
.NLAStackingFactor "1"
.NLADirectionX "1"
.NLADirectionY "0"
.NLADirectionZ "0"
.Colour "0", "1", "1"
.Wireframe "False"
.Reflection "False"
.Allowoutline "True"
.Transparentoutline "False"
.Transparency "0"
.Create
End With
"""
oProject._FlagAsMethod("AddToHistory")
oProject.AddToHistory("define material", setMaterialFerrite)
oProject._FlagAsMethod("Save")
oProject.Save()
# Close 지연
print("Python, time.sleep(10) -> 10초 기다림")
time.sleep(10) # 10초 기다림
# Close oProject
oProject.Quit()
# 종료 지연
print("Python, time.sleep(10) -> 10초 기다림")
time.sleep(10) # 25초 기다림
print("Python, time.sleep(5) -> 5초 기다림")
time.sleep(5) # 2초 기다림
print("Goodby!")
# CST STUDIO SUITE 종료
oCSTApp.Quit()
CST Studio Suite에서 지원하는 python script 이용하기
Using python scripts supported by CST Studio Suite
728x90
반응형
댓글