In ANSYS Mechanical, we can make the mass of all bodies as a parameter, but, if one wants mass of a multibody Part or an assembly, the Parameter option is not available.
Starting from v2021R2, we can use Python Code object to parametrize non-parametrizable properties in Mechanical, such as Mass (for example) shown in the question.
Here are the steps:
Step 1: RMB on Solution --> Insert --> Python Code, and set the, "Target Callback" in the Properties to "After Solve"
Step 2: Python Code object has two tabs, "Script", "Property Provider". Script section is where we put our Mechanical script (python). Property Provider section is used to create custom properties (it can be float, text, drop down menu with options, geometry scoping etc)
this.PropertyProvider = None
# comment the following return to allow the rest of the function definition to be executed and add properties
Some sample code is provided below that shows how to:
1. Create an instance of the Provider. The Provider class is used to add custom properties to the details.
2. Use the Provider instance to add custom properties.
3. Configure those custom properties.
# Create the property instance
provider = Provider()
# Create a group named Group 1.
group = provider.AddGroup("Outputs")
# 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("Mass", Control.Double)
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
this.PropertyProvider = provider
def after_solve(this, analysis):# Do not edit this line
Called after solving the parent analysis.
Keyword Arguments :
this -- the datamodel object instance of the python code object you are currently editing in the tree
analysis -- Static Structural
# To access properties created using the Property Provider, please use the following command.
# To access scoping properties use the following to access geometry scoping and named selection respectively:
# this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection")
# this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection")
this.GetCustomPropertyByPath("Outputs/Mass").Value = DataModel.GetObjectsByName("Component1").Mass.Value
Step 3: Click on the check box to send this property as a parameter to WB (you can now see this under Parameter page in WB). One can now start the Design Point run to see the variation of output parameter for each Design Point.