Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to removw y UserRefProperties ?

Status
Not open for further replies.

eperichon

Aerospace
Jan 16, 2013
7
CH
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 :

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
 
Replies continue below

Recommended for you

Hi

With the code bellow you can remove them all in selection. Is easy to modify this code to achieve what you want

Code:
 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 Sub

Regards
Fernando

 
Hello,

thank you for the answer. I have resolve my problem with that code input inside my loop :

Code:
           While oparameters.Count > 0
           oparameters.Remove (1)
           Wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top