How to add custom properties at the body level in SCDM?

Gabriel Messager
Gabriel Messager Member, Employee Posts: 56
Second Anniversary 10 Comments 5 Likes Name Dropper
✭✭✭✭
edited June 2023 in 3D Design

How to add custom properties at the body level in SCDM?

Example:

Tagged:

Answers

  • Gabriel Messager
    Gabriel Messager Member, Employee Posts: 56
    Second Anniversary 10 Comments 5 Likes Name Dropper
    ✭✭✭✭
    Answer ✓
    # Python Script, API Version = V21
    from SpaceClaim.Api.V21 import CustomProperty, SimplePropertyDisplay, Application
    
    class CustomPropertyDisplay(SimplePropertyDisplay):
        """This is a property diplay class used to populate the properties window.
           To use it, you must first register it with the Application:
           Application.AddPropertyDisplay(...).
           Once registerd the GetValue method is called on each selection change, and it should
           return the string to be displayed."""
        
        def __init__(self, category, name):
            SimplePropertyDisplay.__init__(category,name)
        
        def GetValue(self, body):
            # Make sure the selection is a body
            if not isinstance(body, IDesignBody):
                return None
                
            # Try to get the "MyCustomProp" attribute from the body
            (success, value) = body.GetMaster().TryGetTextAttribute("MyCustomProp")
            return value
        
        def SetValue(self, body, value):
            # Make sure the selection is a body
            if not isinstance(body, IDesignBody):
                return None
            
            # Update the attribute
            body.GetMaster().SetTextAttribute("MyCustomProp", value)
            
    # All DocObjects allow you set Text and Number attributes.  
    # We will use these attributes to store our custom property
    for body in GetRootPart().GetAllBodies():
        body.GetMaster().SetTextAttribute("MyCustomProp", "This is my description")
    
    Application.AddPropertyDisplay(CustomPropertyDisplay("My_custom_properties", "my_title"))