[Closed] How to select objects with part of the name created dynamically
Hello everyone,
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’
Ciao
Hi Guibou,
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.
- Enrico
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)[1]
For anyone that is interested I encountered this problem using getNodeByName in max design 2009 64bit
Hi Gravey,
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)[1]
Why do you have the [1] at the end?
Thanks a lot for the response guys, it’s greatly appreciated. Have a good day
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 [1] just means he ends up using the first of those found.
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[1]
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
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.