Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA V6 Macro - Insert new 3DPart under Product

Status
Not open for further replies.

Phuc Phan Tu

Structural
Feb 1, 2017
3
VN
Hi

I want to write a macro using VB.NET or VBA to insert a new 3DPart or 3DShape under a product. I read V6 Automation Help document but i don't see it. I also used record but CATIA can't record that action. I followed this example to write my code Instantiating Product Representation Reference but it doesn't work. Here is my code:

Code:
Public Sub Macro_Chenbulong()
        Dim ActiveEditor As Editor
        ActiveEditor = CATIA.ActiveEditor
        Dim oProductService As PLMProductService
        oProductService = ActiveEditor.GetService("PLMProductService")
        Dim oVPMRootOccOnRoot As VPMRootOccurrence
        oVPMRootOccOnRoot = oProductService.RootOccurrence
        Dim oVPMRefOnRoot As VPMReference
        oVPMRefOnRoot = oVPMRootOccOnRoot.ReferenceRootOccurrenceOf
        CATIA.GetSessionService("PLMPropagateService").Save()

        Dim My3DPartService As PLMNewService
        My3DPartService = CATIA.GetSessionService("PLMNewService")
        Dim MyEditor3DShape As Editor
        My3DPartService.PLMCreate("3DPart", MyEditor3DShape)

        Dim MyEditor As Part
        MyEditor = MyEditor3DShape.ActiveObject
        Dim MyVPMRepRef As VPMRepReference
        MyVPMRepRef = MyEditor.Parent
        Dim MyRootRef As VPMReference
        MyRootRef = MyVPMRepRef.Father


        Dim cListInstances As VPMInstances
        cListInstances = oVPMRefOnRoot.Instances
      
        Dim oNewProdInst As VPMInstance
        cListInstances.Add(MyRootRef, oNewProdInst)
    End Sub

When i debug, cListInstances error: nothing

What can I do to fix that?
Thanks

 
Replies continue below

Recommended for you

Hello,

I might be wrong but what the hell: are you trying to add a VPMRepInstance (the instance of 3DPart) of a VPMRepReference (the actual 3DPart) in a collection of VPMInstances? Isn't that wrong? I imagine you should call the VPMRepInstances collection instead of VPMInstances.

Hope it helps,
Calin
 
I am not sure. This is example in document
Sub Add( VPMReference iProductReference,
VPMInstance oProductInstance)

Creates a new child PLM Product Instance.

This example shows you how to instantiate a PLM Product Reference (oProdRefToBeInstantiated), to insert the new instance below another given PLM Product Reference (oProdRefAsParent)
Code:
Dim  oProdRefAsParent  As VPMReference
   Dim  oProdRefToBeInstantiated  As VPMReference
   .....
   Dim  cListInstances As VPMInstances
   Set  cListInstances = oProdRefAsParent.Instances
   
   Dim oNewProdInst As VPMInstance
   cListInstances.Add oProdRefToBeInstantiated,oNewProdInst
 
i Think problem is when I created a new 3D Part, active window changed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top