Notifications
Clear all

[Closed] get object's name

hi, all … i’m new here.

my question is, how can i access the name of the object, if i write a script controller for it.

e.g. i have a sphere and i make copies/instances of that sphere and assign a script controller to the scale of that sphere, so that each copy get’s bigger by a certain ammount. this should be done by using that 3dmax “counts” for me sphere01, next sphere02, … i’d use “substring” to just cut out 01, 02, … and use “as float” so that i cna use those values.

so, this was just an example for my question

i’ve tried things like $.name, but this would only work, when i’ve an object (sphere) selected

thanks an best regards thomas aka taemon

i hope that my question is clear, though english is not my mother tongue

3 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Servus Thomas,

In versions before Max 8, you would use what is known as an “object path” – dollar sign followed by the name of the object. In a scripted controller, this would mean that changing the name of the scene object would break the script.

For example, you could say

$Sphere01.radius = $Sphere02.radius = $Sphere03.radius = [1,1,1] * $Box01.height

Since 3ds Max 8 though, this approach has become obsolete – it is still supported, but you are encouraged to use the new approach which ensures that scripted controllers would not “break” anymore if you renamed the object. It also allows for using scripted controllers inside of XRef files woutout breaking the animation.
The new method requires you to create variables (like in the old Expression controllers) and assign objects, tracks, controllers or constants to them. These variables are stored in a parameter block just like in regular plugins, thus the scripted controller has direct access to the referenced object via a real POINTER and does not have to resolve the path to the object. In addition, the new scripted controllers update automatically when a parameter changes via the internal dependency system, so the old DependsOn method is not needed anymore.

In 3ds Max 9, take a look at the “Script Controllers” topic in the MAXScript Reference.
Especially look at the AddNode and AddObject methods which allows you to create a new variable with a given name and assign an scene object to it. Then you can reference that object by the name of the variable:

s = sphere()
 b = box pos:[100,0,0]
 ctrl = float_script()
 b.height.controller = ctrl
 ctrl.AddObject "theSphere" s
 ctrl.script = "theSphere.radius"

The difference between AddNode and AddObject is that a Node variable will force an update of the controller only when the node transforms (position,rotation,scale) are changing. In contrast, AddObject causes the script to update whenever the object is changing at ANY level (both node and object properties). So in the above case, changing the Radius of the sphere automatically changes the height of the box, but the controller will be updated more often.

If the script was using node transforms though, like

 s = sphere()
  b = box pos:[100,0,0]
  ctrl = float_script()
  b.height.controller = ctrl
  ctrl.AddNode "theSphere" s
  ctrl.script = "theSphere.pos.x"

then the height of the box will only be refreshed when you move/rotate/scale the sphere, but never when you change the radius, so when creating complex rigs, it would be a lot faster.

You can write a script that creates the scripted controllers, creates as many variables as you need in each controller and assign the reference to the actual scene nodes to the variables. Thus, you don’t need any names…

Gruesse nach Linz,
Bobo

Hi, I’m trying to understand your question.

When you grab the sphere to assign the controller to it, how are you accessing the sphere? You should be able to get the name string easily from the internal object name.

s = sphere() 
objNameString = s.name

and then you can use subString to get the number from objNameString.

If you’re creating the spheres and then assigning the controllers later, you can put the spheres in an array as you make them, and then go through the array and get the sphere names.

sphereArray = #() 
for i - 1 to 10 do -- or whatever you are using for a loop
(
  s = sphere()
  append sphereArray s
)

and then later…

for obj in sphereArray do 
(
  objNameString = obj.name
  {use subString to grab the number, do the calculation, change controller, etc.}
)

Is this what you had in mind?

  • Michele

hi bobo, mbousquet,

as it seems i was quite unclear in my explaination, but advancing in the topic your replys helped me to get along. the idea that i had just would not work the way i thought.

i opend up a new thread which fits better to what i want achieve.

thanks and best regards
thomas aka taemon

… maybe one could close this thread