[Closed] Using a Variable to define partial object name?
Hi all,
Just wondering if it was possible to use a variable to be used to make up a full name when selecting an object
So for example
the objects are
$Square_Shape
$Circle_Shape
$Box_Shape
Can I define a variable Type = “Square” and then somehow plug it along when referring to the object.
E.G Type_Shape ?
Thanks
select $*Square*
This would select your objects with “square” in the name, i fthat’S what you’re looking for. If you want to batch rename objects, there is also the max tool in Tools -> rename objects.
edit: another way:
objectname = "box"
myobjects = (for a=1 to objects.count where findString objects[a].name objectname != undefined collect objects[a])
print myobjects
Thanks, hmm I should have added more details, thats not exactly what I was after. Maybe the whole way I am approaching this is not a good method.
So the script detects a certain named object in the scene, and then from there it switches some variables to match the objects.
Its a script to help automate some basic characters, its my first real serious script so I still am hacking and slashing my way a bit.
So when the script detects its a Male model by finding any object that begins with male it changes the variable to those specific body parts . e.g
Gender_type = Male
Head = $Male_Head
Legs = $Male_Legs
Feet = $Male_Feet
I was trying to put the in the $Male part as a variable so that instead of redefining the variables I could redefine one variable.
So it would look something like this (Geneder_Type is a variable)
So somehow splicing the Gender_Type variable with the $Male_Head selection.
Gender_type = Male
Head = Gender_type_Head
Legs = Gender_type_Legs
Feet = Gender_type_Feet
Lol I think I’ve just done it a bad way!
I’m still not sure if I understand what you’re trying to do, but maybe this helps you. Aussuming you want to rename your objects by adding your variable. The follwing code assumes that the Objects Head, Legs and Feet exist. I don’t like getnodebyname that much, as it could always happen that an artist renames objects.
--- your gender
Prefix = "Male_"
--- these are the names of the nodes to rename
NodesToRename = #("Head","Legs","Feet")
--- we replace the names with the actual nodes
for a=1 to NodesToRename.count do NodesToRename[a] = getnodebyname NodesToRename[a]
--- rename the nodes
for mynode in NodesToRename do mynode.name = (Prefix+mynode.name)
Maybe you can elaborate more about what you’re trying to do
Basically, if you want a variable in an object name, you can do it like this:
prefix = "blabla_"
suffix = "_01"
myobject.name = (prefix+myobject.name+suffix)
If you variable is not a string you can use:
gender = 1
case gender of
(
1: prefix = "male"
2: prefix = "female"
default: prefix = "NoSex"
)
objectname = "Teapot5000"
objectname = (prefix+objectname)
clearlistener()
print objectname
the most used way to collect nodes by pattern is a using of execute with a pathname.
for example:
charname = "Male"
legs = execute ("$" + charname + "_*leg*")
another way is to collect nodes using matching a pattern:
charname = "Male"
pattern = charname + "_*leg*"
for node in objects where matchpattern node.name pattern:pattern collect node
usually i use the method #2 because it’s easier to specify a list of node where you need to search in
Fantastic! this was definitely what I was after, this really helps and also gives me a good insight how to tackle other things!
I am trying to set up a basic character randomiser, but I have each gender stored in a different max file, at one point I was building each one their own script but as I continued to add to it and add new features this wasn’t very practical.
Thank you so much for the help!