vbacatia

How to know which CATIA component is in the current edit mode


I want to know programmatically which component of a Product in CATIA v5 is in editing mode now. Example:

Example tree

Here I want to take that "Pruebaocultar2" is the active component (not the selected). It could be a Part or a Product.

I tried with CATIA.ActiveDocument.Name, but I always get the root...


Solution

  • To get the active node you can use a workaround: search for product in the active UI node.

    Sub CATMain()
    
    Dim oProductdocument As Document
    Dim oSel as Selection
    Dim oActiveProduct as Product
    Dim oDoc as Document
    
    Set oProductdocument = CATIA.ActiveDocument
    Set oSel = oProductdocument.Selection
    
    if TypeName(oProductdocument) = "ProductDocument" then
        'Search for products in active node
        oSel.Search "CATAsmSearch.Product,in"
    
        if oSel.Count2 <> 0 then
            'first selected product is the active node
            Set oActiveProduct = oSel.Item2(1).LeafProduct
            Set oDoc = oActiveProduct.ReferenceProduct.Parent
            MsgBox "Active Instance: " & oActiveProduct.Name & Chr(13) & "Type: " & TypeName(oDoc) & Chr(13) & "FileName: " & oDoc.Fullname, 0, "Active node"
        end if
    end if
    
    oSel.Clear
    
    End Sub
    

    This workaround fails if other Workbenches as Assembly Design or Product Structure are active.

    Remark: Code is in CATScript/VBA and not catvbs/vbscript