There may be a number of things you repeat every time you create a new model, like creating a material or defining a number of standard beam sections. It's tedious work and prone to error, but you don't have to. You can simply have a simple Python script (which you can record as a macro), do it for you every time you start MSC Apex or when you create a new model.
The sample script below creates two materials:
import apex apex.setScriptUnitSystem(unitSystemName = r'''mm-kg-s-N''') model_1 = apex.currentModel() def CreateMaterials(): material_1 = apex.catalog.createMaterial( name = "Material 1", description = "", color = [ 128, 128, 128 ] ) material_1.update( name = "Steel", elasticModulus = 200000., poissonRatio = 0.3,density = 0.00000785 ) material_2 = apex.catalog.createMaterial( name = "Material 2", description = "", color = [ 217, 217, 217 ] ) material_2.update( name = "Aluminium", elasticModulus = 70000., poissonRatio = 0.33,density = 0.0000027 ) CreateMaterials()
The content above is simply saved to a text file with the .py extension and set up in MSC Apex to execute whenever a new default model is created (on start up of MSC Apex) or when the user creates a new model (File > New).
The only content from the script above, that you need to copy and reference in MSC Apex, to set it up for automatic execution, is the function name, e.g. CreateMaterials, and the name and location of the file, as shown below:
For the example above, the function CreateMaterials from the script CreateMaterialsOnStartUp.py will execute every time the default new model is created when starting MSC Apex, or when the user creates a new model.
FYI: The first 4 lines of code:
import apex
from apex.construct import Point3D, Point2D
apex.setScriptUnitSystem(unitSystemName = r'''mm-kg-s-N''')
model_1 = apex.currentModel()
are standard lines of code that any MSC Apex script starts with, regardless of what follows.
The line setting the unit system should be self explanatory but is important to note that should you want to work in a different unit system, this line has to be edited.
To get started creating your own scripts, simply record a macro while executing some basic functions to see what the created Python code looks like, like the code of this macro which was created when recording the task of creating a new material:
The macro recorded above can be run directly, as-is, any time those exact steps are required to be performed.
When you wish to set the above script to be run automatically, a few minor edits are required as explained below:
The example above shows the 4 standard (required) lines of code in blue in both the recorded macro and the edited script, with some additional (optional) settings recorded that can be kept or left out from the edited script.
The only required edit for scrips, which will be set to run automatically, is the definition of a function that isolates the lines of code that MSC Apex has to run under the set condition(s).
This implies that multiple functions can be defined in the same script (*.py file) as well to keep an organised set of functions and each function can also accept its own input arguments as required, opening up the full power of customized scripting.
A strong community of MSC Apex script writers already exist with many custom and specialized scripts already available. Feel free to contact us to be connected or to inquire if a certain function you require might already exist in an available script.