×
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

Macro to know the type of document in the complete catia tree

Macro to know the type of document in the complete catia tree

Macro to know the type of document in the complete catia tree

(OP)
Hello,

Here is an interesting code that give the type of all documents in a tree. You could know if it is a part, a product, or a component. It could be very useful in order to introduce some userrefproperties or other thing in different type of file. Some code are used from other codes find on the web.

CODE --> VBA

'********************************************************
'By e. perichon , some code borrowed from forums
'********************************************************


Sub CATMain()

    GetNextNode CATIA.ActiveDocument.Product
   
End Sub

 

Sub GetNextNode(oCurrentProduct As Product)

    Dim oCurrentTreeNode As Product
    Dim StrNomenclature, StrDesignation, StrWindows As String
    Dim i As Integer
          
    ' Loop through every tree node for the current product
    For i = 1 To oCurrentProduct.Products.Count
        
        Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
                
        ' Determine if the current node is a part, product or component
        
        If Right(StrWindows, 4) = "Part" Then
            'MsgBox oCurrentTreeNode.PartNumber & " is a part"
                
                                      
        ElseIf IsProduct(oCurrentTreeNode) = True Then
            'MsgBox oCurrentTreeNode.PartNumber & " is a product"
                        
        Else
           'MsgBox oCurrentTreeNode.PartNumber & " is a component"        
                   
        End If
        
        ' if sub-nodes exist below the current tree node, call the sub recursively
        If oCurrentTreeNode.Products.Count > 0 Then
            GetNextNode oCurrentTreeNode
        End If
              
        
   Next

End Sub

Function IsProduct(objCurrentProduct As Product) As Boolean

    Dim oTestProduct As ProductDocument
    
    Set oTestProduct = Nothing
    
    On Error Resume Next
      
        Set oTestProduct = CATIA.Documents.Item(objCurrentProduct.PartNumber & ".CATProduct")
        'Set oTestProduct = CATIA.Documents.Item(objCurrentProduct.ReferenceProduct.Parent.Name & ".CATProduct")
        
        If Not oTestProduct Is Nothing Then
            IsProduct = True
        Else
            IsProduct = False
        End If
         
End Function 

RE: Macro to know the type of document in the complete catia tree

(OP)

Sorry i have forgotten the red line that are importants...

CODE --> vba

'********************************************************
'By e. perichon , some code borrowed from forums
'********************************************************


Sub CATMain()

    GetNextNode CATIA.ActiveDocument.Product
   
End Sub

 

Sub GetNextNode(oCurrentProduct As Product)

    Dim oCurrentTreeNode As Product
    Dim StrNomenclature, StrDesignation, StrWindows As String
    Dim i As Integer

    StrWindows = oCurrentTreeNode.ReferenceProduct.Parent.FullName
    On Error Resume Next
       
    ' Loop through every tree node for the current product
    For i = 1 To oCurrentProduct.Products.Count
        
        Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
                
        ' Determine if the current node is a part, product or component
        
        If Right(StrWindows, 4) = "Part" Then
            'MsgBox oCurrentTreeNode.PartNumber & " is a part"
                
                                      
        ElseIf IsProduct(oCurrentTreeNode) = True Then
            'MsgBox oCurrentTreeNode.PartNumber & " is a product"
                        
        Else
           'MsgBox oCurrentTreeNode.PartNumber & " is a component"        
                   
        End If
        
        ' if sub-nodes exist below the current tree node, call the sub recursively
        If oCurrentTreeNode.Products.Count > 0 Then
            GetNextNode oCurrentTreeNode
        End If
              
        
   Next

End Sub

Function IsProduct(objCurrentProduct As Product) As Boolean

    Dim oTestProduct As ProductDocument
    
    Set oTestProduct = Nothing
    
    On Error Resume Next
      
        Set oTestProduct = CATIA.Documents.Item(objCurrentProduct.PartNumber & ".CATProduct")
        'Set oTestProduct = CATIA.Documents.Item(objCurrentProduct.ReferenceProduct.Parent.Name & ".CATProduct")
        
        If Not oTestProduct Is Nothing Then
            IsProduct = True
        Else
            IsProduct = False
        End If
         
End Function 

RE: Macro to know the type of document in the complete catia tree

Hi eperichon,

What if I want to compile the output (list) to an existing file in my folder and expand the output (list) as the code runs through the entire tree? Where can I insert a chunk of code for this purpose?

By the way, this has helped me a lot...didn't know I can call out a sub () within itself.

RE: Macro to know the type of document in the complete catia tree

Thanks for the code. I am looking to do something similar where I need to get the number of unique parts for each sub-assembly. Any ideas?

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