Notifications
Clear all

[Closed] use an object's name is a variable

 gcx

Hello, I’m learning maxscript and I am confronted to a very simple problem (I think) and I can’t seem to be able to find the answer…

I want to store the selected object’s name using a variable, so I enter:
mysel = $.name

It then returns (for example):
“Box01”

Now, when I deselect the object, I want to be able to reselect it by using:
select $mysel

Now obviously, that doesn’t work because it stores the ” ” as well.

So my question is very simple. How can I store an object’s name is a variable without the ” “.

Thanks in advance!!

2 Replies

To select an object using a stored variable value I think you need to use “getNodeByName”.

For example try this…

mysel = $.name
select (getNodeByName mysel)

Something that escaped me for a long time when learning to program was that variables can hold more than just basic values such as strings or numbers. They can hold references, such as objects, keyframes, modifiers, etc.

So if you want to store the name, that’s fine.

 mysel = $.name

However, you’re actually storing a string, not a selection (your variable is called mysel, right?)
So as michael said, you have to convert the string back into an object reference if you want to make a selection.

A much more flexible approach would just be to store a reference to the object in the variable:

 mysel = $ 
select mysel

If you ever need the name, just reference the name property (or any other property)

 mysel.name 
mysel.height
mysel.material

Make sense?

Cheers,
Dave