View Full Version : Insert joint in middle

03 March 2011, 05:06 PM
Hi all.

I'm trying to create a MEL script which creates a joint right in the middle between two others, say between shoulder_JNT and elbow_JNT.
I know the position of shoulder and elbow, so I guess I should use that.I was thinking about using insert joint, because that will automatically orient it correctly, and then just parent it out of the hierachy after its creation, but I can't really wrap my head round, how I position it correctly.

Any ideas?

03 March 2011, 05:45 PM
Use a parent constraint with maintain offset off (by default) and delete the constraint

pConstraint = `parentConstraint shoulder_JNT elbow_JNT inbetween_JNT` ;
delete pConstraint;

Then parent the inbetween_JNT under the shoulder_JNT

parent inbetween_JNT shoulder_JNT ;

if your shoulder / elbow have odd rotation values your inbetween might not get placed correctly. In this case, use a pointConstraint instead, delete the pointConstraint, parent under the shoulder, then set your rotations to zero on the inbetween.

Robert Bateman
03 March 2011, 05:57 PM
$joint1 = "shoulder_JNT";
$joint2 = "elbow_JNT";
$joint3 = "someNewlyCreatedJoint";

// position using point and orient constraints.
select -r $joint1;
select -add $joint2;
select -add $joint3;
$pconstraint = `pointConstraint -o 0 0 0 -w 1.0`;
select -r $joint1;
select -add $joint3;
$oconstraint = `orientConstraint -o 0 0 0 - w 1.0`;

// get rid of the constraints (leaving the joint in the correct location)
delete $oconstraint;
delete $pconstraint;

// get world space rotation values
$rx = `getAttr ($joint3+".rx")`;
$ry = `getAttr ($joint3+".ry")`;
$rz = `getAttr ($joint3+".rz")`;

// move into the joint orient, and zero the rotation
setAttr ($joint3+".jo") $rx $ry $rz;
setAttr ($joint3+".r") 0 0 0;

// now parent the joint (which will automagically calculate the local space position + joint orient).
// If you don't want the joint in the hierarchy, comment out this line ;)
parent $joint3 $joint1;

03 March 2011, 07:56 PM
Wow, thanks guys!

That makes perfect sense and was easily applied to what I'm working on.
Great :)


CGTalk Moderation
03 March 2011, 07:56 PM
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.