select an object with a part of his name

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 01 January 2009   #1
select an object with a part of his name


I would like to make a script that recognise the name of a selected object and select the opposite. For example: If a hand of a character named "Hand_L" is selected, the script will select the opposite hand named "Hand_R".

thanks a lot

Old 01 January 2009   #2

not fully tested and no error catching in it, but this should do the job:
if your left and right labels are different, then change them here:
sideIdentifierStrL = "_L"
sideIdentifierStrR = "_R"
This script works with multiple objects as well.

sideIdentifierStrL = "_L"
 sideIdentifierStrR = "_R"
 fn returnObjSideID obj =
 	return (substring ( - 1)
 fn returnObjNameWithoutSideID obj =
 	return (substring 1 ( - 2) )
 fn selectOppObjs = 
 		theSelObjs = selection as array
 		allRObjs = #();
 		allLObjs = #();
 		for i = 1 to theSelObjs.count do
 			curObj = theSelObjs[i];
 			curObjSideID = returnObjSideID(curObj);
 			curObjNameOnly = returnObjNameWithoutSideID(curObj)
 			if(curObjSideID == sideIdentifierStrL) then
 				allObjs = $* as array;
 				for obj in allObjs do
 					if(curObjNameOnly == returnObjNameWithoutSideID(obj)  and returnObjSideID(obj) == sideIdentifierStrR ) then
 						append allRObjs obj
 			if(curObjSideID == sideIdentifierStrR) then
 				allObjs = $* as array;
 				for obj in allObjs do
 					if(curObjNameOnly == returnObjNameWithoutSideID(obj)  and returnObjSideID(obj) == sideIdentifierStrL ) then
 						append allLObjs obj
 		print allRObjs
 		select allRObjs
 		selectmore allLObjs
Old 01 January 2009   #3
thank you !

yes it works ! Very usefull script for a character animator like me.
I put it as macroscript in my Quads.

Old 01 January 2009   #4
hmm ... it could do with some enhancements ...
1) It currently only looks for the side ID at the end of the object name. So the tool is of no use with bipeds which has default object names like `bip L hand` or something like that
2) The tool is restricted to the side ID string being of 2 letters eg "_L" or "_U" "_D"
Old 01 January 2009   #5
here's a slightly different method - you can keep the macros, it uses the same function name

  fn selectOpposites report:false = (
  	local curSel = getCurrentSelection()
  	local leftIDs = #("_L", "L ", "Left")
  	local rightIDs = #("_R", "R ", "Right")
  	local newSel = #()
  	for o in curSel do (
  		local oppNames = for i = 1 to leftIDs.count collect ( substituteString leftIDs[i] rightIDs[i] )
  		oppNames += for i = 1 to leftIDs.count collect ( substituteString rightIDs[i] leftIDs[i] )
  		local opposites = for oppName in oppNames where (oppName != collect ( oppName )
  		local nodes = for opp in opposites collect (getNodeByName opp)
  		if (report) do (
  			format "'%' opposites:\n"
  			for i = 1 to opposites.count do (
  				format "\t'%' (exists: %)\n" opposites[i] (nodes[i] != undefined)
  		for i = nodes.count to 1 by -1 do (
  			if (nodes[i] == undefined) then ( deleteItem nodes i )
  		join newSel nodes
  	select newSel

Adjust the "leftIDs" and "rightIDs" to match whatever you encounter.
If you call "selectOpposites report:true", then a small report will be printed. If the report states "exists: false", it means that the opposite object wasn't found. That's usually a good indication of one of two things:
1. it's not a name that should have been 'mirrored'
2. your character has lost a limb

Example output and effect in a test scene:

  selectOpposites report:true
  'Arm_L' opposites:
  	'Arm_R' (exists: true)
  'Leg R Lower' opposites:
  	'Leg L Lower' (exists: true)
  'Left Eye' opposites:
  	'Right Eye' (exists: true)
  'L L Cool J' opposites:
  	'R R Cool J' (exists: false)
  -- and back the other way around
  selectOpposites report:true
  'Arm_R' opposites:
  	'Arm_L' (exists: true)
  'Leg L Lower' opposites:
  	'Leg R Lower' (exists: true)
  'Right Eye' opposites:
  	'Left Eye' (exists: true)

Last edited by ZeBoxx2 : 01 January 2009 at 04:24 PM.
Old 01 January 2009   #6
Your script is so much better, Richard. And extendable too
Old 01 January 2009   #7
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 11:48 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.