×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to removw y UserRefProperties ?

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 :

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 ?

Hi

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 Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: How to removw y UserRefProperties ?

(OP)
Hello,

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources