Hello,
I have this following code that i try to modify. In fact I want to create a custom property named "AU_COMPO" = 2 in each components of my tree. The code works but the problem is that it adds as new string as the number of component : "AU_COMPO" , "AU_COMPO.1" , "AU_COMPO.2" "AU_COMPO.3" ....
I just want to check if the custom properties already exists, and if yes, to go to the next component witouht any creation. How can I do that ?
Here is the code :
I have this following code that i try to modify. In fact I want to create a custom property named "AU_COMPO" = 2 in each components of my tree. The code works but the problem is that it adds as new string as the number of component : "AU_COMPO" , "AU_COMPO.1" , "AU_COMPO.2" "AU_COMPO.3" ....
I just want to check if the custom properties already exists, and if yes, to go to the next component witouht any creation. How can I do that ?
Here is the code :
Code:
Sub CATMain()
GetNextNode CATIA.ActiveDocument.Product
End Sub
Sub GetNextNode(oCurrentProduct As Product)
Dim oCurrentTreeNode As Product
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)
Set oparameters = oCurrentTreeNode.ReferenceProduct.userrefproperties
[COLOR=#4E9A06]' Determine if the current node is a part, product or component[/color]
If IsPart(oCurrentTreeNode) = True Then
[COLOR=#4E9A06]'MsgBox oCurrentTreeNode.PartNumber & " is a part"[/color]
ElseIf IsProduct(oCurrentTreeNode) = True Then
[COLOR=#4E9A06]'MsgBox oCurrentTreeNode.PartNumber & " is a product"[/color]
Else
[COLOR=#4E9A06]'MsgBox oCurrentTreeNode.PartNumber & " is a component"[/color]
[COLOR=#4E9A06]'if oparameters.getitem("AU_COMPO")<> 0 then[/color]
oparameters.CreateString "AU_COMPO", "2"
[COLOR=#4E9A06]'End If[/color]
Thank you for your help
Edouard
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 IsPart(objCurrentProduct As Product) As Boolean
Dim oTestPart As PartDocument
Set oTestPart = Nothing
On Error Resume Next
Set oTestPart = CATIA.Documents.Item(objCurrentProduct.PartNumber & ".CATPart")
If Not oTestPart Is Nothing Then
IsPart = True
Else
IsPart = False
End If
End Function
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")
If Not oTestProduct Is Nothing Then
IsProduct = True
Else
IsProduct = False
End If
End Function