CATIA V6 Automation: Visual Studio Tools for Applications
|One of the main changes going from programming macros in CATIA V5 to CATIA V6 is that the data model replaces the document-centric model relying on files with a product/representation model relying on a database and client/server architecture. In V6, documents and files are replaced with product references and instances. There are new robust query and save operations as well as a unique entity-relation based data model that reduces storage size. Parts now support multiple representations enabled through isolation between the part reference and its shape.
V6 macros are saved and accessed from macro libraries stored in PLM server database. You can create a V6 macro for each V5 macro processed. V5 VBA should first be exported from V5. V6 macros cannot be saved in representations. Review, modify, and test code. Any objects whose types derives from Document in V5 should be replaced.
Supported Scripting Languages in CATIA V6
Scripting languages supported in V5 are still supported in V6, including:
- CATScript (typed variables)
- Visual Basic Scripting Edition – VBScript (variant variable)
- Visual Basic for Applications – VBA
- Supports both VB.net and C# languages
- New in V6 is VSTA – Visual Studio Tools for Applications
Visual Studio Tools for Applications (VSTA)
VSTA provides a development framework and a light version of the Visual Studio Integrated Development Environment (IDE). VSTA provides .NET data access capabilities, where VBA is limited to COM based data access. The VSTA runtime works in both 32-bit and 64-bit client and server environments. VSTA provides a more powerful customization toolset than VBA, CATScript, or VBScript. VSTA supports VB.net and C# languages
- Create a VSTA library
- Tools>Macro>Macros>Macro libraries
- Select PLM VSTA Projects from Library Type then Create new library…C# or VB.net
- V6 automation documentation: launch DSYAutomation.chm. This will show you the V6 object model.
I am making a VBA macro to insert a new 3D Part under a Product in CATIA V6, but my code doesn’t work. Can you help me?
My code
Sub Macro()
Dim ActiveEditor1 As Editor
Set ActiveEditor1 = CATIA.ActiveEditor
Dim oProductRootService As PLMProductService
Set oProductRootService = ActiveEditor1.GetService(“PLMProductService”)
Dim oVPMRootOccOnRoot As VPMRootOccurrence
Set oVPMRootOccOnRoot = oProductRootService.RootOccurrence
Dim oVPMRoot As VPMReference
Set oVPMRoot = oVPMRootOccOnRoot.ReferenceRootOccurrenceOf
Dim cListInstances As VPMInstances
Set cListInstances = oVPMRoot.Instances
Dim My3DPartService As PLMNewService
Set My3DPartService = CATIA.GetSessionService(“PLMNewService”)
Dim MyEditor3DShape As Editor
My3DPartService.PLMCreate “3DPart”, MyEditor3DShape
Dim MyEditor As Part
Set MyEditor = MyEditor3DShape.ActiveObject
Dim MyVPMRepRef As VPMRepReference
Set MyVPMRepRef = MyEditor.Parent
Dim MyRootRef As VPMReference
Set MyRootRef = MyVPMRepRef.Father
Dim oNewProdInst As VPMInstance
cListInstances.Add MyRootRef, oNewProdInst
End Sub
Hello, do you fix that?
If you are working on a cloud license then you need E70 license to do that. Add method is hidden in the object browser.
this method is good : cListInstances.Add MyRootRef, oNewProdInst
As workaround, what you can do after creating the 3DPart is to copy the head product by selection and paste it in your destination product.
Regards
Thanks so much for the info!
Hello everyone,
I’ve been spending days trying to figure out how to create a Product then place in a 3DShape inside this product created, I tried this code below:
Sub CATMain ()
‘—–create a product
dim oNewService As PLMNewService2
set oNewService = CATIA.GetSessionService(“PLMNewService2”)
Dim oEditor As Editor
oNewService.PLMCreate “VPMReference”,oEditor
‘——for the next line i want to add a 3DShape to this product I’ve created
oNewService.PLMCreate “3DShape”,oEditor ‘the 3dshape is created alone in a new window
End Sub
as you can see in the code above, I have problem adding a 3DShape to the product , for more details , in V5 I can do that using the code below :
Sub CATMain ()
dim documents1 As Documents
set documents1=CATIA.Documents
dim productdocument1 As ProductDocument
set productdocument1=documents1.Add(“Product”)
dim products1 As Products
set products1=productdocument1.Products
dim product2 as product
set product2=products1.AddNewComponent(“Part”,””)
End Sub
Any hint is really appreciated!
Regards