×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA V6 Macro - Insert new 3DPart under Product

CATIA V6 Macro - Insert new 3DPart under Product

CATIA V6 Macro - Insert new 3DPart under Product

(OP)
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 --> VB.NET

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

RE: CATIA V6 Macro - Insert new 3DPart under Product

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

RE: CATIA V6 Macro - Insert new 3DPart under Product

(OP)
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 --> VB.NET

Dim  oProdRefAsParent  As VPMReference
   Dim  oProdRefToBeInstantiated  As VPMReference
   .....
   Dim  cListInstances As VPMInstances
   Set  cListInstances = oProdRefAsParent.Instances
   
   Dim oNewProdInst As VPMInstance
   cListInstances.Add oProdRefToBeInstantiated,oNewProdInst 

RE: CATIA V6 Macro - Insert new 3DPart under Product

(OP)
i Think problem is when I created a new 3D Part, active window changed

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources