DS WhitePapers Modelling and Simulation-Automation Using VBA R2017x
DS WhitePapers Modelling and Simulation-Automation Using VBA R2017x
3DS.COM
Confidential Information. © [2017] Dassault © Dassault
Systèmes. reserved.
Systèmes
All Rights
3DEXPERIENCE R2017x
White Paper
Executive Summary
3DEXPERIENCE MODELLING AND SIMULATION AUTOMATION USING VBA
The objective of modelling and simulation automation is to reduce the time required for re-
execution of multiple finite element simulation cases with/without minor changes.
3DEXPERIENCE uses VBA as tool for automation which can readily be integrated with other
Microsoft Windows software tools empowering its functionality further.
This document is intended for people such as Simulation Analysts, Tech Support Engineers,
Simulation Consultants, and Field Engineers etc. who want to learn automation in the
simulation domain.
This document covers automation for geometric modelling, searching and applying
materials from the database, mesh creation for solid geometries, setting up the simulation
scenarios, simulation execution and post-processing. It also includes ready to use sample
scripts that users can use to learn from.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
2
White Paper
Contents
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
3
White Paper
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
4
White Paper
In this paper, we have covered automation in the CATIA Part Design, Structural Model
Creation, Structural Scenario Creation and Physics Results Explorer apps.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
5
White Paper
To create a macro library, first launch the 3DEXPERIENCE platform and then follow the
following steps:
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
6
White Paper
a. PLM Directories library type allows users to create a macro of type CATScript or MS
VB Script (VBS). CATScript requires object type declaration explicitly whereas MS
VB Script does not.
b. PLM VBA project library type allows users to create a macro with MS VBA (Visual
Basic for Applications) language. VBA provides a macro editor along with integrated
development environment (IDE) and Object Browser. VBA also supports GUI
creation and customizations.
c. PLM VSTA projects library type allows users to create a macro with VB.NET and C#
languages. VSTA stands for Visual Studio Tools for Applications.
The following sample scripts show the difference between writing styles of all VB
flavours using the ActivePrinter property of the Application object.
Users can find the documentation for VBA basics and its syntax for the Windows
7/8/10 Operating System in a compiled HTML file located at the below location:
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
7
White Paper
4. Click Create new library The Macro library VBA dialog opens.
5. In the Title box, type the title you want to assign to the macro library, or keep the
default name. Click OK. Click Close in the Macro libraries dialog.
9. Paste the following code in the code window and Click on Run
Confidential Information. © [2017] Dassault Systèmes. All Rights reserved.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
8
White Paper
Sub CATMain()
MsgBox "Welcome to Automation in 3DEXPERIENCE"
End Sub
10. A welcome window will appear in the 3DEXPERIENCE graphics area as shown
below.
11. Congratulations! You have run your first macro. Click OK to close the welcome
window.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
9
White Paper
2. Geometry Creation
We can automate the geometry creation and part modelling in the CATIA Part Design
app. For modelling the part we need the following objects.
a. PLMNewService
b. Sketch
c. Shape
d. PLMPropagateService
Note: Users can find relevant documentation about this feature in the
3DEXPERIENCE documentation at:
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
10
White Paper
Sketch
Axis2D
Constraints
Factory2D
GeometricElements
Line2D
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
11
White Paper
' Point1
Dim oPoint1 As Point2D
Set oPoint1 = oFactory2D.CreatePoint(-W, H)
' Point2
Dim oPoint2 As Point2D
Set oPoint2 = oFactory2D.CreatePoint(W, H)
' Line1
Dim oLine1 As Line2D
Set oLine1 = oFactory2D.CreateLine(-W, H, W, H)
oLine1.StartPoint = oPoint1
oLine1.EndPoint = oPoint2
⋮
⋮
We should close the sketch edition after editing the sketch.
The ShapeFactory object is used to add solid modelling features like Pad (Extrude),
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
12
White Paper
3. Materials
This section deals with searching for a material in the database and applying it to a 3D
Part.
Documentation: Native Apps Automation | Content and Simulation Apps | Physics Simulation
| Material Definition | Material Definition Object Model Map
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
13
White Paper
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
14
White Paper
Documentation: Native Apps Automation | Content and Simulation Apps | Physics Simulation
| Multiphysics Model Creation | Multiphysics Model Creation Object Model Map.
' - Creates the FEM representation and retrieves its root object
Dim oPrdRepFactory As SimPrdRepFactory
Set oPrdRepFactory = oRootProduct.GetItem("SimPrdRepFactory")
Dim oFemRepRef As VPMRepReference
Set oFemRepRef = oPrdRepFactory.CreatePrdRep("FEM")
Confidential Information. © [2017] Dassault Systèmes. All Rights reserved.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
15
White Paper
' -
Associates the PartBody with the FEM representation
oReference As Reference
Dim
oReference = oPartM.CreateReferenceFromObject(oBody)
Set
oLink As AnyObject
Dim
oLink = oPLMProductService.ComposeLink(oRootOcc,
Set
oPartInstance, oReference)
oFemRepRoot.AddAssociatedRep oLink
' - Property
Dim oProperties As SimProperties
Set oProperties = oFemRepRoot.GetSet("SimProperties")
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
16
White Paper
oSimInitService.SetSimulationMethod
SimInitializationServiceStructuralMechanics
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
17
White Paper
The object model for Analysis case is documented in the following section:
oAnalysisCase.CreateDefaultElementTypeAssignment
Confidential Information. © [2017] Dassault Systèmes. All Rights reserved.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
18
White Paper
oStaticStep.MaximumIncrements = 1000
The SimFeatures object adds the simulation feature similar to the interactive
feature creation and the SimFeatureStates object commits the action in the same
way as the ‘OK’ action in the GUI mode of a feature creation.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
19
White Paper
The object model description for SimExecutionService can be found in the following
documentation section:
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
20
White Paper
CATIA.StartWorkbench "SMAHvcResultsVisualizationWorkbench"
We can create custom plots for the field and history variables after retrieving the analysis
case.
We can create sensors for field variables by retrieving the ResultsAnalysisCase object and
the CreateSensor method.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
21
White Paper
7. Conclusion
This document provides an overview of modelling and simulation automation in the
3DEXPERIENCE platform by demonstrating an end-to-end automation from geometry
creation to visualization of simulation results. It provides users the scripting walkthroughs for
repetitive tasks along with coding conventions which enables easy debugging of the scripts.
8. References
DS Documentation
9. Document History
Document
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
22
White Paper
10. Appendix
This section provides ready to use scripts for a various automation tasks.
Sub CreateGeometry()
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
23
White Paper
ArrayForAxes(8) = 0#
' Point2
Dim oPoint2 As Point2D
Set oPoint2 = oFactory2D.CreatePoint(W, H)
' Point3
Dim oPoint3 As Point2D
Set oPoint3 = oFactory2D.CreatePoint(W, -H)
' Point4
Dim oPoint4 As Point2D
Set oPoint4 = oFactory2D.CreatePoint(-W, -H)
' Line2
Dim oLine2 As Line2D
Set oLine2 = oFactory2D.CreateLine(W, H, W, -H)
oLine2.EndPoint = oPoint2
oLine2.StartPoint = oPoint3
' Line3
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
24
White Paper
' Line4
Dim oLine4 As Line2D
Set oLine4 = oFactory2D.CreateLine(-W, -H, -W, H)
oLine4.EndPoint = oPoint4
oLine4.StartPoint = oPoint1
oCircle2D.CenterPoint = oPoint2D5
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
25
White Paper
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
26
White Paper
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
27
White Paper
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
28
White Paper
' - Creates the FEM representation and retrieve its root object
Dim oPrdRepFactory As SimPrdRepFactory
Set oPrdRepFactory = oRootProduct.GetItem("SimPrdRepFactory")
Dim oFemRepRef As VPMRepReference
Set oFemRepRef = oPrdRepFactory.CreatePrdRep("FEM")
Dim oFemRepRoot As SimFemRoot
Set oFemRepRoot = oFemRepRef.GetItem("SimFemRoot")
oReference As Reference
Dim
oReference = oPartM.CreateReferenceFromObject(oBody)
Set
oLink As AnyObject
Dim
oLink = oPLMProductService.ComposeLink(oRootOcc,
Set
oPartInstance, oReference)
oFemRepRoot.AddAssociatedRep oLink
Confidential Information. © [2017] Dassault Systèmes. All Rights reserved.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
29
White Paper
' - Checks if the FEM representation have at least one associated shape
Dim bHasAnAssociatedRep As Boolean
bHasAnAssociatedRep = oFemRepRoot.HasAnAssociatedRep
If (bHasAnAssociatedRep = False) Then
MsgBox "Error while associating the PartBody to the FEM Rep!"
Exit Sub
End If
' - Property
Dim oProperties As SimProperties
Set oProperties = oFemRepRoot.GetSet("SimProperties")
End Sub
GetPart Sub:
You can use the GetPart procedure for an interactive selection of the part geometry.
Public myLinkOnFeature
Public oPart
Sub GetPart()
MsgBox "Select support for Meshing"
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
30
White Paper
'
'' - Prompt the user to select a body
Dim varFilter(0) As Variant
Dim objSel As Selection
Dim objSelLB As Object
Dim strReturn As String
Dim strMsg As String
varFilter(0) = "Part"
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
31
White Paper
End Sub
' - Associating the Structural Analysis Case with the FEM rep
Dim oAnalysisCases As SimAnalysisCases
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
32
White Paper
oAnalysisCase.FEMRep = oFEMRoot
oAnalysisCase.CreateDefaultElementTypeAssignment
oStaticStep.MaximumIncrements = 1000
oStaticStep.CreateAnalysisDefaultOutputRequests
Sub CreateSensor()
Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
33
White Paper
End If
Dim oSimResults As SimulationResults
Set oSimResults = oSimulationReferenceNew.Results
End Sub
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
34
White Paper
About Author
Our 3DEXPERIENCE® platform powers our brand applications, serving 12 industries, and provides a rich
portfolio of industry solution experiences.
Dassault Systèmes, the 3DEXPERIENCE® Company, provides business and people with virtual universes
to imagine sustainable innovations. Its world-leading solutions transform the way products are
ial innovation,
expanding possibilities for the virtual world to improve the real world. The group brings value to over
210,000 customers of all sizes in all industries in more than 140 countries. For more information, visit
www.3ds.com.
This document is intended for internal use only and is provided for information purpose. Any other use without the written prior authorization from
Dassault Systèmes is strictly prohibited, except as may be permitted by law.
35