Using a solved project, this example examines APIs for post processing User Defined Results and graphical manipulation actions. This example requires you to download the following project and python files.
Post_Processing_User_Defined_Results.wbpz
Post_Processing_User_Defined_Results.py
These files are available here.
Procedure
Open the project file Post_Processing_User_Defined_Results.wbpz in the Workbench application.
Right-click the Model cell in the Project Schematic and the Edit option. This opens the project in Mechanical.
Select the Automation tab and select the Scripting option to open the Mechanical Scripting pane.
Select the Open Script option (
) from the Editor toolbar. Navigate to the proper folder location and select Post_Processing_User_Defined_Results.py.
Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
# -*- coding: UTF-8 -*- #Scenario 1: Set up the Tree objects items and API base definitions. This step is necessary for all the API functions that follow. These definitions will be used throughout the current example. GEOM=Model.Geometry MESH=Model.Mesh STATIC_STRUCTURAL=Model.Analyses[0] SOLUTION=STATIC_STRUCTURAL.Solution #Scenario 2: Add different results from Tree. In this example we will add Total Deformation result, von Mises stress result and Normal strain result items TOTAL_DEFORMATION_RESULT=SOLUTION.AddTotalDeformation() EQUIVALENT_STRESS_RESULT=SOLUTION.AddEquivalentStress() NORMAL_STRESS=SOLUTION.AddNormalStress() #Scenario 3: Modify display options for inserted results. #Modify the result display option from Averaged(default) to Unaveraged. EQUIVALENT_STRESS_RESULT.DisplayOption=ResultAveragingType.Unaveraged #Modify the Orientation to Y-Axis for Normal stress results (only applicable with certain results) NORMAL_STRESS.NormalOrientation=NormalOrientationType.YAxis #Modify the result display time to 0.4 s. TOTAL_DEFORMATION_RESULT.DisplayTime=Quantity(0.4,'s') #Get Result values, maximum of Total Deformation Results VAL1=TOTAL_DEFORMATION_RESULT.Maximum.Value #Scenario 4: Add User Defined results. In this example we will add USUM, SEQV and SX to reflect the regular results. USUM=SOLUTION.AddUserDefinedResult() USUM.Expression='USUM' SEQV= SOLUTION.AddUserDefinedResult() SEQV.Expression='SEQV' SX= SOLUTION.AddUserDefinedResult() SX.Expression='SX' #Scenario 5: Modify display options for user defined results #Modify the result output unit category. USUM.OutputUnit=UnitCategoryType.Length SEQV.OutputUnit=UnitCategoryType.Stress SX.OutputUnit=UnitCategoryType.Stress #Modify the result Averaging option across bodies SEQV.AverageAcrossBodies=True #Modify the Identifier SX.Identifier='SX_ID' #Modify the result display by option USUM.By=SetDriverStyle.ResultSet #Scenario 6: Duplicate, Clear, Evaluate results. Create Results at All sets USUM2=USUM.DuplicateWithoutResults() SEQV.ClearGeneratedData() SX.CreateResultsAtAllSets() USUM.RenameBasedOnDefinition() SEQV.RenameBasedOnDefinition() SX.RenameBasedOnDefinition() SOLUTION.EvaluateAllResults() #Scenario 7: Use PlotData API to extract useful information from results. Here we show a snippet to access values at individual nodes/elements SOLUTION.EvaluateAllResults() PLOT_DATA_RESULT= EQUIVALENT_STRESS_RESULT.PlotData def findNodeResult(nodeID,plotDataResult): nodes=plotDataResult ['Node'] resultValue=plotDataResult ['Values'] if nodeID in nodes: for index in range(len(nodes)): if nodes[index]==nodeID: return resultValue[index] else: print("Given NodeID doesn't exist in result set") #Find the result value associated for node number 3 using VALUE2=findNodeResult(3, PLOT_DATA_RESULT) print('The result value at node 3 is '+str(VALUE2)) #Scenario 8: Add figures under the results. FIGURE=EQUIVALENT_STRESS_RESULT.AddFigure()
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.