- Rename an object in the tree
- Change a material
- Mesh the model
- Insert a Fixed Support
- Insert a Total Deformation result
- Solve the solution
- Save the results to a file
📎 Files for this article:Model1.wbpz·Model1_Hello_Mechanical.py
Note: Model was created in 26R1“Spot the differences!” — here’s the tree before the script runs:



Model, and renamed simply by assigning a new value to its .Name property. This is about as gentle an introduction to the Mechanical API as you can get: you’re reading an object from the tree and writing a new value to one of its properties.
Step 2 — Change a material. Materials live under the Geometry branch of the tree. Model.Geometry gets you into Geometry, and .Children[1] selects the second child underneath it (indexing starts at 0), whose material you then assign directly. The script also includes an optional safety check — if the material name wasn’t recognized and applied, it prints a warning rather than failing silently.

Children[index], then either read or set a property on whatever you land on.
Step 3 — Mesh. The Mesh object is reached with Model.Mesh, and generating the mesh with default settings is a single function call: Model.Mesh.GenerateMesh().
Step 4 — Insert a Fixed Support. This step is a little more involved, because it needs to reference a face by name rather than by tree position. First, the script looks up the Named Selection for the face by name using DataModel.GetObjectsByName, which returns a list — so [0] grabs the first (and here, only) match. Then a Fixed Support is added under the first analysis in the tree (Model.Analyses[0] — for this model, that’s the Modal analysis) using AddFixedSupport(), and its location is scoped to the Named Selection just found.
Step 5 — Insert Total Deformation. Results live under Solution, which you reach via Model.Analyses[0].Solution. Adding a Total Deformation result is another one-line function call: AddTotalDeformation().

Solve() function called on that same analysis object: Model.Analyses[0].Solve().
Step 7 — Export the results. Finally, the script grabs the Total Deformation object — which, in this tree, is the second child under Solution — assigns it to a variable called result, and exports it to a text file. ExportToTextFile needs a full file path, so the script builds one from WorkingDir (the Solver Files Directory for this analysis) plus the desired filename.

