Notifications
Clear all

[Closed] general questions about names/objects in maxScript

Hi everyone
I try to learn the basics of maxScript these days, and I ran into the following scenario:

  • I create a box using box name:“mybox”
  • I repeat the command, resulting in a second box with the name “mybox”
  • I execute delete $mybox and only one box gets deleted
  • I repeat the delete command and the second box gets deleted
  • Using delete $mybox* though, both boxes will get deleted at the same time

Why is that only one box gets deleted when not using the asterix (*)?
If I have many objects in my scene with the same name, is there any way to index them anyways? Or is this based on the last selected/created/modified object with a certain name? Or is it purely random which objects gets adressed in max, assuming multiple objects share the same name?

I understand that it’s not good practice to have multiple objects with the same name in a scene. This is purely to get more indepth into maxScript. So I hope some of the wise max gurus here can help me out with an explanation.

cheers,
Daniel

7 Replies

Why is that only one box gets deleted when not using the asterix (*)?

if you are not using wildcards, delete only works for single object, or object set. i think it was based on the last -> first accessed (selected) order.

in your case wildcard () is searching for objects beginning with “mybox”, and deleting them. as all your object names begin with “mybox”, they all get deleted. if you had mybox1, mybox2, mybox_abc, etc, they would be deleted by [I]delete $mybox[/I] command also…

while creating an object in max, you can use a variable for counting the object you are creating and adding it to the name.

<object>.name = “mybox” + (<variable> as string)

also using a random number at the end is a fast solution

<object>.name = “mybox” + (random <min number> <max number> as string)

Internally, MAX does not care about object names – the objects are unique entities and the names play no role in distinguishing between them and references use pointers to the object instances to do all the linking, constraining etc.

So in Max 1.0, you were allowed to have all objects in the scene with the same name and it would not complain, but it would have been a pain for the user to select and work with them as the user needs a name to recognize what is what.

In Max 2.0, MAXScript was introduced and this became a problem since MAXScript allows the names to be used in “paths” to the objects in the scene and duplicated names mean the path is pointing at the FIRST object MAXScript finds with that name. That’s why your delete() function deletes only one object. GetNodeByName() also returns one object even if there are many with the same name. It is a case to be avoided.

MAXScript provides the method uniquename() which generates a name out of a string by adding numbers at the end to ensure each object is named uniquely.

Thus,

box name:(uniquename “MyBox”)

is the way to go to prevent confusion.

i can’t believe that autodesk kept that one hidden at the end of the node reference
my scripts will be getting smaller, thanks bobo

You do know Bobo writes the maxscript reference don’t you?

that’s why there is a smiley at the end of that sentence
the dvd set of Bobo and Laszlo Sebo is why I started maxscript…

The truth is somebody else put that function there (it was John Wainwright back in Max 2 days I guess).

What I will do for the next build of the Reference is add a FAQ based on this thread which discusses unique and duplicate names matter and shows how to use uniquename() in that context…

Thanks so much for the replies guys. It not only helps me to understand maxScript better, but the tip with uniquename will certainly benifit all my future scripts.

Thanks,
Daniel