[Closed] Script Controller Name Dependancy
Hi
I have 120 instances of an object and I need to make then rotate depanding on a number in their name.I need to get the object that hold that script controller to capture its name but i dont want to do 120 diff script controller because it will be amazingly heavy.
Is their any way to find the node of the assign controller without refering to it manually ?
Thank you
The Dark_MOB
maybe you can use the ‘this’ variable.
copy/paste from max8 help:
[color=white]‘This’ Local Variable in Scripted Controllers[/color]
[left]The this local variable in scripted controllers will contain a MAXWrapper value wrapping the scripted controller. The this is a local variable that exists while evaluating the scripted controller’s script, and is not a property of the scripted controller.
[/left]
[left]In order to access the actual object the controller is assigned to, you can use the refs.dependents method using the this variable, then filter the valid nodes.
[/left]
[left]For example:
[/left]
[left]refsArray = (refs.dependents this)
[/left]
[left][color=blue]for[/color] i [color=blue]in[/color] refsArray [color=blue]where[/color] isvalidnode i [color=blue]do[/color] print i.name
[/left]
[left]0.0
[/left]
[left]The example returns the name of the object the scripted controller is assigned to. Obviously it is not possible to tell the actual node when the controller is instanced across multiple objects which is a known limitation.
[/left]
/Lui
Thanks a lot
at least i wont have to make any changes on each controller.
Thank
Dark MOB
refs.dependants will return an array of all objects that reference the controller. If you instance the script controller to all the 120 objects then it will return all of them in the array and as far as I know there is no way to know which one it is directly on. Also at any given frame if the script controller is instanced it will control all objects that have that instance of the script controller.
I can’t see how you would get around having unique script controllers on every object. If I were you I would just write a script that adds the script controller to the objects as needed.
Am I way off base here?
Thanks for your toughts Paul…
Thats exactly what I did.
The only thing I didnt wanted to do was to make any changes manually to each controller because thats not the only controller needed in that scene.
Thanks
Dark_MOB
Hi Dark_MOB
That solution works fine if the objects are stationary in space. If their rotation must be animated you could write very simple script to control the rotation of each of the objects.
I would do it this way:
- Create the object that will hold the script, probably a dummy, or such.
- Create a visibility track and assign a float_script to it. This way, the script gets evaluated before setting up the scene in rendering time, therefore producing the correct results.
- In the script, i would create an Array of all the objects you need. If their names are similar only different in number, you could write a one line script to create such an array.
- Then do a for n in array type of script. In this way you can use string operations to access the .name and filter the number of the objects, etc.
- Set the .rotation or the .transform of the objects in the loop.
- Last line should be a 0.0 to return that value to the visibility track.
In that way the script is not only run at creation time, but every frame and before meshes are exported to render. In this way, the objects could be animated.
Again, if they are not moving, all this would be a waiste of computer efforts and man time as well.
Hope this helps,
Rafael Polit Jr.
Quito, Ecuador.