How to transfer loads and boundary conditions from one analysis to all other analyses in the tree?
I have 4 analyses in Mechanical. I have defined some loads and boundary conditions. How can I use scripting to transfer these loads and boundary conditions from this analysis to all the remaining analyses?
Answers
-
You can try using the below script (tested in 2022R2 and above).
Steps:
1. Select (multiselect) all the loads and boundary conditions under a particular analysis.
2. Paste the below script in Mechanical scripting console and run it.import context_menu #Copy the active Boundary Condition/s context_menu.DoEditCopy(ExtAPI) parentAnalysis = Tree.FirstActiveObject.Parent for analysis in DataModel.AnalysisList: if analysis.ObjectId != parentAnalysis.ObjectId: print analysis.Name analysis.Activate() context_menu.DoEditPaste(ExtAPI)
- All the loads and boundary conditions will be pasted into other analyses.
0 -
Another way without using and importing external libraries/modules (context_menu), and that uses only ACT mechanical scripting could be using the below code. It 'copies' the selected load (force), pressure, thermalcondition and support (fixed support) from the main/base analysis to other analysis systems that share data with the base one. The below code can be easily extended using the same logic for other load types (e.g., displacements)
myo=Tree.FirstActiveObject parentAnalysis = Tree.FirstActiveObject.Parent for analysis in DataModel.AnalysisList: if analysis.ObjectId != parentAnalysis.ObjectId: print analysis.Name analysis.Activate() if str(myo.GetType()) == 'Ansys.ACT.Automation.Mechanical.BoundaryConditions.Force': f=analysis.AddForce() f.Location=myo.Location f.AppliedBy=myo.AppliedBy f.Magnitude.Inputs[0].DiscreteValues=myo.Magnitude.Inputs[0].DiscreteValues f.Magnitude.Output.DiscreteValues=myo.Magnitude.Output.DiscreteValues elif str(myo.GetType()) == 'Ansys.ACT.Automation.Mechanical.BoundaryConditions.FixedSupport': d=analysis.AddFixedSupport() d.Location=myo.Location elif str(myo.GetType())== 'Ansys.ACT.Automation.Mechanical.BoundaryConditions.Pressure': f=analysis.AddPressure() f.Location=myo.Location f.AppliedBy=myo.AppliedBy f.Magnitude.Inputs[0].DiscreteValues=myo.Magnitude.Inputs[0].DiscreteValues f.Magnitude.Output.DiscreteValues=myo.Magnitude.Output.DiscreteValues elif str(myo.GetType())== 'Ansys.ACT.Automation.Mechanical.BoundaryConditions.ThermalCondition': f=analysis.AddThermalCondition() f.Location=myo.Location f.Magnitude.Inputs[0].DiscreteValues=myo.Magnitude.Inputs[0].DiscreteValues f.Magnitude.Output.DiscreteValues=myo.Magnitude.Output.DiscreteValues else: print('No force or fixed support is selected')
1 -
Hi @Erik Kostson , thanks for posting this answer.
Just for reference, there might be some limitations with this method.
An example is a scenario where there are some deactivations in the tabular data of the load, especially inertial loads such as acceleration, rotational velocity etc, as currently there is no API to get this information and hence exactly replicate the load in a new analysis.
Also, depending on the load, we might have additional settings (other than scoping and magnitude) which may only be accessible via InternalObject or Property.InternalValue.
0 -
Thank you. Very good description
0