PDA

View Full Version : My first mel script....


tomof
01-31-2013, 06:59 PM
Hey there. I'm trying to write a script to automate a process i repeat over and over.
The process is, load and constrain a locator to a selected object.
Bake the trans and rotations to the locator.
Swap the constraints around so the object is controlled by the locator.

I have copied and pasted this script from the script editor. It works using a cube and locator. The cube has animation and the locator gets constrained to the cube.

One of the problems I have is not knowing how to script attaching the locator to the selected object.

select -r pCube1 locator1 ;

PointConstraint;
performPointConstraint 0;
pointConstraint -mo -weight 1;

performOrientConstraint 0;
orientConstraint -mo -weight 1;

select -r locator1 ;

bakeResults -simulation true -t "1:24" -sampleBy 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -bakeOnOverrideLayer false -controlPoints false -shape true {"locator1"};

select -r locator1_pointConstraint1 locator1_orientConstraint1 ;
doDelete;

select -r locator1 pCube1 ;

PointConstraint;
performPointConstraint 0;
pointConstraint -mo -weight 1;

performOrientConstraint 0;
orientConstraint -mo -weight 1;

Any help would be much appreciated.
Thanks in advance.
T.

ldunham1
01-31-2013, 10:55 PM
in effect, the very top line is what you wanted to look further into. Check out the command documentation and try breaking down the codes line by line, finding out what each on does.
To be able to gather data and then store it for use later on, variables are used.
So you want to store the selected object into a variable and then use that in the script instead.

string $framesToBake = "1:24";

string $selected[] = `ls -sl`;
// this assumes that the first selected object is the 'cube' and the second is the locator
string $cube = $selected[0];
string $locator = $selected[1];

string $pConstraint[] = `pointConstraint -mo -weight 1 $cube $locator` ;
string $oConstraint[] = `orientConstraint -mo -weight 1 $cube $locator` ;


bakeResults -simulation true -t $framesToBake -sampleBy 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -bakeOnOverrideLayer false -controlPoints false -shape true {$locator};

delete $pConstraint $oConstraint;

pointConstraint -mo -weight 1 $locator $cube ;
orientConstraint -mo -weight 1 $locator $cube ;

Although i dont think this is going to give you the result you want, as it wont work if the original object has keys/constraints/connections etc.

What are you looking to be able to do?

tomof
02-15-2013, 03:56 PM
Hey there.
Thanks for your reply, sorry for the late response, I had a deadline to attend too.
You're right, it is the first line i'm having trouble with. I'm trying to select an object, create a locator, then constrain the locator to the selected object.

My problem is, in the scene, the names of the objects and locators will change each time I run the script.

Therefore i'm trying to figure out how to code "constrain the last locator created to the last object selected"

Ive tried to use a string to store the name of the selected object

string $constrainToMe[] = `ls -sl`;
CreateLocator;

But i'm unsure how to get the locator to constrain to the string $constrainToMe

Any guidance would be really appreciated.
Cheers, T.

kdronez
02-15-2013, 04:27 PM
Hey there.
Thanks for your reply, sorry for the late response, I had a deadline to attend too.
You're right, it is the first line i'm having trouble with. I'm trying to select an object, create a locator, then constrain the locator to the selected object.

My problem is, in the scene, the names of the objects and locators will change each time I run the script.

Therefore i'm trying to figure out how to code "constrain the last locator created to the last object selected"

Ive tried to use a string to store the name of the selected object

string $constrainToMe[] = `ls -sl`;
CreateLocator;

But i'm unsure how to get the locator to constrain to the string $constrainToMe

Any guidance would be really appreciated.
Cheers, T.
Maybe try using filterExpand option.

string $locators[]=`filterExpand -sm 22`;
string $objects[]=`filterExpand -sm 12`;

first will return to you only the locators from the selected objects
second one will return only the objects :>.Also waht you can do is give your locator initial proxy name and after you finish with him rename it so your proxy name will be always in use and you dont have to worry :>.
Hope this helps if not sry for wasting your time T_T.

Panupat
02-15-2013, 05:49 PM
So, at the end, you want the locator to be where the object is with the same transform and rotation the object has right? Except now the object would be constrained to the locator and has 0 translate and rotation?

I think this would be an easier work flow...
1. store the translation and rotation of the object into variables.
2. reset your object back to 0 0 0
3. create locator at 0 0 0, constrain your object to it.
4. apply the values from 1 to the locator

Would this give you the same result you're after?

tomof
02-19-2013, 10:44 AM
Hey there.
Thanks a million for the input, i have found a script on Creative Crash that does pretty much what I was looking for.

http://www.creativecrash.com/maya/downloads/scripts-plugins/animation/c/make-anim-global

I'm new when it comes to mel so your help has been greatly appreciated. I'm going to try and de construct this code and see how it was done.
Many thanks, T.

CGTalk Moderation
02-19-2013, 10:44 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.