Mech Scrip 2024R1 en LE01
Mech Scrip 2024R1 en LE01
The console will appear on the right of the screen New Open Save Run Debugger
To know what each button does simply hover on it and the Recorder
definition will appear
• Clear the Shell window and write print (‘Hello’) in this window
• Hit Enter
As you have just seen either the Shell or the Editor can be used to write scripts
You are going to try some basic python functionalities, by using the script editor:
• In the script editor write ‘a=3*3’ on the first line and ‘print (a)’ on the second line
• Run the script
The simplest loop in python is the for loop. The for loop needs to be indented
• In the script editor write:
for i in range(10):
print (I)
And run
Pay attention to the space in front of print. Anything written with an indent under for will be inside the loop.
To stop the loop, just remove the indent
To try it: under print (i), write print (‘Hello’) with an indent and without. Run each version.
Look at the shell window each time
In the same way you can create more indents for an ‘if’ statement for example
• There is often more than one way to access something in the API using different entry points. For
example: Model.Analyses[0] = ExtAPI.DataModel.AnalysisList[0]= DataModel.AnalysisList[0]
-------------------------------------------------------------------------------------------------------------------------------
for i in range(len(Model.Analyses)):
analysis=Model.Analyses[i]
analysis.Name='Analysis '+str(i+1)
-------------------------------------------------------------------------------------------------------------------------------
for i in range(len(DataModel.AnalysisList)):
analysis=Model.Analyses[i]
analysis.Name='Analysis '+str(i+1)