SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / Script for creating joints based on existing locators?

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
11-10-2014, 05:47 PM   #1
thebooface
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
  Reply with quote
12-10-2014, 12:18 AM   #2
Gen
Super Moderator
 
Gen's Avatar
 
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
  Reply with quote
13-10-2014, 02:15 PM   #3
thebooface
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!
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing the "Quick help" window size in the maya 2012 script editor. Jouri Programming 3 27-11-2011 06:15 AM
locators to joints jamtho Animation 0 04-05-2011 04:42 PM
load pre-made script rejh2 Maya Basics & Newbie Lounge 3 28-02-2010 12:33 AM
GI_Joe script Blayd Maya Basics & Newbie Lounge 7 01-10-2006 10:07 PM
looking for a mel script on UV mapping junkyBob Maya Basics & Newbie Lounge 1 14-11-2005 03:21 AM