Python: name variables with a loop
for our ansys software i would like to generate a script to automate certain things. when i record my actions I get the following
template1 = GetTemplate(
TemplateName="Random Vibration",
Solver="ANSYS")
system1 = GetSystem(Name="Modal (ANSYS)")
component1 = system1.GetComponent(Name="Engineering Data")
component2 = system1.GetComponent(Name="Geometry")
component3 = system1.GetComponent(Name="Model")
component4 = system1.GetComponent(Name="Solution")
componentTemplate1 = GetComponentTemplate(Name="SimulationSetupCellTemplate_StructuralRandomVibrationANSYS")
system2 = template1.CreateSystem(
ComponentsToShare=[component1, com开发者_Go百科ponent2, component3],
DataTransferFrom=[Set(FromComponent=component4, TransferName=None, ToComponentTemplate=componentTemplate1)],
Position="Right",
RelativeTo=system1)
there need to be created 72 sytems, so i would like to do this with a loop in stead of manually copy paste these. What is the best way to proceed
I'm not sure I fully undesrtood your question but from your code naming I think this is what you want:
systems1 = []
systems2 = []
templates = []
components1 = []
components2 = []
components3 = []
components4 = []
for i in range(72):
template = GetTemplate(
TemplateName="Random Vibration",
Solver="ANSYS")
system = GetSystem(Name="Modal (ANSYS)")
component = system.GetComponent(Name="Engineering Data")
component1 = system.GetComponent(Name="Geometry")
component2 = system.GetComponent(Name="Model")
component3 = system.GetComponent(Name="Solution")
componentTemplate = GetComponentTemplate(Name="SimulationSetupCellTemplate_StructuralRandomVibrationANSYS")
system = template.CreateSystem(
ComponentsToShare=[component1, component2, component3],
DataTransferFrom=[Set(FromComponent=component4, TransferName=None, ToComponentTemplate=componentTemplate)],
Position="Right",
RelativeTo=system)
templates.append(template)
... rest of appends...
The appends are if you need to access those later as I guess you do. If you actually need them to be named system1, system2 etc you could use exec
and build your strings in a loop.
精彩评论