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

Member, Employee Posts: 59
5 Answers Second Anniversary 10 Comments 5 Likes
✭✭✭✭
edited June 2023 in 3D Design

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

Example:

Tagged:

Answers

  • Member, Employee Posts: 59
    5 Answers Second Anniversary 10 Comments 5 Likes
    ✭✭✭✭
    Answer ✓
    1. # Python Script, API Version = V21
    2. from SpaceClaim.Api.V21 import CustomProperty, SimplePropertyDisplay, Application
    3.  
    4. class CustomPropertyDisplay(SimplePropertyDisplay):
    5. """This is a property diplay class used to populate the properties window.
    6. To use it, you must first register it with the Application:
    7. Application.AddPropertyDisplay(...).
    8. Once registerd the GetValue method is called on each selection change, and it should
    9. return the string to be displayed."""
    10. def __init__(self, category, name):
    11. SimplePropertyDisplay.__init__(category,name)
    12. def GetValue(self, body):
    13. # Make sure the selection is a body
    14. if not isinstance(body, IDesignBody):
    15. return None
    16. # Try to get the "MyCustomProp" attribute from the body
    17. (success, value) = body.GetMaster().TryGetTextAttribute("MyCustomProp")
    18. return value
    19. def SetValue(self, body, value):
    20. # Make sure the selection is a body
    21. if not isinstance(body, IDesignBody):
    22. return None
    23. # Update the attribute
    24. body.GetMaster().SetTextAttribute("MyCustomProp", value)
    25. # All DocObjects allow you set Text and Number attributes.
    26. # We will use these attributes to store our custom property
    27. for body in GetRootPart().GetAllBodies():
    28. body.GetMaster().SetTextAttribute("MyCustomProp", "This is my description")
    29.  
    30. Application.AddPropertyDisplay(CustomPropertyDisplay("My_custom_properties", "my_title"))

Welcome!

It looks like you're new here. Sign in or register to get started.