How to call the specific product required from the products list in the tree in CATIA using VB.net

Raja Rimmalapudi

How to call the specific product required from the products list in the tree in CATIA using VB.net

How to call the specific product required from the products list in the tree in CATIA using VB.net?

I have multiple number of products existing inside one another in my 3D experience part design tree structure. I want to work on one specific product among them. How can I call a specific product from the tree using VB.net.  

Attachments

  • Tree structure.PNG (198.1k)
Edited By:
Raja Rimmalapudi[Linkoping University] @ Apr 07, 2021 - 07:49 PM (Europe/Stockholm)

Patrick Voosen

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Raja Rimmalapudi)

Hi Raja,

 

When you say you want to call a specific product, what exactly do you mean? Are you hoping to select a product in the tree and perform some operations in it, or search through the product structure and find a product based on some attribute, or loop over all products in the tree? In any case I think there are some helpful examples in the documentation. "Modifying PLM Attributes of a Selected Product Object" and "Generating Bill of Materials (BOM)" are good starting points for navigating the product structure. If you can provide more info on exactly what you are trying to accomplish, it would be easier to provide a more detailed response.

Raja Rimmalapudi

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Thank you Patrick. Here I have to call a specific product from the tree to perform instantiation on the product using for loop. Basically, the inputs for instantiation will be copied from another product in the same tree and will be pasted in the new product. As this will be in loop, multiple number of parts will be created under the new product. So, for doing this firstly, I want to call the product from which I have to copy the inputs. And then create a new product under the main parent product. 

Patrick Voosen

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Raja Rimmalapudi)

Since it sounds like you are looping over the product I think the bill of materials example will be more relevant. The example also navigates through the tree recursively to get to the leaf level nodes, so if you are only interested in first level children you could simplify the code. Here is an excerpt from the most useful section of the code:

Generating Bill Of Materials (BOM) source
Sub NavigateProductStructure(oProductEditor)
    'Error handling
    On Error GoTo ErrorSub
    
    'Initializes the global variable
    strBrowsedPLMCompIDAttr = ""
    iNewObjectIndex = 0
 
    'Retrieves the Product Service from the editor
    Dim oProductService As PLMProductService
    Set oProductService = oProductEditor.GetService("PLMProductService")
        
    'Retrieves the Root Product Occurrence from the current VPM Editor to navigate
    Dim oVPMRootOccOnRoot As VPMRootOccurrence
    Set oVPMRootOccOnRoot = oProductService.RootOccurrence
    
    'Retrieves the Root Reference from the occurrence model
    Dim oVPMRefOnRoot As VPMReference
    Set oVPMRefOnRoot = oVPMRootOccOnRoot.ReferenceRootOccurrenceOf
    
    'Displays the Root Product Reference name
    strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRefOnRoot.Name + vbCrLf
        
    'Navigates the Product Reference
    '(Call for Navigate on the retrieved Reference)
    NavigateProdReference oVPMRefOnRoot, 1
    
    'Displays the Occurrence Product Model Contents in the Message Box
    MsgBox strBrowsedPLMCompIDAttr
        
    'Clears the display contents
    strBrowsedPLMCompIDAttr = ""
            
   'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Sub
'
'--------------------------------------------------------------------------
'Navigates the Product Reference
'    Input : the Product Reference
'            depth of the object in hierarchy
'--------------------------------------------------------------------------
Sub NavigateProdReference(oProdRef, depth)
    'Error handling
    On Error GoTo ErrorSub
    
   'Retrieves the list of instances within the input reference
    Dim oListChildrenInstances As VPMInstances
    Set oListChildrenInstances = oProdRef.Instances
    
    'Navigates through each child Reference recursively
    'Loop through the List of child instances
    For i = 1 To oListChildrenInstances.Count
    
        'Retrieves the Child instance from the list
        Dim oVPMInst As VPMInstance
        Set oVPMInst = oListChildrenInstances.Item(i)
        
        'Indent the PLM entity appropriately
        For spaceCnt = 1 To depth
            strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + vbTab
        Next spaceCnt
        
         'Retrieves the Reference of the instance
        Dim oVPMRef As VPMReference
        Set oVPMRef = oVPMInst.ReferenceInstanceOf
         
        '---------------------------------------------------------------
        '2.1- Retrieves the Leaf nodes
        '---------------------------------------------------------------
        'Retrieve count of Children Instances
        Dim oListChildrenInstToIdentifyLeafNode As VPMInstances
        Set oListChildrenInstToIdentifyLeafNode = oVPMRef.Instances
        
        Dim StrNewObjRef As String
        StrNewObjRef = ""
        
        'Zero count of Children Instances shows that its leaf node
        If 0 = oListChildrenInstToIdentifyLeafNode.Count Then
        '-----------------------------------------------------------------
        '2.2- Count and display leaf node occurrences
        '-----------------------------------------------------------------
            'Update its status for new or already exist node Reference in list
            StrNewObjRef = GetLeafNodeStatusAndAddCount(oVPMRef)
        End If
        
        'Prepare the string for displaying purpose
        strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRef.GetAttributeValue("PLM_ExternalID") + oVPMRef.GetAttributeValue("revision") + " " + "("
        strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMInst.GetAttributeValue("PLM_ExternalID") + ")" + StrNewObjRef + vbCrLf
              
        'Navigate further into this VPM Ref. A recursive call to Navigate follows
        NavigateProdReference oVPMRef, depth + 1
            
    'Next ref
    Next i
    
    'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Sub

Raja Rimmalapudi

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Thank you for help. By the way I have another question. 

Do we need VMX license for creating a new product or part in 3D experience using VB.net?

Patrick Voosen

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Raja Rimmalapudi)

I do know you need an additional license to create products and parts, but I couldn't tell you which one.

Raja Rimmalapudi

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Hello Patrick. Thanks for your help previously. As I cannot create a product without E70 license, I want to create a new  3DShape Instead. I also have the code for creating 3DShape. But, this 3DShape has to be created inside the existing product. Can you help me with the code for doing this?

Patrick Voosen

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Raja Rimmalapudi)

I am not sure if that is possible. I found an older post on 3dswym with the same question. You may need to create the 3dshape and then copy and paste it into your product.

Have you considered using EKL instead of VB?

Patrick Voosen

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Hi Raja, 

I came across an answer on stack exchange and it seems like it may be useful for you.

https://stackoverflow.com/questions/64439571/insert-part-to-assembly-in-3dexperience-macro 

Raja Rimmalapudi

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Thank you

Darius James McAdam

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Patrick,

Haha, this is a reply to an old post and is a bit off-topic. However, you mentioned that there was documentation for "Modifying PLM Attributes of a Selected Product Object." How do I find that documentation? I tried searching the COE forums and a google search with that as the criteria. I'm trying to change physical product titles and Enterprise Item Numbers with a macro, and I'm banging my head against the wall. Thanks in advance for any help in finding that documentation!

Patrick Voosen

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Darius James McAdam)

In your install directory the path to the documentation is: \win_b64\code\bin\DSYAutomation.chm

It should be easy to change the title, but I haven't tried modifying the EIN yet.

Darius James McAdam

RE: How to call the specific product required from the products list in the tree in CATIA using VB.net
(in response to Patrick Voosen)

Thanks, Patrick!