Knowing if an object has Custom Attributes

Knowing if an object has Custom Attributes

Anonymous
Not applicable
647 Views
5 Replies
Message 1 of 6

Knowing if an object has Custom Attributes

Anonymous
Not applicable
Hi,
I've been having this problem at my job where I need to go through a scene's objects and check if they have a custom attribute on them. Whenever you try to access one of the C.A properties of an object that has no C.A applied , it returns an error.

Thus the solution for now is to do a try()catch(). But on a large group of objects , the UI (dotnet) becomes slow because of that check. When I did put that checkup part under comments,
the process was much faster.

So the question is: Is there a way to ask to an object if it has been assigned with a specified custom attribute. Returning a true / false , an empty list or whatever! As long as it's not an error!

Thanks in advance!
0 Likes
648 Views
5 Replies
Replies (5)
Message 2 of 6

Steve_Curley
Mentor
Mentor
custAttributes.count <obj> maybe?

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 6

Anonymous
Not applicable
Also can test for concrete property using isProperty() function
for obj in objects where isProperty obj #roundness do ...
0 Likes
Message 4 of 6

Anonymous
Not applicable
I believe isProperty is just a wrapper for try/catch, it takes the same amount of time to execute as try/catch if the result is false.
0 Likes
Message 5 of 6

Anonymous
Not applicable
yep, i not tested it runtime before and i see some sense in this conclusion.

custAttributes.count looks enough if the scene has only one attribute, else - need to test their names. maybe this snippet looks more promising:
for obj in objects where custAttributes.count obj > 0 do (
objCAsNames = for ca in (custAttributes.getDefs obj) collect ca.name
if findItem objCAsNames #CA_Name_Here > 0 do (
-- ...
)
)
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks alot guys, looks like i haven't been enough through the help files or haven't it done properly. This last solution works perfectly well, very apreciated!

See ya!
0 Likes