Substance Painter
In this start to finish texturing project within Substance Painter we cover all the techniques you need to texture the robot character.
# 1 11-10-2014 , 05:47 PM
Registered User
Join Date: Mar 2014
Posts: 6

Script for creating joints based on existing locators?

Hey there!
I'm currently in a scripting class, and I've decided to write a script to create joints based on a selection of locators. Said joints would need to be automatically translated to the position of the locators - and this is the part I'm struggling with. Here's what I have up to now:

string $selectedLocators[] = `ls -sl`;
int $selectionSize = size($selectedLocators);
int $i;

//rename locators temp
for ($locatorName in $selectedLocators)
{
rename $locatorName tempName_loc;
};

//create appropriate number of joints
if ($selectionSize >=1)
{
for ($i = 1; $i <= $selectionSize; ++$i)
{select -cl;
joint;
}
}
else
{error ("Please select locators");}

//rename joints temp
select "joint*";
string $createdJoints[] = `ls -sl`;

for ($jointName in $createdJoints)
{
rename $jointName tempName_joint;
}

My plan was to find a way to match the name of the tempJoints to the corresponding tempLocs, but I'm not sure how to approach that. I know there are faster ways to get around it, but I'm trying to do it with the limited knowledge of mel I have - so if it's possible to get the next step done the way I originally intended to, that'd be awesome.

Thanks in advance,
Gio

# 2 12-10-2014 , 12:18 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,518
This can be done within a single loop block

Since this is a class assignment the following isn't working code but a guide.

I have to note, clearing the selection after we've saved a list of objects to act on is very important since the joint command cannot parent joints to multiple objects, you will get an error.


Code:
	selection[] = list selection;
	clear selection; //simply deselects objects and doesn't clear our array variable
	
	// this integer is for renaming consistency
	intCounter = 0;
	
	for(locator in selection){
	
		// need the world position of locator and the xform command is perfect for that
		xyzCoords[] = xform -worldSpace -query -translation locator;
		
		// start making joints at the given postions
		// using the elements of the xyzCoord array
		joint = joint -position xyzCoords[0] xyzCoords[1] xyzCoords[2];
		rename locator ("myTempName_" + intCounter);
		rename joint ("myOtherTempName_" + intCounter);
		intCounter++;

	}
Command Refs:
xform
joint


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::

Last edited by Gen; 12-10-2014 at 12:21 AM. Reason: Adding command ref links
# 3 13-10-2014 , 02:15 PM
Registered User
Join Date: Mar 2014
Posts: 6
Thanks so much for the reply!

Now I've advanced to the final part of the script, which was to come up with a way to have controllers be created and then set as parents of the locators. I've figured out how to do the parenting with the joints and the locators, since I can do it in the same loop - but since I want to give the user freedom to move the controls around before they're parented (by breaking this procedure and having a button the user can press once they're done rearranging which would call the "parenting" procedure), I can't really approach it the same way.
Is there any way to "save" the selections of two separate string arrays, and then have the corresponding locator and control names be matched?
I'm not even quite sure how to start tackling this one.
Thanks again!

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads