[Closed] How to get the object from within a custom attributes rollout
Hi there. I’ve been trying to navigate the docs to work this out, but had no luck so far so I thought I’d ask here:
I want to add a scripted custom attribute to a rig control with a button that rotates the object. Right now I just can’t work out how to get the object that the custom attribute is attached to from within the button’s pressed handler. All the methods I can find in the docs require a variable that points to the attributes, so only seem appropriate at the point I add it to the object.
Any pointers would be greatly appreciated.
Custom attributes can be instanced so there is no direct reference to the node from the CA.
I have gotten around this in the past by storing a weak reference to the node in the CA.
You can use the NodeMonitor object to do this.
One of the properties in your parameter block should be like so:
Self Type:#MaxObject
Then you can set the property like so:
<NodeToReference>.<CustomAttribute>.Self = NodeMonitor Node:<NodeToReference>
Then to access the node from withing the CA:
Self.Node
The other approach would be to iterate over all nodes in the scene and test if they have the CA on them from within the CA. This is the more straightforward approach but will get slower as more nodes are added to the scene.
b = box()
_ca = attributes _ca attribid:#(12,34567)
(
parameters params
(
)
rollout params "CA"
(
)
)
custattributes.add b _ca
_owner = custattributes.getowner b.baseobject.custattributes[1]
_node = (refs.dependentnodes _owner)[1]