PDA

View Full Version : inserting a variable in object name


Arturo
08-08-2011, 06:19 PM
for ($i = 1; $i < 77; $i++) //
{
select -r OBJECTANAME$i:nurbsToPoly1 ;
select -add OBJECTBNAME$i:nurbsToPoly1 ;
blendShape -frontOfChain;
}




This ain't working knowing that I would like to loop 77 times the creation of a blend shape selecting OBJECT A and B Both with same number i.


If I put[$i] it recognizes the variable but writes the [] in the object name so it isnt working neither.

Same problem in Phyton

for i in range(1,77):
cmds.blendShape( ObjectAi, ObjectBi)

ain't working neither

Please can you help me on how to write this correctly?
thanks a lot

NaughtyNathan
08-08-2011, 09:52 PM
in both MEL and python you must catenate ( + ) strings and variables.
select -r ("OBJECTANAME" + $i );
OBJECTANAME is a LITERAL STRING so you must treat it as such and enclose it in "quotes". however, if that too is a variable the catenate rules are basically the same:
select -r ($OBJECTANAME + $i );

However, in python you can only catenate strings, not ints or floats or whatever, so you must cast them to strings:
cmds.blendShape( ObjectA + str(i), ObjectB + str(i) )
# or:
cmds.blendShape( 'ObjectA' + str(i), 'ObjectB' + str(i) )
# or use string formatting if they are strings, not variables:
cmds.blendShape( 'ObjectA%d' % i , 'ObjectB%d' % i )
:nathaN

Arturo
08-09-2011, 01:33 PM
Thanks a lot Nathan!

And what about if the variable is in the middle of the name?

"OBJ" + $i "ECTNAME" ;

Is this correct?
In Python:
cmds.blendShape (Obj + str (i) ectA , Obj + str (i) ectB )

thanks!

gonzalimator
08-10-2011, 07:15 AM
And what about if the variable is in the middle of the name?

"OBJ" + $i "ECTNAME" ;

Is this correct?

For MEL, just don't forget the brackets (and the + signs).
("OBJ" + $i + "ECTNAME") ;
I don't know how it's done in Python.

CGTalk Moderation
08-10-2011, 07:15 AM
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.