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.
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
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 FunctionRE: Macro to know the type of document in the complete catia tree
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
RE: Macro to know the type of document in the complete catia tree
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...