Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
* Changed `Element.set_attribute` args to use `user_attribute_id` as int and `user_attribute` as string.

### Removed

Expand Down
34 changes: 25 additions & 9 deletions src/compas_cadwork/datamodel/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,45 @@ def from_selection(cls) -> Generator[Element]:
"""
return (Element(e_id) for e_id in ec.get_active_identifiable_element_ids())

def set_attribute(self, name, value):
def set_attribute(self, attribute_number: int, name_or_value: str, value: Optional[str] = None):
"""Sets an attribute on the Element

Parameters
----------
name : str
The name of the attribute
value : str
attribute_number : int
The number of the attribute (1-10)
name_or_value : str
If ``value`` is provided, this is the name of the attribute.
Otherwise, this is the user attribute value.
value : str, optional
The value of the attribute

"""
ac.set_user_attribute([self.id], name, value)
if value is None:
user_attribute_value = name_or_value
else:
ac.set_user_attribute_name(attribute_number, name_or_value)
user_attribute_value = value

ac.set_user_attribute([self.id], attribute_number, user_attribute_value)

def remove_attribute(self, name):
# actully this only use the user_attribute number; no pass the elment id
# I am not sure how it defines which element to remove the attribute from
def remove_attribute(self, attribute_number: int, value: Optional[str] = None):
"""Removes an attribute from the Element

Parameters
----------
name : str
The name of the attribute
attribute_number : int
The number of the attribute (1-10)
value : str, optional
The attribute value to remove from the user attribute list.

"""
ac.delete_user_attribute([self.id], name)
if value is None:
ac.delete_user_attribute(attribute_number)
else:
ac.delete_item_from_user_attribute_list(attribute_number, value)

def set_is_instruction(self, value: bool, instruction_id: Optional[str] = None):
"""Sets the is_instruction attribute on the Element
Expand Down