selecting multiple objects by name

selecting multiple objects by name

Anonymous
Not applicable
4,983 Views
36 Replies
Message 1 of 37

selecting multiple objects by name

Anonymous
Not applicable
Hi,

I want to select all nodes in a scene that have "moveall" in their name.
The following code only selects 1, how do I get all of them?

getnodebyname "moveall"


thx,
Brian
0 Likes
4,984 Views
36 Replies
Replies (36)
Message 2 of 37

Steve_Curley
Mentor
Mentor

select $*moveall*


getNodeByName "somename" returns a Node - it doesn't select the node.
getNodeByName "somename" all:true returns an array of nodes. Still doesn't select them though.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 37

Anonymous
Not applicable
ok, thx. i just need to put all of them in an array and then display them for now.

x = getNodeByName "Moveall" all:true
print x

doesn't work

sorry for the newbie questions, this is my first maxscript.

brian
0 Likes
Message 4 of 37

Anonymous
Not applicable
x = $*Moveall* as array
print x
0 Likes
Message 5 of 37

Anonymous
Not applicable
wher d u guys lurn all thes scripts,that are realy helpful,but i m trying since one year,its beyond my understanding how to begin wid?
0 Likes
Message 6 of 37

Steve_Curley
Mentor
Mentor
1: Try writing a script
2: Use the Maxscript help to work out what you did wrong
3: if if doesn't work, GOTO 2.

In other words, there's no easy way. You just have to learn how to use it the same way as you learn to do anything. Trial and error, read the help, the forums, books. Try again.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 37

paulneale
Advisor
Advisor
select $moveAll*

And to learn script well how about starting with all of the tutorials that ship with Max in the Max script help. It will takes lots of time. I have been at it for about 13 years.
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 8 of 37

Anonymous
Not applicable
Learning about scripting requires alot of trial and error.
Just like the other parts of the 3d universe.

I started out with the Getting Started from the 3ds max help section.
After two years on my own i have a decent understanding of how to build your own tools and macros.
Still have far to go if i want to do advanced plugins and stuff...
0 Likes
Message 9 of 37

Anonymous
Not applicable
ok, thx.

so now i can find all of my nulls, load them into an array, index them, and print them, but when i try to trimleft the name, i get the message:

-- Unable to convert: $Null:C-Ly_Sheppard_Ctrl_M_Moveall @ to type: String

i thought the items in my array were already strings?

thx
brian
0 Likes
Message 10 of 37

Steve_Curley
Mentor
Mentor
That depends on what is in the array. If you selected them by "x=$MoveAll* as array" then you have nodes, not names.

Try "print x.name". If that works, then so do the new batteries in my crystal ball...

You need to post the actual code, not just the results of it, for us to have any chance of working out what's wrong.

If you used "select $MoveAll*" then you have no array other than the built-in "Selection" collection, in which case you need to iterate over the collection "for obj in selection do" and you still need "obj.name" to get at the name.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 11 of 37

Anonymous
Not applicable
ok, here is what i have so far:

$*Moveall* as array
$*Moveall*.count
for i in $*Moveall* do
i as string
trimleft i "$Null:C-Ly_"
print i


and here is the output:

#($Null:C-Ly_Sheppard_Ctrl_M_Moveall @ , $Null:C-Ly_KroganGrunt_Ctrl_M_Moveall @ , $Null:C-Ly_Thane_Ctrl_M_Moveall @ )
3
OK
-- Error occurred in anonymous codeblock; filename: C:\Documents and Settings\bmckee\Desktop\LayoutQC.ms; position: 178
-- Unable to convert: undefined to type: String
undefined
undefined
OK

thx
brian
0 Likes
Message 12 of 37

Steve_Curley
Mentor
Mentor
Ok, first thing is getting the selection.
Either "select $*Moveall" or "x = $*Moveall as array", but not both or a combination. If you need them to be selected, then use the 1st form, if not then use the second. Remember that they do not need to be selected in order to work on them.
This does affect how you write the next part.

Either "for i in selection do..." or "for 1 = 1 to x.count do..."
Note that in the 1st case "i" is the actual object, in the second it is an index into an array of the objects (i.e. a number).


"something as string" won't work in either case, either "something.name" in the first case, or "x.name" in the second.

The loop won't work as it stands either way, because you don't have parenthesis around all the statements which need to be executed for each object.

Finally, "print" can give, how shall I say, interesting results - things printed twice, strings with quote marks around them (may seem trivial, but when you start on filenames it can be a pain). Use the "Format" function instead.

The image shows both methods and also shows that the results are the same. Which method you use depends on what else you need to do with the objects, but in most cases, unless you want to manually move them in the viewports, they don't need to be selected.


Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 13 of 37

Anonymous
Not applicable
To make things a little simpler to follow, you can use "for obj in x do" on the array version too. Then everything in the for loop is identical.

Also (and I know this isn't from you Steve, but to the op), it's not a good idea to have a variable called "x" that holds an array. It won't break anything, but you're better off using a descriptive name like "nullArray" or something so you know what you're looking at.
0 Likes
Message 14 of 37

Steve_Curley
Mentor
Mentor
LOL - I thought I was keeping it simple 😛


for obj in $*Moveall do
format "%\n" (trimLeft obj.name "Null:C-Ly_")

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 15 of 37

Anonymous
Not applicable
Thanks Steve, you are very helpful.

(
MyArray = ($*Moveall* as array)
for i = 1 to MyArray.count do
(
CharName = trimLeft MyArray.name "C-Ly_"
CharName2 = trimRight CharName "_Ctrl_M_Moveall"
format "%\n" CharName2
)
)

and here is the output:

Sheppard
KroganGrun
Than

Works well, except I lose the "t" in "KroganGrunt" and the "e" in "Thane".
Oh, I think thats because of the "t" and "e" in "_Ctrl_M_Moveall". How can I correct that?

I need to read up on maxscript syntax and parenthesis. I'm used to python scripting in MotionBuilder.

thx,
Brian
0 Likes
Message 16 of 37

Steve_Curley
Mentor
Mentor
Can you post a few examples of the full names - the Trim functions shouldn't lose odd letters like that.

As for the parenthesis - they are used mainly to create "code blocks" and to control the scope of variables. They have other uses as well, but those are the basic ones. "Scope" is covered quite well in the help.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 17 of 37

Anonymous
Not applicable
sure,

here are the full names before any trimming:

C-Ly_Sheppard_Ctrl_M_Moveall
C-Ly_KroganGrunt_Ctrl_M_Moveall
C-Ly_Thane_Ctrl_M_Moveall
0 Likes
Message 18 of 37

Steve_Curley
Mentor
Mentor
Ok, now I understand (I think) - it's removing any of the characters in the 2nd string from the 1st string - not quite what you would expect from working with other languages.

substituteString seems to work though, as it's looking for an exact match.

I created 3 objects and named them appropriately and selected them for this test.


(
for obj in selection do
(
str1 = obj.name
str2 = substituteString str1 "C-Ly_" ""
str3 = substituteString str2 "_Ctrl_M_Moveall" ""
format "%, %, %\n" str1 str2 str3
)
)


Essentially it is finding the quoted text within the string and replacing it with the 2nd quoted text, which is an empty string thus removing it. The results are what you are looking for, I believe.


Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 19 of 37

Anonymous
Not applicable
thanks Steve, substituteString worked well.

Here is what I have so far:
(
format "%\n" "" --blank line
MoveAllArray = ($*Moveall* as array) --put movealls in array
CharacterPath = substring maxFilePath 1 (maxFilePath.count-25) --get current file path and trim
CharacterPath = append CharacterPath "01_Characters\\" --change path to characters folder
CharacterFolderArray = (GetDirectories (CharacterPath+"*") as array) --load folders into FolderArray
for i = 1 to MoveAllArray.count do --loop thru array trimming character names
(
CharacterName = substituteString MoveAllArray.name "C-Ly_" ""
CharacterName = substituteString CharacterName "_Ctrl_M_Moveall" ""
format "%\n" CharacterName
for j = 1 to CharacterFolderArray.count do --loop thru array trimming folder names
(
FolderName = substituteString CharacterFolderArray CharacterPath ""
FolderName = substituteString FolderName "\\" ""
Match = stricmp CharacterName FolderName --compare characters name to folder names
if Match == 0 do
format "%\n" "Max character name matches folder name!"
)
)
)


My formatting got messed up when I pasted above, sorry. It loads all of my movealls into an array. Then reads folder names from my Characters folder on the network into another array. It compares Character names in max to folder names and prints if there is a match. It is a QC check for character names.

Got another question though. When i load my MoveAllArray it is full of characters:
C-Ly_Sheppard_Ctrl_M_Moveall
C-Ly_KroganGrunt_Ctrl_M_Moveall
C-Ly_Thane_Ctrl_M_Moveall


But it also loads an environment:
E-Ly_Mountain_Ctrl_X_MoveAll


Is there an easy way to keep the environment out of the array? Can I change this:
$*Moveall*

to exclude "E-Ly_Mountain_Ctrl_X_MoveAll"?

Nevermind, got it. "$*M_Moveall*" worked.

thx,
Brian
0 Likes
Message 20 of 37

Anonymous
Not applicable
sorry, got 1 more question. i have one environment in each file named something like
E-Ly_Mountain_Ctrl_X_MoveAll

i'm just trying to search for it and put it in a variable, not an array. This isn't working.

EnvironmentName = $*X_MoveAll* as string
format "%\n" EnvironmentName


this doesn't work either:
EnvironmentName = getnodebyname $*X_MoveAll* as string
format "%\n" EnvironmentName


sorry for this basic syntax type question...

thx,
brian
0 Likes