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:
[COLOR=#4E9A06]'********************************************************
'By e. perichon , some code borrowed from forums
'********************************************************[/color]
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
[COLOR=#4E9A06]' Loop through every tree node for the current product[/color]
For i = 1 To oCurrentProduct.Products.Count
Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
[COLOR=#4E9A06]' Determine if the current node is a part, product or component[/color]
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
[COLOR=#4E9A06]' if sub-nodes exist below the current tree node, call the sub recursively[/color]
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")
[COLOR=#4E9A06]'Set oTestProduct = CATIA.Documents.Item(objCurrentProduct.ReferenceProduct.Parent.Name & ".CATProduct")[/color]
If Not oTestProduct Is Nothing Then
IsProduct = True
Else
IsProduct = False
End If
End Function