Notifications
Clear all

[Closed] Position constraint-float script question

Hi, could someone help me please to sort this problem?
I have an object with position constraint and float script controller.
I would like to change the object name “$man01.” to something, what could
automatically recognize the root/parent object’s name. Is it possible?
see attchad image

I want to apply this script controller to more objects without retyping manually
its name in every script…

Thanks,
filip

4 Replies

In general, you shouldn’t be referencing objects with $ notation in a script controller. Better practice is to add the objects you want to use as node variables and access them that way. Then you can change the names of the objects as much as you want and the script doesn’t care because it knows the object’s id. (Not sure if this answers your question, though…)

Thanks mate;)
You helped me a lot!
cheers
filip

You can use,

(for x in refs.dependents(this) where isValidNode x collect x)[1].parent
  to replace $man01, although its not very efficient and might not work properly if the controller is instanced over several objects.
  
  I'd do what focomoso suggested and then, with the object selected, execute this code in the listener..

   $.pos.controller.position_script.controller.setNode "par" $.parent
   

Assuming you’ve named your variable “par”, it will automatically set the value of “par” to the node that is the parent of the selected object.

EDIT: Theres not supposed to be a tab in .setNode

Thanks Mathieson!
this “(for x in refs.dependents(this) where isValidNode x collect x)[1].parent” works exactly the way I wanted;)
cheers
filip