Conversation
|
@Brunner246 ? could you have a look?thx |
|
|
||
| """ | ||
| ac.set_user_attribute([self.id], name, value) | ||
| ac.set_user_attribute_name(number=attribute_number, user_attribute_name=name) |
There was a problem hiding this comment.
whenever I try calling cwapi3d functions using kwargs I get a TypeError, sure this works?
| 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): |
There was a problem hiding this comment.
The user attributes system seems to be working like:
set_user_attribute_name - adds a new attribute name to some general attributes database and assigns it an attribute number. this has to happen once and not per element. multipe calls with different names but same number overwrite the name of the same attribute.
Now this attribute can be set on elements:
set_user_attribute sets a user attribute using its number and a value onto an element
Now the tricky part that's a bit confusing to me:
To remove an attribute, we have to remove its value - which uniquely identifies it in the user attributes item list (get_user_attribute_list_items).
This is done using delete_item_from_user_attribute_list. If the same value is set on multiple elements, all of them will get cleared..
delete_user_attribute deletes the attribute from the global attribute list and will only be successful if no elements are using this attribue. meaning, all the values set to this attribute have to first be cleared using delete_item_from_user_attribute_list.
in other words, delete_user_attribute won't do anything here if the user attribute is currently set on any elemetns.
confusing.
There was a problem hiding this comment.
Example code:
# adds attribute with number 11 and name 'AttrName` to the global user attributes database
>>> ac.set_user_attribute_name(11, "AttrName")
# only here it's actually set on elements
>>> ac.set_user_attribute([4625], 11, "AttrValue4625")
>>> ac.set_user_attribute([4624], 11, "AttrValue4624")
>>> ac.get_user_attribute_list_items(11)
['', 'AttrValue4624', 'AttrValue4625']
# returns `False` and does nothing because attribute number 11 is in use
>>> ac.delete_user_attribute(11)
False
# attributes first need to be removed from the elements using their.. value..
>>> ac.delete_item_from_user_attribute_list(11, 'AttrValue4625')
True
>>> ac.delete_item_from_user_attribute_list(11, 'AttrValue4624')
True
# Only now, attribute number 11 can be removed from the database
>>> ac.delete_user_attribute(11)
True
|
@chenkasirer Thanks.You’re right—kwargs to cwapi3d throw TypeError, so I switched set_attribute to positional args. I also updatet remove_attribute to optionally remove by value using delete_item_from_user_attribute_list |
What type of change is this?
It was the issue with
set_attributetake wrong type of argument. The function in cadwork api:it should take number: int(user attribute id) and
user_attributeisstringChecklist
CHANGELOG.mdfile in theUnreleasedsection under the most fitting heading (e.g.Added,Changed,Removed).