View Full Version : How to select objects with part of the name created dynamically
05-04-2009, 08:55 PM
I have a rollout that has a text field used to give the right prefix to already created objects and to new ones that will get created through another maxcript.
When it comes to changing the prefix of an object that is already in my scene things work just fine.
Also giving the new prefix to an object that will get created through a script works too.
My problem is when i want to perform an action with those newly created objects, i don't know how to get them correctly with the $. If part of my objects name (string) is built with a variable, how can i can i select it afterwards?
-- coming from a rollout
edittext prefix_Text "Name" enabled:true
prefixText = prefix_Text.text
MyBox.name = (prefixText + "Box")
How would i then select this box through a script and perform actions with it? Let's say:
$myNewlyCreatedBoxWithTheVariableAsPartOfTheName.transform = $Box01.transform
I hope I'm clear enough. Thanks everyone and keep on Postin'
05-04-2009, 08:59 PM
take a look at "getNodeByName", under "Node Common Properties, Operators, and Methods" in MaxScript Reference. If I understood your problem well, it could provide the solution.
05-05-2009, 02:14 AM
i had problems with getNodeByName recently where it returned the correct node but the transform was set to the identity matrix which was completely useless to me. if you use getNodeByName in the listener it works fine but in my script it broke...
so i ended up looping through the scene geometry and collecting the first occurence of the node with the right name using matchpattern like this:theNodeThatIWanted = (for o in geometry where matchpattern o.name pattern:myNamePattern collect o)For anyone that is interested I encountered this problem using getNodeByName in max design 2009 64bit
05-05-2009, 12:49 PM
Thanks for the heads up. I can see your problem affecting me since a lot of the things i do with my nodes have to do with their transform.
About your code
theNodeThatIWanted = (for o in geometry where matchpattern o.name pattern:myNamePattern collect o)
Why do you have the  at the end?
Thanks a lot for the response guys, it's greatly appreciated. Have a good day
05-05-2009, 01:06 PM
his line collects all object matching that pattern into an array.. Even if there's only 1 object that matches, he'll still need to get that out of the array. For multiple matching objects, the  just means he ends up using the first of those found.
05-05-2009, 01:19 PM
to add to what Richard has already said, you can think of it like this:-- define the new object name to test for
myNamePattern = "prefix_box01"
-- collect all the geometry objects with who's name matches the string held
-- in the variable 'myNamePattern' into a new array called 'myArray'
myArray = for o in geometry where matchpattern o.name pattern:myNamePattern collect o
-- get the first node in the array. could be undefined if there were none
-- so you should check for that unless you're really sure!
theNodeThatIWanted = myArray
05-05-2009, 01:25 PM
Thanks a lot for the explanation.
So myNamePattern here would be a variable holding a string? Could this string be built in part with a variable and an actual string, like (myName + "_Arm_Right")?
Thanks again :)
05-05-2009, 01:39 PM
Hi Gravey, apparently we posted pretty much at the same time cause i hadn't seen your post when i wrote mine.
So you would have to create an array for every object you want to work on and anytime you want to perform an action with one of those object you would refer to the corresponding array, right?
If i wanted to perform action with those objects but through a custom attribute holder, i guess i would need to create the needed arrays with that same technique inside my custom attribute holder definition?
Also, my main goal here is to have the user give a name to the character that he will rig through a rollout. The name entered would be put in a global variable, let's say, myCharName. So i guess that when i would be looking for my objects, arm for example, the MyNamePattern variable would be built like this: (myCharName + "_Arm_Right").
Now if i have multiple characters in my scene that have been rigged in the same fashion, would i end up with conflicts?
Thanks for your time guys, it's really helping me out.
05-05-2009, 01:39 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.