Home Technical Talk

[Maya] Translate/Snap objects with different pivots without grouping?

I've never found a way to do this: Take a selection of objects and snap them them to a new point on the grid without grouping or changing the pivot for each object. In most cases, I'd really rather not disturb the existing grouping just to make a quick change, like expand a hallway or make room for some late change to a map layout. Any ideas?

Replies

  • dlz
    Options
    Offline / Send Message
    dlz polycounter lvl 4
    i would like to know this too
  • TTools
    Options
    Offline / Send Message
    TTools polycounter lvl 4
    I got you  :)

    This is a bit of a hack, but it does work.  Here's the quick breakdown:  I'm creating a dummy locator, and then connecting my objects to that locator via a parentConstraint.  You can then move the locator and the objects follow.  I've written you code for the connecting process and the removal of the constraints.  Just follow the code comment instructions below.

    A couple caveats: Don't try and move the objects individually while they are constrained to the locator.  If you do, and then you move the locator, your individual objects will shift. Second, the locator being created at the origin isn't ideal.  I could modify the code so that the creation of the locator occurs at the pivot point of the first object selected.  If you find the following code useful, I'd be willing to make that modification.
    good luck!


    //Select all the objects you want to constrain and run the following code.
    //This will create a locater at the origin with parent constraints linked to the objects
    //you had selected.  You can now move, rotate, and scale the locator, and the objects will follow.
    //Your hierarchy will be untouched.  This can work on objects and/or existing groups.

    string $selected[] = `ls -sl -long`;
    spaceLocator -p 0 0 0;
    string $locator[] = `ls -sl`;
    for ($i=0;$i<size($selected);$i++)
    {
        parentConstraint -mo -weight 1 $locator[0] $selected[$i];    
    }



    //Once you're done moving your objects around, you'll want to get rid of the parent constraints.
    //To do so, select all the objects you previously selected that were linked to the locator.
    //Run this code.  All of the parent constraints "should" be removed.  You can now delete the locator,
    //and continue to beat Maya into submission.

    string $selected[] = `ls -sl -long`;
    for ($i=0;$i<size($selected);$i++)
    {
        string $constraint[] = `listRelatives -f -type "parentConstraint" $selected[$i]`;
        if (`objExists $constraint[0]` == 1)
        {
            delete $constraint[0];
        }

    }

  • throttlekitty
    Options
    Offline / Send Message
    @TTools oh wow thanks! You're digging through all my old threads, eh?

    Using the first selecteds pivot as pivot would be a nice touch, thanks!
  • TTools
    Options
    Offline / Send Message
    TTools polycounter lvl 4
    Caught red handed. Was bored and looking for something to do.  Besides, you bought my tools so that's strong encouragement for me to help a brother out.  :p

    This code should work even better.  This will put the locator at the pivot location of the first selected object.

    //Select all the objects you want to constrain and run the following code.
    //This will create a locater at the pivot of the first of the objects
    //you had selected.  You can now move, rotate, and scale the locator, and the objects will follow.
    //Your hierarchy will be untouched.  This can work on objects and/or existing groups.

    string $selected[] = `ls -sl -long`;
    float $worldLoc[] = `xform -q -rp -ws $selected[0]`;
    spaceLocator -n "TT_MoveByLocator" -p 0 0 0;
    move -ws $worldLoc[0] $worldLoc[1] $worldLoc[2];
    string $locator[] = `ls -sl`;
    for ($i=0;$i<size($selected);$i++)
    {
        parentConstraint -mo -weight 1 $locator[0] $selected[$i];    
    }


    AND
    This is a complete rewrite of the code in my first post for removing the parentConstraints.  The previously posted removal code required you to select all the objects that you had originally selected. That's a bit cumbersome since the user will most likely already have the new locator selected.
    So instead of that, once you're done moving the objects around via the locator, and with it alone selected, just run the code below and it will remove all parentConstraints on the linked objects and the locator itself.  Like they were never even there.  ;)  


    //A method of removing the Parent Constraints by just selecting the generated locater
    //and running this code.  This is a bit more "scripty" as listConnections does not return
    //long names, thus we need to run it through another `ls` command to ensure we're catching
    //only the desired constraints in case of identically nested constraint names.

    string $selected[] = `ls -sl -long`;
    string $constraintsAll[] = `listConnections -source false -type "parentConstraint" $selected[0]`;
    select $constraintsAll;
    string $constraints[] = `ls -sl -long`;
    delete $constraints;
    delete $selected;

    Give this a try.  If it works out favorably, I can throw it into some global procs for easier deployment to shelf buttons and downloading.
    cheers!

Sign In or Register to comment.