[Closed] Custom Attributes – hasProperty?
I’m working on a couple of scripts at the moment using Custom Attributes to put extra UI rollouts on lights and cameras.
I keep managing to add multiple rollouts to each object however when I’m re-running the script testing it. I can’t use a hasProperty query to find out if it already has the CA, how can I test to see if I need to add it or not?
Best Regards
Dave
[left]custAttributes.get <obj> (<index> | <attrib_def>) [BaseObject:<bool>]
[/left]
[left]Returns the custom attribute set, specified as an index or by its defining attribute definition.
[/left]
[left]BaseObject:<bool>
[/left]
[left]If the optional keyword argument baseObject is set to true (the default), in case the object specified is a node, the base object will be operated on. If false, the node itself will be operated on. (In versions prior 3ds Max 5.1, the base object was always used.)
[/left]
for o in lights where classof o != TargetObject and (custAttributes.get o def_test) == undefined do custAttributes.add o def_test
I still get additional rollouts… I’m sure I’m missing something obvious here…
Hmm ok it’s because I’m redefining the def_test attribute on each run of the script…
def_test = attributes testCA
(
parameters main rollout:RL_test
(
testVal type:#boolean ui:chk_test
)
rollout RL_test "test"
(
checkbox chk_test "testVal"
)
)
for o in lights where classof o != TargetObject and (custAttributes.get o def_test) == undefined do custAttributes.add o def_test
you have to make your attribute ‘global’ by giving it unique attribID
OR
search an attribute instance by name instead of by definition. because as you said above you redefine your attribute every time.
the easiest way to do it:
(node.baseobject.custattributes[attrName]) != undefined
-- or
(node.custattributes[attrName]) != undefined