How to removw y UserRefProperties ?
How to removw y UserRefProperties ?
(OP)
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 --> VBA
Sub CATMain()
GetNextNode CATIA.ActiveDocument.Product
End Sub
Sub GetNextNode(oCurrentProduct As Product)
Dim oCurrentTreeNode As Product
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)
Set oparameters = oCurrentTreeNode.ReferenceProduct.userrefproperties
' Determine if the current node is a part, product or component
If IsPart(oCurrentTreeNode) = True 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"
'if oparameters.getitem("AU_COMPO")<> 0 then
oparameters.CreateString "AU_COMPO", "2"
'End If
Thank you for your help
Edouard
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 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 




RE: How to removw y UserRefProperties ?
With the code bellow you can remove them all in selection. Is easy to modify this code to achieve what you want
CODE --> CATScript
Sub CATMain() Dim oSel Dim InputObjectType(0) Dim Status Set odoc = CATIA.ActiveDocument Set oSel = odoc.Selection InputObjectType(0) = "Product" oSel.Clear Status = oSel.SelectElement2(InputObjectType, "Select the product", False) If (Status = "Cancel") Then Set oSelectedProduct = Nothing Else Set oSelectedProduct = oSel.Item(1).Value End If Dim oParams As Parameters Set oParams = oSelectedProduct.ReferenceProduct.UserRefProperties For i = 1 To (oParams.Count) oParams.Remove (oParams.Count) Next End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: How to removw y UserRefProperties ?
thank you for the answer. I have resolve my problem with that code input inside my loop :
CODE --> vba
While oparameters.Count > 0 oparameters.Remove (1) Wend