In this example, using the support files, you will perform a Static Structural analysis using an imported mesh-based geometry from an External Model system. Using a sequence of python journal commands, you will automatically define and solve the analysis.
This example begins in the Mechanical application. It requires you to download the following files.
External_Model.bfd
External_Model.py
These files are available here.
Procedure
Open Workbench and insert an External Model system, from the Component Systems group in the Toolbox, into the Project Schematic.
Double-click the Setup cell of the External Model system.
From the External Model tab, select the option of the Location column and select Browse.
Navigate to the proper folder location and select the sample file, External_Model.bfd.
Return to the project page.
Drag and drop a Static Structural system onto the Setup cell of the External Model system so that it is linked as shown below.
Select the Update Project option on the toolbar.
Open Mechanical: right-click the Model cell and select .
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 External_Model.py.
Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
# Scenario 1 Set up the Tree Object Items: Define the geometry, coordinate system, connections, mesh, static system, the analysis settings, and the solution navigating through the tree items. GEOMETRY= Model.Geometry COORDINATE_SYSTEM = Model.CoordinateSystems CONNECTIONS = Model.Connections MESH = Model.Mesh STATIC_STRUCTURAL = ExtAPI.DataModel.AnalysisByName("Static Structural") ANALYSIS_SETTINGS = STATIC_STRUCTURAL.AnalysisSettings SOLUTION= STATIC_STRUCTURAL.Solution # Scenario 2 Set up Unit System: Set up the Unit Systems to Metric (m, kg, N, s, V, A) ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS # Scenario 3 Shell Thicknesses Imported from External Model: working with Get and Set methods for getting and setting different properties from Shell Thicknesses worksheet SHELL_THICKNESSES_WORKSHEET=[x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Shell Thicknesses(External Model)'][0] SHELL_THICKNESSES_WORKSHEET.Activate() SHELL_THICKNESSES_PROPERTY_NAMES= SHELL_THICKNESSES_WORKSHEET [0].GetPropertyNames() SHELL_THICKNESS_OBJECT1_ID = SHELL_THICKNESSES_WORKSHEET [0].GetPropertyValueAsString("Id") SHELL_THICKNESS_OBJECT1_SCOPE = SHELL_THICKNESSES_WORKSHEET [0].GetPropertyValueAsString("Scoping") SHELL_THICKNESS_OBJECT1_THICKNESS = SHELL_THICKNESSES_WORKSHEET [0].GetPropertyValueAsString("Thickness") SHELL_THICKNESS_OBJECT1_OFFSET_TYPE = SHELL_THICKNESSES_WORKSHEET [0].GetPropertyValueAsString("OffsetType") SHELL_THICKNESSES_WORKSHEET [4].SetPropertyValue("OffsetType", ShellOffsetType.UserDefined) SHELL_THICKNESS_OBJECT4_OFFSET = SHELL_THICKNESSES_WORKSHEET [4].GetPropertyValueAsString("Offset") SHELL_THICKNESSES_WORKSHEET [4].SetPropertyValue("Offset", -0.01) # Scenario 4 Point Masses Imported from External Model: working with Get and Set methods for getting and setting different properties from Point Masses worksheet POINT_MASSES_WORKSHEET= [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Point Masses(External Model)'][0] POINT_MASSES_WORKSHEET.Activate() POINT_MASSES_PROPERTY_NAMES = POINT_MASSES_WORKSHEET[0].GetPropertyNames() POINT_MASSES_OBJECT1_ID = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("Id") POINT_MASSES_OBJECT1_REFERENCENODEID = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("ReferenceNodeId") POINT_MASSES_WORKSHEET[0].SetPropertyValue("ReferenceNodeId", "54_firstNode") POINT_MASSES_OBJECT1_REFERENCENODEID = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("ReferenceNodeId") POINT_MASSES_OBJECT1_MASS = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("Mass") POINT_MASSES_WORKSHEET[0].SetPropertyValue("Mass", "1e5") POINT_MASSES_OBJECT1_MASS = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("Mass") POINT_MASSES_OBJECT1_INERTIAX= POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaX") POINT_MASSES_WORKSHEET[0].SetPropertyValue("InertiaX", "100") POINT_MASSES_OBJECT1_INERTIAX = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaX") POINT_MASSES_OBJECT1_INERTIAY = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaY") POINT_MASSES_WORKSHEET[0].SetPropertyValue("InertiaY", "80") POINT_MASSES_OBJECT1_INERTIAY = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaY") POINT_MASSES_OBJECT1_INERTIAZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaZ") POINT_MASSES_WORKSHEET[0].SetPropertyValue("InertiaZ", "50") POINT_MASSES_OBJECT1_INERTIAZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaZ") POINT_MASSES_OBJECT1_INERTIAXY = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaXY") POINT_MASSES_WORKSHEET[0].SetPropertyValue("InertiaXY", "0") POINT_MASSES_OBJECT1_INERTIAXY = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaXY") POINT_MASSES_OBJECT1_INERTIAXZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaXZ") POINT_MASSES_WORKSHEET[0].SetPropertyValue("InertiaXZ", "0") POINT_MASSES_OBJECT1_INERTIAXZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaXZ") POINT_MASSES_OBJECT1_INERTIAYZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaYZ") POINT_MASSES_WORKSHEET[0].SetPropertyValue("InertiaYZ", "0") POINT_MASSES_OBJECT1_INERTIAYZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("InertiaYZ") POINT_MASSES_OBJECT1_OFFSETX = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("OffsetX") POINT_MASSES_WORKSHEET[0].SetPropertyValue("OffsetX", "10") POINT_MASSES_OBJECT1_OFFSETX = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("OffsetX") POINT_MASSES_OBJECT1_OFFSETY = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("OffsetY") POINT_MASSES_WORKSHEET[0].SetPropertyValue("OffsetY", "8") POINT_MASSES_OBJECT1_OFFSETY = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("OffsetY") POINT_MASSES_OBJECT1_OFFSETZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("OffsetZ") POINT_MASSES_WORKSHEET[0].SetPropertyValue("OffsetZ", "5") POINT_MASSES_OBJECT1_OFFSETZ = POINT_MASSES_WORKSHEET[0].GetPropertyValueAsString("OffsetZ") POINT_MASSES_WORKSHEET[1].SetPropertyValue("InertiaXY", "0") POINT_MASSES_WORKSHEET[1].SetPropertyValue("InertiaXZ", "0") POINT_MASSES_WORKSHEET[1].SetPropertyValue("InertiaYZ", "0") POINT_MASSES_WORKSHEET[0].SetPropertyValue("OffsetX", "0") POINT_MASSES_WORKSHEET[0].SetPropertyValue("OffsetY", "0") POINT_MASSES_WORKSHEET[0].SetPropertyValue("OffsetZ", "0") POINT_MASSES_WORKSHEET[0].SetPropertyValue("Mass", "1e3") # Scenario 5 Rigid Remote Connectors Imported from External Model: working with Get and Set methods for getting and setting different properties from Rigid Remote Connectors worksheet RIGID_REMOTE_CONNECTORS_WORKSHEET= [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Rigid Remote Connectors(External Model)'][0] RIGID_REMOTE_CONNECTORS_WORKSHEET.Activate() RIGID_REMOTE_CONNECTORS_PROPERTY_NAMES = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyNames() RIGID_REMOTE_CONNECTORS_OBJECT1_TYPE = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("RigidConnectorType") RIGID_REMOTE_CONNECTORS_OBJECT1_ID = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Id") RIGID_REMOTE_CONNECTORS_OBJECT1_REFERENCE_NODE_ID = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ReferenceNodeId") RIGID_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("ReferenceNodeId", "53_firstNode") RIGID_REMOTE_CONNECTORS_OBJECT1_REFERENCE_NODE_ID = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ReferenceNodeId") RIGID_REMOTE_CONNECTORS_OBJECT1_DOFS = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Dofs") RIGID_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("Dofs", "uz; rot x; rot y") RIGID_REMOTE_CONNECTORS_OBJECT1_DOFS = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Dofs") RIGID_REMOTE_CONNECTORS_OBJECT1_PARTICIPATING_NODES = RIGID_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ParticipatingNodes") RIGID_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("Dofs", "ux; uy; uz; rot x; rot y; rot z") # Scenario 6 Flexible Remote Connectors Imported from External Model: working with Get and Set methods for getting and setting different properties from Flexible Remote Connectors worksheet FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET= [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Flexible Remote Connectors(External Model)'][0] FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET.Activate() FLEXIBLE_REMOTE_CONNECTORS_PROPERTY_NAMES = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyNames() FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_TYPE = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ConnectorType") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_ID = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Id") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_REFERENCE_NODE_ID = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ReferenceNode") FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("ReferenceNode", "54_firstNode") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_REFERENCE_NODE_ID = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ReferenceNode") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_DOFS = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Dofs") FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("Dofs", "uz; rot x; rot y") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_DOFS = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Dofs") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_PARTICIPATING_NODES = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("ParticipatingNodes") FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_WEIGHT_PARTICIPATING_FACTOR = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("WeightParticipatingFactor") FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("WeightParticipatingFactor", 2) FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_WEIGHT_PARTICIPATING_FACTOR = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("WeightParticipatingFactor") FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("WeightParticipatingFactor", 1) FLEXIBLE_REMOTE_CONNECTORS_OBJECT1_WEIGHT_PARTICIPATING_FACTOR = FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("WeightParticipatingFactor") FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].SetPropertyValue("Dofs", "ux; uy; uz; rot x; rot y; rot z") # Scenario 7 Spring Connectors Imported from External Model: working with Get and Set methods for getting and setting different properties from Spring Connectors worksheet SPRING_CONNECTORS_WORKSHEET= [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'Spring Connectors(External Model)'][0] SPRING_CONNECTORS_WORKSHEET.Activate() SPRING_CONNECTORS_PROPERTY_NAMES = SPRING_CONNECTORS_WORKSHEET[0].GetPropertyNames() SPRING_CONNECTORS_OBJECT4_TYPE = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("Type") SPRING_CONNECTORS_OBJECT4_ID = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("Id") SPRING_CONNECTORS_OBJECT4_NODES = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("Nodes") SPRING_CONNECTORS_OBJECT1_STIFFNESS = SPRING_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Stiffness") SPRING_CONNECTORS_OBJECT1_DAMPING = SPRING_CONNECTORS_WORKSHEET[0].GetPropertyValueAsString("Damping") SPRING_CONNECTORS_OBJECT4_COORDINATE_SYSTEM = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("CoordinateSystem") SPRING_CONNECTORS_OBJECT4_LOCATION= SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("Location") SPRING_CONNECTORS_OBJECT4_LOCATION_COORDINATE_SYSTEM = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("LocationCoordinateSystem") SPRING_CONNECTORS_WORKSHEET[3].SetPropertyValue("GroundedNode", 2) SPRING_CONNECTORS_OBJECT4_GROUNDEDNODE = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("GroundedNode") SPRING_CONNECTORS_WORKSHEET[3].SetPropertyValue("GroundedNode", 0) SPRING_CONNECTORS_OBJECT4_GROUNDEDNODE = SPRING_CONNECTORS_WORKSHEET[3].GetPropertyValueAsString("GroundedNode") SPRING_CONNECTORS_WORKSHEET.Suppressed = True SPRING_CONNECTORS_WORKSHEET.Suppressed = False # Scenario 8 Define Analysis Settings: Set Number of Steps is equal to 4 under details view of Analysis Settings. ANALYSIS_SETTINGS.Activate() ANALYSIS_SETTINGS.NumberOfSteps=4 # Scenario 9 Insert Results: Insert a Total deformation. SOLUTION.Activate() TOTAL_DEFORMATION = SOLUTION.AddTotalDeformation() # Scenario 10 Uncheck Point Masses, Rigid and Flexible connectors: Unchecking Point Mass, Rigid and Flexible connector from the respective worksheets. POINT_MASSES_WORKSHEET.Activate() POINT_MASSES_WORKSHEET[0].Active = False POINT_MASSES_WORKSHEET[1].Active = False FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET.Activate() FLEXIBLE_REMOTE_CONNECTORS_WORKSHEET[0].Active = False RIGID_REMOTE_CONNECTORS_WORKSHEET.Activate() RIGID_REMOTE_CONNECTORS_WORKSHEET[0].Active = False # Scenario 11 Solve and Review the Results: Solve the system and set the results variables. Note the Scripting window returns the value of any of the variables stored. SOLUTION.Activate() SOLUTION.Solve(True) MAXIMUM_TOTAL_DEFORMATION = TOTAL_DEFORMATION.Maximum.Value MINIMUM_TOTAL_DEFORMATION =TOTAL_DEFORMATION.Minimum.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.