0% found this document useful (0 votes)
203 views35 pages

DS WhitePapers Modelling and Simulation-Automation Using VBA R2017x

Uploaded by

Speedriser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views35 pages

DS WhitePapers Modelling and Simulation-Automation Using VBA R2017x

Uploaded by

Speedriser
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

White Paper

Best Practices for Automation in


Modelling, Simulation & Results in
the 3DEXPERIENCE Physics Apps

3DS.COM
Confidential Information. © [2017] Dassault © Dassault
Systèmes. reserved.
Systèmes
All Rights

Version 1.0 - 6/1/2017

Written by: Sagar POHEKAR


Validated by: Srikanth KANNAN
Edited by: Véronique LECOEUR

3DEXPERIENCE R2017x
White Paper

Executive Summary
3DEXPERIENCE MODELLING AND SIMULATION AUTOMATION USING VBA

Materials & Scenario &


Geometric Post -
Mesh Simulation
Modelling Processing
Generation Execution

3DS.COM © Dassault Systèmes


Automation in the 3DEXPERIENCE platform is a powerful solution available for various
domains and provides a complete set of dedicated APIs which allows users to create, model
and execute the multiphysics simulations.

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.

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.

2
White Paper

Contents

1. Introduction to Automation in 3DEXPERIENCE ............................................................. 5


1.1. Getting Started with Automation ................................................................................. 5
1.1.1. Writing Your First Macro ......................................................................................... 5
2. Geometry Creation....................................................................................................... 10
2.1. How to create a 3D Part using the PLMNewService Object ...................................... 10
2.2. How to retrieve and edit the sketch from a Partbody? ............................................... 10
3. Materials ...................................................................................................................... 13
3.1. How to search for a Core Material in the Database .................................................. 13
3.2. How to apply a Core Material to a 3D Part................................................................ 13
4. Finite Element Model (FEM) and Mesh Creation .......................................................... 15
4.1. Steps to create a FEM Representation and Mesh Generation: ................................ 15

3DS.COM © Dassault Systèmes


4.1.1. Retrieve the Root Product ..................................................................................... 15
4.1.2. Create FEM Representation and retrieve its root object ........................................ 15
4.1.3. Associate PartBody with FEM ............................................................................... 16
4.1.4. Generate the Mesh and specify its attributes ........................................................ 16
4.1.5. Create a Section Property ..................................................................................... 16
5. Scenario Creation and Simulation Execution ............................................................... 17
5.1. Scenario and Simulation Features Creation ............................................................. 17
5.1.1. Initialize the simulation method ............................................................................. 17
5.1.2. Create a Scenario ................................................................................................. 17
5.1.3. Associate Analysis Case with FEM ....................................................................... 18
5.1.4. Add Simulation Steps to the scenario.................................................................... 18
5.1.5. Create Simulation Features .................................................................................. 19
5.2. Simulation Execution ................................................................................................ 19
6. Simulation Results and Post-processing ...................................................................... 21
7. Conclusion ................................................................................................................... 22
8. References .................................................................................................................. 22
9. Document History ........................................................................................................ 22
10. Appendix .................................................................................................................. 23

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.

3
White Paper

10.1. Geometric Modelling: Create a Plate with a Hole .................................................. 23


10.2. Search Material from the Database. ...................................................................... 25
10.2.1. Search Core Material......................................................................................... 26
10.2.2. Apply Material ................................................................................................... 27
10.3. Creating FEM Rep and Mesh ................................................................................ 28
10.4. Scenario Creation ................................................................................................. 32
10.5. Sensor Creation .................................................................................................... 33
10.6. Knowledge base Articles on VB Automation ......................................................... 34

3DS.COM © Dassault Systèmes

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.

4
White Paper

1. Introduction to Automation in 3DEXPERIENCE


The 3DEXPERIENCE platform increases our productivity by enabling the use of the VB
scripting language for automation. Repetitive tasks can be automated for customized
applications. Automation in the 3DEXPERIENCE platform is supported for a wide range of
apps as shown below.

3DS.COM © Dassault Systèmes


Figure 1.1 3DEXPERIENCE Automatable apps

In this paper, we have covered automation in the CATIA Part Design, Structural Model
Creation, Structural Scenario Creation and Physics Results Explorer apps.

1.1. Getting Started with Automation


This section shows how to get started with automation of a simple example.

1.1.1. Writing Your First Macro


To run a Macro, you will need a macro library.

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.

5
White Paper

To create a macro library, first launch the 3DEXPERIENCE platform and then follow the
following steps:

1. Hit Alt + F8 to create a macro library  The Macros dialog opens.

2. Click Macro libraries.  The Macro libraries dialog opens

3DS.COM © Dassault Systèmes


3. In the Library type list, select PLM VBA projects.

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.

6
White Paper

Three library types are available:

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.

Languages Code Comments


Dim oPrinter As Printer The variable oPrinter is declared
CATScript Set oPrinter = using the Dim keyword and typed
CATIA.ActivePrinter using the As keyword.
Dim oPrinter The variable oPrinter is declared
VB Script Set oPrinter = using the Dim keyword, but not
CATIA.ActivePrinter typed.
Dim oPrinter As Printer The variable oPrinter is declared
VBA Set oPrinter = using the Dim keyword and typed

3DS.COM © Dassault Systèmes


CATIA.ActivePrinter using the As keyword.
The variable oPrinter is declared
using the Dim keyword and typed
Dim oPrinter As INFITF.Printer using the As keyword by using the
VB.NET Set oPrinter = name of the type library containing
CATIA.ActivePrinter the object as namespace. The
variable value is assigned without
using the Set keyword.
The variable oPrinter is declared
private INFITF.Printer oPrinter; and typed outside of the function
...
using the private keyword and by
private void GetActivePrinter()
C# {oPrinter = CATIA.ActivePrinter; using the name of the type library
... containing the object as namespace.
} The variable value is assigned
without using the Set keyword.

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:

C:\ Program Files (x86)\Common Files\microsoft shared\VBA\VBA7.1\1033\


VBUI6.CHM
Note: Users should install VBA while installing the 3DEXPERIENCE platform.

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.

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.

3DS.COM © Dassault Systèmes


6. Click Create in the Macros dialog.  The Create a new macro dialog box opens.
We have selected MS VBA for the macro as MS VBA provides integrated macro
editor and debugger which speeds up the automation process. Also, MS VBA
provides the Object browser which helps the user to understand the object model
and the usage of object methods and attributes.

7. Click OK  The Create a new macro dialog box closes.


8. Click Edit  The Microsoft Visual Basic for Applications window opens. The current
project is opened, the new module is current, and the code window for this module is
opened.

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.

3DS.COM © Dassault Systèmes

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.

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

2.1. How to create a 3D Part using the PLMNewService Object


The PLMNewService object along with the Editor is used to create a new PLM
entity. The Editor associates all the objects that can be interactively edit in the same
window.

Use the following script to create a 3D Part:

' - Retrieve Editor


Coding Convention
Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor
Use VBA coding
convention, which helps to ' - Retrieve Session Service object to
improve the readability of create a new PLM Object
script Dim oPLMNewService As PLMNewService

3DS.COM © Dassault Systèmes


Set oPLMNewService =
Study the CATIA object
CATIA.GetSessionService("PLMNewService")
model to know the
supported automation ' - Create a new 3DPart
types. oPLMNewService.PLMCreate
"3DPart", oEditor

Note: Users can find relevant documentation about this feature in the
3DEXPERIENCE documentation at:

Documentation: Native Apps Automation | Common Services | Representation


Modelers | Mechanical Modeler | Mechanical Objects | Part Object

2.2. How to retrieve and edit the sketch from a Partbody?


The Sketch Object is a collection of objects that define and modify the sketch.
The Sketch object contains a Factory2D object which allows the user to create 2D
geometric elements and these elements get stored in the GeometricElements
collection under the Sketch object. To create geometric elements, the user needs to
open the sketch using the OpenEdition method available under the Sketch object.
The sketch can be closed using the CloseEdition method. The OpenEdition and

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.

10
White Paper

CloseEdition methods correspond to and commands respectively that let


the user edit and close the sketch through scripting.

The Sketch object contains the following set of objects:

Sketch
Axis2D
Constraints
Factory2D
GeometricElements
Line2D

To add geometric elements to the sketch, the user


needs to retrieve it from the 3DPart created earlier.
Autosuggestion
' - Retrieve Part Body
Press Ctrl + Space Dim oPart As Part
after the period (.) to Set oPart = oEditor.ActiveObject
popup autosuggestion
Dim oBodies As Bodies
and to find the
Set oBodies = oPart.Bodies
available methods for

3DS.COM © Dassault Systèmes


the current object. Dim oBody As Body
Right click just after Set oBody = oBodies.Item("PartBody")
the period (.) and then
' - Retrieve Axis, Skechtes and
go to Definition to find References
the usage of the Dim oSketches As Sketches
method and its Set oSketches = oBody.Sketches
argument’s type for the
current object. ' - Open the Sketch for editing
Dim oFactory2D As Factory2D
Set oFactory2D = oSketch.OpenEdition()

After editing a sketch, we can add geometric features.

' - Add Axes definition, Points, Lines etc.


Dim oGeometricElements As GeometricElements
Set oGeometricElements = oSketch.GeometricElements

Dim oAxis2D As Axis2D


Set oAxis2D = oGeometricElements.Item("AbsoluteAxis")

Dim oLine2D1 As Line2D


Set oLine2D1 = oAxis2D.GetItem("HDirection")

Dim oLine2D2 As Line2D


Set oLine2D2 = oAxis2D.GetItem("VDirection")

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.

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.

' - Close the opened sketch


oSketch.CloseEdition()

The ShapeFactory object is used to add solid modelling features like Pad (Extrude),

3DS.COM © Dassault Systèmes


and the PLMPropagateService object is used to propagate it. Users can find detailed
descriptions of the ShapeFactory object in the documentation:

Documentation: Native Apps Automation | Common Services | Representation


Modelers | Mechanical Modeler | Mechanical Objects | Part Object Model Map |
ShapeFactory

' - Creating a PAD


Dim oShapeFactory As ShapeFactory
Set oShapeFactory = oPart.ShapeFactory

Dim pad1 As Pad


Set pad1 = oShapeFactory.AddNewPad(oSketch, 4#)

' - Update the Part


oPart.Update

' - Saving a Part


Dim oPLMProService As PLMPropagateService
Set oPLMProService =
CATIA.GetSessionService("PLMPropagateService")
oPLMPropService.Save

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.

12
White Paper

3. Materials
This section deals with searching for a material in the database and applying it to a 3D
Part.

3.1. How to search for a Core Material in the Database


To search for a core material in the database, the MATPLMService and SearchService
objects are used. The MATPLMService object allows the user to create and retrieve
materials. We can retrieve materials loaded in the session as a List object. The
SearchService object returns the material as a PLMEntity. We can find the object model for
materials and description on MATPLMService in the documentation in the below section:

Documentation: Native Apps Automation | Content and Simulation Apps | Physics Simulation
| Material Definition | Material Definition Object Model Map

1. Retrieve MATPLMService as a Session Service from CATIA.

' - Retrieve Material Service


Dim oMatPLMService As MATPLMService
Set oMatPLMService = CATIA.GetSessionService("MATPLMService")

2. Retrieve SearchService as a Session Service from CATIA.

3DS.COM © Dassault Systèmes


' - Search Service
Dim oSearchService As SearchService
Set oSearchService = CATIA.GetSessionService("Search")
Dim oDBSearch As DatabaseSearch
Set oDBSearch = oSearchService.DatabaseSearch

3. Provide the type of material to be searched for in the database

' - Setting Type Name


oDBSearch.BaseType = "dsc_matref_ref_Core"
oDBSearch.AddEasyCriteria "V_Name", MatSearchKey
oSearchService.Search
numMat = oDBSearch.Results.Count

' - Save Database Results


Dim myMatList As Object
Set myMatList = oDBSearch.Results

3.2. How to apply a Core Material to a 3D Part


We can retrieve the part object either interactively or by navigating through the product.
The PLMProductService object is used to compose a link between the product feature to
which we want to apply the material and its root part. The SetCoreMaterial method from the
MATPLMService object can be used to apply a material to a 3DPart.
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.

13
White Paper

' - Retrieves the Product Service


Dim oProductService As PLMProductService
Set oProductService = CATIA.GetSessionService("PLMProductService")

' - Retrieves the Material Service


Dim MatService As MATPLMService
Set MatService = CATIA.GetSessionService("MATPLMService")

Set myLinkOnFeature = oProductService.ComposeLink(NoOcc,


oRepInstance, MyReference)

MatService.SetMaterialCore myLinkOnFeature, myCoreMatRef,


MyCoreAppliedMat

3DS.COM © Dassault Systèmes

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.

14
White Paper

4. Finite Element Model (FEM) and Mesh Creation


The SimPrdRepFactory object allows the user to create the FEM representation and
mesh generation. The user needs to specify meshing attributes such as the mesh size,
element order and the type of meshing technique etc. We can use the VBA Form object for
interactive inputs from the user. The object model for objects used in this section can be
found in the following section in the documentation:

Documentation: Native Apps Automation | Content and Simulation Apps | Physics Simulation
| Multiphysics Model Creation | Multiphysics Model Creation Object Model Map.

4.1. Steps to create a FEM Representation and Mesh


Generation:
Retrieve Root Product
Retrieve the PartBody
Create FEM Representation and retrieve its root object
Associate PartBody with FEM
Generate Mesh and specify its attributes
Create Section Property

3DS.COM © Dassault Systèmes


4.1.1. Retrieve the Root Product
The RootOccurrence method from the PLMProductService object allows
users to retrieve the root product. It returns PLMEntity as the object type.

' - Retrieves the root product


Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

Dim oPLMProductService As PLMProductService


Set oPLMProductService =
oEditor.GetService("PLMProductService")

Dim oRootOcc As VPMRootOccurrence


Set oRootOcc = oPLMProductService.RootOccurrence

Dim oRootProduct As VPMReference


Set oRootProduct = oRootOcc.PLMEntity

4.1.2. Create FEM Representation and retrieve its root object


Use the CreatePrdRep method of the SimPrdrepFactory object to create the
FEM representation.

' - 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

Dim oFemRepRoot As SimFemRoot


Set oFemRepRoot = oFemRepRef.GetItem("SimFemRoot")

4.1.3. Associate PartBody with FEM


Interactively we use the contributing parts manager dialog to include parts in the
FEM representation. This can be achieved through scripting using the following code
snippet.

' -
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

4.1.4. Generate the Mesh and specify its attributes


Use the Add method of the SimMeshParts object to mesh the solid geometries.

' - Retrieves the mesh set


Dim oMeshSet As SimMeshSet

3DS.COM © Dassault Systèmes


Set oMeshSet = oFemRepRoot.GetSet("SimNodesElements")
Dim oMeshParts As SimMeshParts
Set oMeshParts = oMeshSet.MeshParts
Dim oMeshPart As SimMeshPart
Set oMeshPart = oMeshParts.Add("CATFmtOctree3DRulesMesher")
oMeshPart.SetAttributeValue "Mesh", "MeshSizeValue",
MeshSize
oMeshPart.SetAttributeValue "Mesh", "ElementOrder", ElmOrd

4.1.5. Create a Section Property


Users can create section properties using the Add method available in the
SimProperties object. To select the support for the section, the SimLinkAccess
object is required. The PLMProductService object enables the user to compose a
link between the geometric feature and section property.

' - Property
Dim oProperties As SimProperties
Set oProperties = oFemRepRoot.GetSet("SimProperties")

Dim oSolidSection As SimSolidSection


Set oSolidSection = oProperties.Add("SimSolidSection")

' - Set Property support


Dim oLinkAccess As SimLinkAccess
Set oLinkAccess = oSolidSection.GetItem("SimLinkAccess")
oLinkAccess.AddLink "MainSupport", 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.

16
White Paper

5. Scenario Creation and Simulation Execution


This section deals with the scenario creation and executing the simulation.

5.1. Scenario and Simulation Features Creation


To create the scenario, we require a physical product along with its finite element
model. We need to associate the finite element model with the Analysis Case to add
simulation features to the simulation object. The SimInitializationService object is used
to set the simulation method for a scenario. To create a scenario the PLMCreate method
of the SIMPLMService object is called with appropriate arguments.

Steps to create a scenario:

Initialize the simulation method


Create a Scenario
Associate the Analysis Case with FEM
Add Simulation Steps to the scenario
Create Simulation Features

5.1.1. Initialize the simulation method


The type of scenario (Structural or Thermal) can be specified using the

3DS.COM © Dassault Systèmes


SimInitializationService object.

Dim oEditor As Editor


Set oEditor = CATIA.ActiveEditor

' - Initialize Simulation Method


Dim oSimInitService As SimInitializationService
Set oSimInitService =
CATIA.GetSessionService("SimInitializationService")

oSimInitService.SetSimulationMethod
SimInitializationServiceStructuralMechanics

5.1.2. Create a Scenario


The PLMCreate method is used to create any PLM object. In this case, the
PLMCreate method from the SIMPLMService object is used to create the scenario.
The documentation for the object model of the SIMPLMService can be found in the
following section:

Documentation: Native Apps Automation | Common Services | VB Programming


Basis | Foundation Objects | Foundation Object Model Map - SIMPLMService

' - Create Scenario


Dim oSimPLMService As SIMPLMService
Set oSimPLMService = CATIA.GetSessionService("SIMPLMService")

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.

17
White Paper

Dim oPLMProductService As PLMProductService


Set oPLMProductService = oEditor.GetService("PLMProductService")

Dim oEntities As PLMEntities


Set oEntities = oPLMProductService.EditedContent
Dim oModel As VPMReference
Set oModel = oEntities.Item(1)

Dim oSimulationReference As SimulationReference


oSimPLMService.PLMCreate "Static Analysis of Plate with Hole",
"SMAFeaPLMNewSimu", oModel, oSimulationReference, oEditor

5.1.3. Associate Analysis Case with FEM


To specify the finite element model for an analysis case, the FEMRep method of the
AnalysisCase object can be used.

The object model for Analysis case is documented in the following section:

Documentation: Native Apps Automation | Content and Simulation Apps | Physics


Simulation | Multiphysics Scenario Creation | Multiphysics Scenario Creation Object
Model Map – SimAnalysisCase

3DS.COM © Dassault Systèmes


' - Associating the Structural Analysis Case with the FEM rep

Dim oScenarioManager As SimScenarioManager


Set oScenarioManager =
oSimulationReference.GetItem("SimScenarioManager")

Dim oAnalysisCases As SimAnalysisCases


Set oAnalysisCases = oScenarioManager.AnalysisCases

Dim oAnalysisCase As SimAnalysisCase


Set oAnalysisCase = oAnalysisCases.Item(1) We need to retrieve
SimFemRoot of an
oAnalysisCase.FEMRep = oFEMRoot active product

5.1.4. Add Simulation Steps to the scenario


The Steps property of an AnalysisCase object stores all the simulation step
dependent data and a particular step can be added or retrieved from it.

' - Creating and initializing the static step


Dim oSteps As SimSteps
Set oSteps = oAnalysisCase.Steps

Dim oStaticStep As SimStaticStep


Set oStaticStep = oSteps.Add("SimStaticStep")

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

5.1.5. Create Simulation Features


To add simulation features to a particular step in an analysis case, the
SimFeatures and SimFeatureStates objects are used. The SimFeatures and
SimFeatureStates objects belong to the Analysis case and Step objects
respectively.

The object model for SimFeatures is documented in the following section:

Documentation: Native Apps Automation | Content and Simulation Apps | Physics


Simulation | Multiphysics Scenario Creation | Multiphysics Scenario Creation Object
Model Map – Simulation Feature Objects.

Steps to create Simulation Features:

Retrieve SimFeatures and SimFeatureStates

Dim oFeatures As SimFeatures


Set oFeatures = oAnalysisCase.Features

Dim oFeatureStates As SimFeatureStates


Set oFeatureStates = oStaticStep.FeatureStates

3DS.COM © Dassault Systèmes


Add simulation features to Step

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.

Dim oFeatures As SimFeatures


Set oFeatures = PlateStaticAnalysis.SimFeatures
Dim oFeatureStates As SimFeatureStates
Set oFeatureStates = PlateStaticAnalysis.SimFeaturesStates

' - Creating Clamp Feature


Dim oClamp As SimClamp We need to select Support
Set oClamp = oFeatures.Add("SimClamp") for feature creation either
Set oLinkAccess = oClamp.GetItem("SimLinkAccess") interactively or with use of
Dim Support As AnyObject Publications.
oLinkAccess.AddLink "MainSupport", Support
oFeatureStates.CreateFeatureState oClamp

5.2. Simulation Execution


The SimExecutionService object is used to execute the simulation. The user needs to
retrieve the SimExecutionService service from the active editor and call the
BasicExecuteAll method to start the execution. The BasicExecuteAll method requires the
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.

19
White Paper

SimulationReference object which stores the reference of the simulation object to be


created before.

The object model description for SimExecutionService can be found in the following
documentation section:

Documentation: Native Apps Automation | Common Services | VB Programming Basis |


Foundation Objects | Foundation Object Model Map – SimExecutionService

' - Executing Simulation


Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

Dim oExecutionService As SimExecutionService


Set oExecutionService = oEditor.GetService("SimExecutionService")
oExecutionService.BasicExecuteAll oSimulationReference

3DS.COM © Dassault Systèmes

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.

20
White Paper

6. Simulation Results and Post-processing


To visualize the simulation results we can switch to the Physics Results Explorer app.
The graphics area displays the field or history plots as per the output request created during
the scenario creation.

Use the below command to switch to the Physics Results Explorer:

CATIA.StartWorkbench "SMAHvcResultsVisualizationWorkbench"

We can create custom plots for the field and history variables after retrieving the analysis
case.

Dim oFieldPlots As SimResultsSet


Set oFieldPlots = oResultsAnalysisCase.GetSet("FieldPlot")

Dim oFieldPlot As SimFieldPlot


We need to retrieve the
Set oFieldPlot = oFieldPlots.Item(1)
ResultsAnalysisCase to
access the Results Sets
Dim sId As String
sId = "Contour_Stress_Tresca"
Dim oPlot As SimFieldPlot

3DS.COM © Dassault Systèmes


Set oPlot = oResultsAnalysisCase.CreateFieldPlotByID(sId, True)

We can create sensors for field variables by retrieving the ResultsAnalysisCase object and
the CreateSensor method.

Dim oSensor As SimSensor


Set oSensor = oResultsAnalysisCase.CreateSensor
oSensor.VariableType = "S" We can specify sensor
oSensor.ProcessingType = SimTensors parameters, its output
oSensor.Location = SimNodes position and the frame using
oSensor.Averaging = SimSectionBoundaries the available methods
oSensor.PrincipalDirection = True
Dim oFrameSelector As SimFramesSelection
Set oFrameSelector = oResultsAnalysisCase.CreateFrameSelector
oFrameSelector.SymbolicFrameRange = SimAllFrames
oSensor.FrameSelector = oFrameSelector

' - Set Parameters


oSensor.SetParameters True, True, True, True, True
oSensor.Update

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.

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.

After carefully studying this document you should be able to:

Create geometries and add solid modelling features to it.


Search and apply materials from the database.
Mesh the 3DParts.
Create simulation scenarios and simulation features.
View the simulation results and post-process it.

8. References
DS Documentation

9. Document History
Document

3DS.COM © Dassault Systèmes


Revision Date Revised By Changes/Notes

1.0 2/3/2017 Original

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.

22
White Paper

10. Appendix
This section provides ready to use scripts for a various automation tasks.

10.1. Geometric Modelling: Create a Plate with a Hole

Sub CreateGeometry()

' - Retrieve Editor


Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

' - Retrieve Session Service object to create a new PLM Object


Dim oPLMNewService As PLMNewService
Set oPLMNewService = CATIA.GetSessionService("PLMNewService")

' - Create a new 3DPart


oPLMNewService.PLMCreate "3DPart", oEditor

' - Retrieve Part Body


Dim oPart As Part
Set oPart = oEditor.ActiveObject

Dim oBodies As Bodies

3DS.COM © Dassault Systèmes


Set oBodies = oPart.Bodies

Dim oBody As Body


Set oBody = oBodies.Item("PartBody")

' - Retrieve Axis, Skechtes and Sketching References


Dim oSketches As Sketches
Set oSketches = oBody.Sketches

Dim oOriginElements As OriginElements


Set oOriginElements = oPart.OriginElements

Dim oReference As Reference


Set oReference = oOriginElements.PlaneXY

Dim oSketch As Sketch


Set oSketch = oSketches.Add(oReference)

' - Define Array for Axes Definition


Dim ArrayForAxes(8)
ArrayForAxes(0) = 0#
ArrayForAxes(1) = 0#
ArrayForAxes(2) = 0#
ArrayForAxes(3) = 1#
ArrayForAxes(4) = 0#
ArrayForAxes(5) = 0#
ArrayForAxes(6) = 0#
ArrayForAxes(7) = 1#

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.

23
White Paper

ArrayForAxes(8) = 0#

' - Open the Sketch for editing


Dim oFactory2D As Factory2D
Set oFactory2D = oSketch.OpenEdition()

Dim oGeometricElements As GeometricElements


Set oGeometricElements = oSketch.GeometricElements

Dim oAxis2D As Axis2D


Set oAxis2D = oGeometricElements.Item("AbsoluteAxis")

Dim oLine2D1 As Line2D


Set oLine2D1 = oAxis2D.GetItem("HDirection")

Dim oLine2D2 As Line2D


Set oLine2D2 = oAxis2D.GetItem("VDirection")

' - Create Rectangle


W = 50 'Width
H = 25 'Length
R = 15 'Radius

' - Add four corner points for rectangle


' Point1

3DS.COM © Dassault Systèmes


Dim oPoint1 As Point2D
Set oPoint1 = oFactory2D.CreatePoint(-W, H)

' 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)

' - Add four lines of Rectangle


' Line1
Dim oLine1 As Line2D
Set oLine1 = oFactory2D.CreateLine(-W, H, W, H)
oLine1.StartPoint = oPoint1
oLine1.EndPoint = oPoint2

' Line2
Dim oLine2 As Line2D
Set oLine2 = oFactory2D.CreateLine(W, H, W, -H)
oLine2.EndPoint = oPoint2
oLine2.StartPoint = oPoint3

' Line3

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.

24
White Paper

Dim oLine3 As Line2D


Set oLine3 = oFactory2D.CreateLine(W, -H, -W, -H)
oLine3.StartPoint = oPoint3
oLine3.EndPoint = oPoint4

' Line4
Dim oLine4 As Line2D
Set oLine4 = oFactory2D.CreateLine(-W, -H, -W, H)
oLine4.EndPoint = oPoint4
oLine4.StartPoint = oPoint1

' - Create Circle


Dim oCircle2D As Circle2D
Set oCircle2D = oFactory2D.CreateClosedCircle(0#, 0#, R)

Dim oPoint2D5 As Point2D


Set oPoint2D5 = oAxis2D.GetItem("Origin")

oCircle2D.CenterPoint = oPoint2D5

' - Close the opened sketch


oSketch.CloseEdition

' - Add Sketch as in-work object


oPart.InWorkObject = oSketch

3DS.COM © Dassault Systèmes


' - Update the Part
oPart.Update

' - Creating a PAD


Dim oShapeFactory As ShapeFactory
Set oShapeFactory = oPart.ShapeFactory

Dim pad1 As Pad


Set pad1 = oShapeFactory.AddNewPad(oSketch, 4#)

' - Update the Part


oPart.Update

' - Saving a Part


Dim oPLMPropagateService As PLMPropagateService
Set oPLMPropagateService =
CATIA.GetSessionService("PLMPropagateService")
oPLMPropagateService.Save

MsgBox "Plate Successfully Created"


End Sub

10.2. Search Material from the Database.


This script allows you to search a core material from the database and store the
materials in a list.

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.

25
White Paper

10.2.1. Search Core Material


Sub MaterialSearch()
' - Retrieve Material Service
Dim oMatPLMService As MATPLMService
Set oMatPLMService = CATIA.GetSessionService("MATPLMService")

Dim oMaterial As Object


Dim matName As Variant
Dim matNames As String
matNames = ""

' - Search Service


Dim oSearchService As SearchService
Set oSearchService = CATIA.GetSessionService("Search")
Dim oDBSearch As DatabaseSearch
Set oDBSearch = oSearchService.DatabaseSearch

Dim inStrMat As String


Dim numMat As Integer
numMat = 1
inStrMat = InputBox("Enter search key term to search
Material", _
"Material Search String", "spr6")

' - Setting Type Name

3DS.COM © Dassault Systèmes


oDBSearch.BaseType = "dsc_matref_ref_Core"
oDBSearch.AddEasyCriteria "V_Name", inStrMat
oSearchService.Search
numMat = oDBSearch.Results.Count

' - Save Database Results


Dim myMatList As Object
Set myMatList = oDBSearch.Results
Set GLmatList = oDBSearch.Results

' - Adding Materials to Listbox


Dim iMat As Integer
For iMat = 1 To myMatList.Count()
Set oMaterial = myMatList.Item(iMat)
matName = oMaterial.Name
ListBox1.AddItem matName
matNames = matNames + matName + vbCrLf
Next
' - Show Availabe Materials in Session
If numMat > 0 Then
MsgBox "Following Materials are in the database " & vbCrLf &
matNames
Else
MsgBox "There are no materials with provided search key, Try
again", vbInformation
End If
End Sub

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.

26
White Paper

10.2.2. Apply Material


This subroutine can be called on the Click event of a form object by providing two
objects MATPLMService and Core Material as input arguments to the ApplyMat function
properly.

Public PartName As String


Sub ApplyMat (ByRef MatService, ByRef myCoreMatRef)

MsgBox "Select part"

' - Retrieves PLMNewService


Dim oPLMNewService As PLMNewService
Set oPLMNewService = CATIA.GetSessionService("PLMNewService")

' - Retrieves Editor


Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

'' - 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"

3DS.COM © Dassault Systèmes


Set objSel = oEditor.Selection
Put here the name of the form
Set objSelLB = objSel
strMsg = "Select a part" object that you want to hide
objSel.Clear
‘PlateStaticAnalysis.hide
strReturn = objSelLB.SelectElement2(varFilter, strMsg, False)
Set objSelLB = objSel
Dim oPart As Part
Set oPart = objSelLB.Item2(1).Value
'MsgBox "Name of selected part is: " & oPart.Name
PartName = oPart.Name

' - Retrieves the active Object


Dim oPart As Part
Set oPart = oEditor.ActiveObject

' - Retrieves the VPMRepReference


Dim oVPMRepRef As VPMRepReference
Set oVPMRepRef = oPart.Parent

' - Retrieves the PartBody


Dim oPartBody As Body
Set oPartBody = oPart.MainBody

' - Retrieves the Reference of 3DPart


Dim oRootRef As VPMReference
Set oRootRef = oVPMRepRef.Father

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.

27
White Paper

' - Retrieves the RepInstance


Dim oRepInstance As VPMRepInstance
Dim ListInstance As VPMRepInstances
Set ListInstance = oRootRef.RepInstances
Set oRepInstance = ListInstance.Item(1)

' - Retrieves the Product Service


Dim oProductService As PLMProductService
Set oProductService = CATIA.GetSessionService("PLMProductService")

' - Retrieves the Root Occurrence


Dim MyVPMRootOcc As VPMRootOccurrence
Set MyVPMRootOcc = oProductService.RootOccurrence

' -Compose link


NoRef
Dim As VPMReference
NoRepInst As PLMEntity
Dim
NoOcc
Dim As VPMOccurrence
'- Retrieves the Material Service
MatService As MATPLMService
Dim
MatService = CATIA.GetSessionService("MATPLMService")
Set
MyReference = oPart.CreateReferenceFromObject(oPartBody)
Set
myLinkOnRootOcc = oProductService.ComposeLink(MyVPMRootOcc,
Set
NoRepInst, NoRef)
Set myLinkOnRepInst = oProductService.ComposeLink(NoOcc,
oRepInstance, NoRef)

3DS.COM © Dassault Systèmes


Set myLinkOnFeature = oProductService.ComposeLink(NoOcc,
oRepInstance, MyReference)
MatService.SetMaterialCore myLinkOnRootOcc, myCoreMatRef,
MyCoreAppliedMat
MatService.SetMaterialCore myLinkOnRepInst, myCoreMatRef,
MyCoreAppliedMat
MatService.SetMaterialCore myLinkOnFeature, myCoreMatRef,
MyCoreAppliedMat
End Sub

10.3. Creating FEM Rep and Mesh


Declare the public variables (such as oSelectedPart etc.) and set them from within
the Sub procedure which can be used later for further processing. For MeshPart Sub, users
need to provide three arguments (MeshingType, ElmOrd and MeshSize) and can
initiate them prior to calling the Sub.

MeshingType : This variable allows user to specify the meshing technique


ElmOrd : To specify order of elements (.i.e. Linear or Parabolic)
MeshSize : To specify the mesh size for the part geometry

Declare public variables, which can act as module


attributes & can store objects for further processing

Public oSelectedPart As Part


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.

28
White Paper

Public oFEMRoot As SimFemRoot

Sub MeshPart(ByVal MeshingType As String, ByVal ElmOrd As String, ByVal


MeshSize As String)
' - Retrieves the root product
Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

Dim oPLMProductService As PLMProductService


Set oPLMProductService = oEditor.GetService("PLMProductService")

Dim oRootOcc As VPMRootOccurrence


Set oRootOcc = oPLMProductService.RootOccurrence

Dim oRootProduct As VPMReference


Set oRootProduct = oRootOcc.PLMEntity

' - Retrieves the PartBody


Dim oProductService As PLMProductService
Set oProductService = oEditor.GetService("PLMProductService")

Dim oPartM As Part


Dim oPartInstance As VPMRepInstance
Dim oBody As Body

Dim oRef As VPMReference

3DS.COM © Dassault Systèmes


Set oRef = oProductService.EditedContent.Item(1)

Dim oReps As VPMRepInstances


Set oReps = oRef.RepInstances
Dim oRep As VPMRepInstance
Set oRep = oReps.Item(1)
Dim oRepRef As VPMRepReference
Set oRepRef = oRep.ReferenceInstanceOf
Set oPart = oRepRef.GetItem("Part")
Set oPartInstance = oRep
Set oBody = oPart.MainBody

' - 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")

' - 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
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

' - Retrieves the mesh set


Dim oMeshSet As SimMeshSet
Set oMeshSet = oFemRepRoot.GetSet("SimNodesElements")
Dim oMeshParts As SimMeshParts
Set oMeshParts = oMeshSet.MeshParts

' - Property
Dim oProperties As SimProperties
Set oProperties = oFemRepRoot.GetSet("SimProperties")

Dim oSolidSection As SimSolidSection


Set oSolidSection = oProperties.Add("SimSolidSection")

' Sets the section support


Dim oLinkAccess As SimLinkAccess
Set oLinkAccess = oSolidSection.GetItem("SimLinkAccess")
oLinkAccess.AddLink "MainSupport", oLink

3DS.COM © Dassault Systèmes


' - Creates a Mesh Part

Dim oMeshPart As SimMeshPart


Set oMeshPart = oMeshParts.Add(MeshingType) 'Octree or Tetra
Meshing

Call GetPart.GetPart 'select part


oMeshPart.AddSupport GetPart.myLinkOnFeature
Set oSelectedPart = GetPart.oPart
'Define the Mesh Part
oMeshPart.SetAttributeValue "Mesh", "MeshSizeValue", MeshSize
oMeshPart.SetAttributeValue "Mesh", "ElementOrder", ElmOrd
oMeshPart.Update

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"

' - Retrieves the 3DPart Service


Dim My3DPartService As PLMNewService
Set My3DPartService = CATIA.GetSessionService("PLMNewService")
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.

30
White Paper

' - Create a 3DPart


Dim MyEditor3DShape As Editor
Set MyEditor3DShape = CATIA.ActiveEditor

'
'' - 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"

Set objSel = MyEditor3DShape.Selection


Set objSelLB = objSel
strMsg = "Select a part"
objSel.Clear
PlateStaticAnalysis.hide
strReturn = objSelLB.SelectElement2(varFilter, strMsg, False)
Set objSelLB = objSel
Set oPart = objSelLB.Item2(1).Value

' - Retrieves the active Object (it is the RepInst)


Dim myEditor As Part
Set myEditor = oPart 'MyEditor3DShape.ActiveObject

3DS.COM © Dassault Systèmes


' - Retrieves the VPMRepReference
Dim MyVPMRepRef As VPMRepReference
Set MyVPMRepRef = myEditor.Parent

' - Retrieves the PartBody


Dim MyPartBody As Body
Set MyPartBody = myEditor.MainBody

' - Retrieves the Reference of 3DPart


Dim MyRootRef As VPMReference
Set MyRootRef = MyVPMRepRef.Father

' - Retrieves the RepInstance


Dim myRepInstance As VPMRepInstance
Dim ListInstance As VPMRepInstances
Set ListInstance = MyRootRef.RepInstances
Set myRepInstance = ListInstance.Item(1)

' - Retrieves the Product Service


Dim MyProductService As PLMProductService
Set MyProductService = CATIA.GetSessionService("PLMProductService")

' - Retrieves the Root Occurrence


Dim MyVPMRootOcc As VPMRootOccurrence
Set MyVPMRootOcc = MyProductService.RootOccurrence

' - Compose link


Dim NoRef As VPMReference
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.

31
White Paper

Dim NoRepInst As PLMEntity


Dim NoOcc As VPMOccurrence

Set MyReference = myEditor.CreateReferenceFromObject(MyPartBody)


Set myLinkOnFeature = MyProductService.ComposeLink(NoOcc,
myRepInstance, MyReference)

End Sub

10.4. Scenario Creation


Declare oSimulationReference, oFeatures and oFeatureStates as public variables which
you can use while post-processing. Call CreateScenario sub by providing oPart and
oFEMRoot object which were stored in the memory during the support selection for FEM or
Mesh creation.

Public oSimulationReference As SimulationReference


Public oFeatures As SimFeatures
Public oFeatureStates As SimFeatureStates

Sub CreateScenario(ByVal oPart, ByVal oFEMRoot)


Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

3DS.COM © Dassault Systèmes


Dim myInitService As SimInitializationService
Set myInitService =
CATIA.GetSessionService("SimInitializationService")
myInitService.SetSimulationMethod
SimInitializationServiceStructuralMechanics
Dim oSimPLMService As SIMPLMService
Set oSimPLMService = CATIA.GetSessionService("SIMPLMService")

Dim oPLMProductService As PLMProductService


Set oPLMProductService = oEditor.GetService("PLMProductService")

Dim oEntities As PLMEntities


Set oEntities = oPLMProductService.EditedContent

Dim oModel As VPMReference


Set oModel = oEntities.Item(1)

Dim oSimulationReference As SimulationReference


oSimPLMService.PLMCreate "Static Analysis of Plate with Hole",
"SMAFeaPLMNewSimu", oModel, oSimulationReference, oEditor

' - Scenario Manager


Dim oScenarioManager As SimScenarioManager
Set oScenarioManager =
oSimulationReference.GetItem("SimScenarioManager")

' - Associating the Structural Analysis Case with the FEM rep
Dim oAnalysisCases As SimAnalysisCases

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.

32
White Paper

Set oAnalysisCases = oScenarioManager.AnalysisCases

Dim oAnalysisCase As SimAnalysisCase


Set oAnalysisCase = oAnalysisCases.Item(1)

oAnalysisCase.FEMRep = oFEMRoot

' - Creating and initializing the static step


Dim oSteps As SimSteps
Set oSteps = oAnalysisCase.Steps

Dim oStaticStep As SimStaticStep


Set oStaticStep = oSteps.Add("SimStaticStep")

oAnalysisCase.CreateDefaultElementTypeAssignment
oStaticStep.MaximumIncrements = 1000

' - Retrieving the features and features states sets


Dim oFeatures As SimFeatures
Set oFeatures = oAnalysisCase.Features

Dim oFeatureStates As SimFeatureStates


Set oFeatureStates = oStaticStep.FeatureStates
Dim oSimOutput As SimOutput

oStaticStep.CreateAnalysisDefaultOutputRequests

3DS.COM © Dassault Systèmes


End Sub

10.5. Sensor Creation


You can create sensors using the following script.

Sub CreateSensor()
Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor

Dim oSimulationReferenceNew As SimulationReference

Dim oProdService As PLMProductService


Set oProdService = oEditor.GetService("PLMProductService")

Dim oEntities As PLMEntities

If Not oProdService.EditedContent Is Nothing Then

Set oEntities = oProdService.EditedContent

Dim oEntity As PLMEntity


Dim oSimObjEntity As PLMEntity

For Each oEntity In oEntities


If oEntity.GetCustomType = "SIMObjSimulationObjectGenericDS" Then
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.

33
White Paper

Set oSimObjEntity = oEntity


End If
Next

Set oSimulationReferenceNew = oSimObjEntity

End If
Dim oSimResults As SimulationResults
Set oSimResults = oSimulationReferenceNew.Results

Dim oSimRepresentation As SimulationRepresentation


Set oSimRepresentation = oSimResults.Item(1)

Dim oSimRepManager As SimResultRepManager


Set oSimRepManager = oSimRepresentation.Root

Dim oResultsManager As SimResultsManager


Set oResultsManager = oSimRepManager.GetItem("SimResultsManager")

Dim oResultsAnalysisCases As SimResultsAnalysisCases


Set oResultsAnalysisCases = oResultsManager.ResultsAnalysisCases

Dim oResultsAnalysisCase As SimResultsAnalysisCase


Set oResultsAnalysisCase = oResultsAnalysisCases.Item(1)

Dim oSensor As SimSensor

3DS.COM © Dassault Systèmes


Set oSensor = oResultsAnalysisCase.CreateSensor
oSensor.VariableType = "S"
oSensor.ProcessingType = SimTensors
oSensor.Location = SimNodes
oSensor.Averaging = SimSectionBoundaries
oSensor.PrincipalDirection = True
Dim oFrameSelector As SimFramesSelection
Set oFrameSelector = oResultsAnalysisCase.CreateFrameSelector
oFrameSelector.SymbolicFrameRange = SimAllFrames
oSensor.FrameSelector = oFrameSelector

' - Set Parameters


oSensor.SetParameters True, True, True, True, True
oSensor.Update

End Sub

10.6. Knowledge base Articles on VB Automation


1. VBScript examples for automating the creation of modeling features in the
3DEXPERIENCE Structural Model Creation app (Article Id: QA00000048963)
2. VBScript examples for automating the creation of scenario features in the
3DEXPERIENCE Mechanical Scenario Creation app (Article Id: QA00000048964)
3. VBScript examples for automating post-processing tasks in the 3DEXPERIENCE
Physics Results Explorer app (Article Id: QA00000048965)
4. VBScript examples for automating tasks related to the materials in the
3DEXPERIENCE Platform (Article Id: QA00000048966)
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.

34
White Paper

About Author

Sagar POHEKAR is a Technical Support Engineer at Dassault


Systèmes since November 2015 working in Finite Element Analysis
and software customizations.

His main interests are finite element modelling, simulation and


software automation.

Sagar graduated from SVNIT, India University and received his


M.Tech in Computer Aided Design and Manufacturing in 2015.

3DS.COM © Dassault Systèmes

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.

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.

35

You might also like