Introduction
This blog post demonstrates how to automate support generation for Additive Manufacturing using Laser Powder Bed Fusion (LPBF) in Ansys Mechanical by leveraging a Python Code Object. Typically, setting up supports in Ansys involves several manual steps through the LPBF setup wizard—selecting the geometry, enabling support creation, and setting up the voxel mesh settings for both the part and the base plate. While this process works well for single studies, it becomes cumbersome and time-consuming when performing design studies involving multiple part orientations or when searching for the optimal build orientation that minimizes support volume. To address this challenge, a Python script can be used to streamline and automate support generation, making it significantly more efficient for iterative simulations and orientation optimization. In this blog we will use an example of a simple Gear Fork geometry and baseplate. Ansys version 2025R1 is used.
The Example
We will look at the example on two levels. In the first one, we will use a few lines of code to automatically generate the supports. This python code is the basic block and can be developed to automate the entire process. This will be shown in the next level, where we will add more code lines to generate additional parameterizable details like support volume. The script can be further developed to automate steps like removing initial contacts, updating the body named selection for material assignment, updating the contact regions etc. Note from the Ansys help:
Generated Supports are available only for parts meshed with Cartesian mesh (with voxelization option equal to yes or no). These supports generated by the Mechanical application are either automatically detected or user-defined. For automatic detection you specify an overhang angle (the default value is 45° to the horizontal X-Y plane) under which supports will be created. For user-defined supports you select individual element faces under which supports will be created. Supports are generated as elements vertically straight down from the overhanging portion of the build to the base, or to a lower portion of the model if it is in the way.
Level 1:
In workbench, double click on ‘AM LPBF Inherent Strain’ under Custom system or preferred analysis system. Import the Gear Fork geometry which includes part and base plate, and double click on model to open Mechanical. The steps below are suggested for manually setting up the simulation. However, if you prefer, use the LPBF setup wizard.
In details of ‘AM Process’ in Tree, set the gear fork as part geometry and Base plate as base plate geometry (as shown in image below).
Right click on Mesh, insert-> Method. In the details, set the Gear Fork as Geometry, Method to Cartesian, and set Mesh Using Voxelization to ‘Yes’. Set Element size to 1.5 mm.
Again, right click on Mesh, insert-> Sizing. In the details, set the Base Plate as Geometry, and Element Size to 1.5 mm.
Now, right click on Model in Tree, Insert-> Python Code. This will insert a Python Code Object into the Tree. Set the Target Callback in the details of the Python Code to ‘After Mesh Generated’.
In the script, add the following lines:
process = Model.AMProcess
if ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanica.lAdditiveManufacturing.AMSupportGroup):
supportGroup = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.AdditiveManufacturing.AMSupportGroup)[0]
else:
process.AddSupportGroup()
supportGroup=process.Children[1]
generatedSupport = supportGroup.DetectSupportFaces()[0]
generatedSupport.GenerateSupportBodies()
generatedSupport.MaterialMultiplier = 0.2
pass
Right mouse click on Python code object and click on Connect. This will set Connected to True in the details and change the question mark to a green tick mark next to the Python code object.
Now, right click on Mesh, and click on Generate Mesh. This will start the meshing process, and after the mesh is generated, will trigger the python code object, as the callback is set to ‘After Mesh Generated’. You will see that the Support Group is added under the AM process, and support is generated.
As said earlier, this is the basic block of code which shows how python object can be used to automatically generate the support structures.
Level 2:
Now we will go a step further and use the python block to parametrize and obtain the volume of the support structures. For this, add the following lines in the python code script (before 'pass'):
support_object=ExtAPI.DataModel.GetObjectsByName("Generated Support")[0]
value = support_object.Volume.Value
this.GetCustomPropertyByPath("Group 1/Sup_Volum").Value = value
Now click on the ‘Property Provide’ tab.
Comment out ‘return’ on line 5.
Replace lines 14 to 47 with following lines:
# Create the property instance
provider = Provider()
# Create a group named Group 1.
group = provider.AddGroup("Group 1")
# Create a property with control type Expression and a property with control type Double, and add it to the Group 1
double_prop = group.AddProperty("Sup_Volum", Control.Double)
# Configure the double property to be parameterizable. As a default the property will be an input parameter.
# However, by updating the ParameterType property, it can be configured to be a output parameter as well.
double_prop.CanParameterize = True
double_prop.ParameterType = ParameterType.Output
# The valid range set here is used by the IsValid handler in the Provider class, please look at the class definition above.
# If interested in the implementation, please look at the class definition below
# Connects the provider instance back to the object by setting the PropertyProvider member on this, 'this' being the
# current instance of the Python Code object.
this.PropertyProvider = provider
Right Click on Python code object, click on Connect and click on Reload Properties. Now, you will be able to see additional property ‘Sup_Volume’ under Group 1 in details of Python code. You will also notice that this property is parameterizable. If you clear the mesh data and generate it again, the modified Python object will be activated, a new mesh and supports will be generated, the modified python object will be triggered, a new mesh and supports will be generated, and the volume of the generated supports will be obtained. The support volume will use the same units chosen in Ansys Mechanical.
This concludes the example for the automated support generation using a Python code object. This example can be further enhanced by changing the callback of the Python code object. For example, if the callback is set to ‘After Geometry Changed’, the code block will be triggered after any change in geometry. This will be useful in case of design studies where multiple orientations of the geometry can be set in the design study, and project can be solved by updating all design points in workbench. In that case, updating geometry, generating mesh and creating supports will be done by the python code in the background.
Summary
In this blog post, an example shows how Python code object can be used to automate the support generation for LPBF process simulation in Ansys Mechanical: This example can be further enhanced to automate multiple processes such as geometry updates and obtaining more properties as parametrizable outputs, on which design studies can be based.