Create a new part with V6 macro vs V5 macro

To create a new part in CATIA V5 using VBA, you would use this code:

Dim oProduct As Object

Set oProduct = CATIA.Documents.Add(“Part”)

To create a 3Dpart in 3Dexperience, an E70 license is required. Here’s the VBA code for V6:

Dim oNewService As PLMNewService

Set oNewService = CATIA.GetSessionService(“PLMNewService”)

Dim oEditor3DShape As Editor

oNewService.PLMCreate “3DPart”, oEditor3DShape

Also, if you want to name the newly created part, here’s how you do it in V5:

Sub Create_Part(outName)

Dim temp

Set temp = CATIA.Documents.Add(“Part”)

temp.Product.PartNumber = outName

End Sub

To do the same thing in V6:

Sub Create_Part(outName)

Dim temp

Dim oNewService

Set oNewService = CATIA.GetSessionService(“PLMNewService”)

oNewService.PLMCreate “3DShape”, temp

Dim shapeRepRef As VPMRepReference

set shapeRepRef = temp.ActiveObject.Parent

shapeRepRef.Set AttributeValue “V_Name”, outName

End Sub

In V6 macro, you can also use the StartCommand:

Dim oProduct as Object

CATIA.StartCommand “3D Part”

On Error Resume Next

Set oProduct = CATIA.ActiveEditor.ActiveObject

That’s all there is to it!

Would you like to learn more about creating macros in 3Dexperience? Let us know in the comments below if we should write more articles!

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.