Notifications
Clear all

[Closed] select inverese by name ??

Ok im still learning maxscript and i using a naming convention for my rigs and max scene.

On my name convention i use firstable the name of the character or object follow by “_” example :

testcharacter_

later i ad the side L_ ( for left side ) or (R_ for right side) or C_( for center ).

I will like a script for every object selected that will select the inverse by name and if is C wil keep the selection.

so example : if i have select the $.testcharacter_L_arm if i execute my script wil select the
$.testcharacter_R_arm.

the dificult comes is i want to have my script as more as generic as posible.so the name of the begining (testcharacter could change to other like car_ or …)
so i wil like the script to detect the character name in this case testcharacter_ and replace the side .

one time i have the select inverse by name script working i start to build other utilities that make my life easier , like inverse position by name or inverse rotation by name so i only have to place one side of my rigs and the other wil be put in place by the script easly.

thanks for the help in advance.

4 Replies
 rdg

what you need is filterString the object name for ‘_’.
this splits the name into an array.
the array looks like this:
[1] name of character
[2] Side
[3] item name.

using a ‘case of’ you can then invert your selection.

Georg

 PEN

rdg has it it right. Here is a bit of hack untested code but will get the point across.


 --Filter the string into its parts
 fStr=filterString "theChracterName_R_arm" "_"
 --returns #("theCharacterName,"R","arm")
 
 --Swap the R for an L
 if fStr[2]=="R" then fStr[2]="L"
 
 --Build the name string back up
 otherSide=fStr[1]+"_"+fStr[2]+"_"+fStr[3]
 
 --Get the node by the name
 theNode=getNodeByName otherSide
 
 --Check if the node is valid and select it
 if (isValidNode theNode) then select theNode
 

thanks paul and rdg. thanks is a quick feedback ;).

I am in the midle of finishing a rig but a soon as I could i will try the scirpt or ideas you give me and post my code to see if is well done .

Hi i found time to finish the script thanks a lot guys for the ideas, I dided so can work with diferent amount of “_” so will work with longer names like “test_L_test_1_2 “and can have space in between the names like “test_L_arm dedo”

the code:
– create empty array

SI_Array = #()
– loop for all the objects in selection
for obj in selection do
(
–get the name
SI_a =obj.name
–Filter the string into its parts
fStr= filterString SI_a “
–Swap the R for an L and add varibale for append
if fStr[2]==“R” then (fStr[2]=“L”)
else (
if fStr[2]==“L” then ( fStr[2]=“R”) else ()
)
–Build the name string back up
SI_b = fstr.count
otherside= “”
for i = 1 to SI_b do
(
a= (if SI_b == i then fStr[i] else (fStr[i] + “
”) )
otherside += a
)
–Get the node by the name
theNode= getNodeByName otherSide
– append to the SI_array if the object exist
if ( execute ( “$” + “’” + otherSide + “’” )) != undefined do (
append SI_Array thenode
)
)
clearSelection()
select SI_Array

this is the way i dided if anyone seensomething he will do diferent or could be done simple wil lbe great to know