Form and Space

creating CG 3D since 2001

  • Connect @
  • Linked in
  • Vimeo
  • Twitter
melscript locators to cvs

Maya: Locators to CVs Script

Matthew | August 1, 2012

1 Comment

Here’s a very useful tool for animating or sculpting a curve(s) shape. I’m in the middle of finishing my training recording on making grapes, and I was in need of a tool like this. It’s all yours.


/**************
Locators to CVs 
version 0.4
Author:  Matthew L. Stoehr
formandspace.com
mattstoehr@gmail.com
updated Feb. 04, 2013

Creates a locator at each 
CV to animate or 
sculpt the curve shape.

Select curve(s), then run.
****************************/


mls_nullsToCVs();


proc string[] mls_nullsToCVs()
{

    string $sel[] = `ls -selection`;
    string $nulls[];
    
    for($node in $sel) 
    {
        select ($node + ".cv[*]");
    
        string $cvs[] = `filterExpand -sm 28 -fullPath true`;
        int $n = size($cvs);
        string $c[];
        string $clusters[];
        string $clustersTrans[];
        string $null[];
        string $nullgrps[];
        vector $v;
        
        //create and collect
        for($i = 0; $i < $n; $i++){
            //cluster each cv
            $c = `cluster -name ($node + "_cluster_" + $i) $cvs[$i]`;
            stringArrayInsertAtIndex($i, $clusters, ($c[0]+"HandleShape"));
            stringArrayInsertAtIndex($i, $clustersTrans, ($c[0]+"Handle"));
            hide $c;
            //make locators or cubes
            $null = `spaceLocator -absolute -position 0 0 0 -name ($node + "_cv")`;
            stringArrayInsertAtIndex($i, $nulls, $null[0]);               
        }
        
        //walk through collected
        for($i = 0; $i < $n; $i++){ 
  
            //move the locators to cluster origin
            $v = getAttr ($clusters[$i] + ".origin");
            //print ($i + ": " + $vOrigin + ", \n");
            setAttr ($nulls[$i] + ".translate") -type "double3" ($v.x) ($v.y) ($v.z);  
            parent $clustersTrans[$i] $nulls[$i];
                        
            /*  Group here, so the group 
            position is not at the origin, 
            but at the null's center.  */
            
            string $nullgrp = `group -n ($node + "_for_constraints_" + ($i)) $nulls[$i]`;
            stringArrayInsertAtIndex($i, $nullgrps, $nullgrp);
        }
        
        group -n ($node + "_TRANSLATION") $nullgrps;
        
        //empty the array before looping to next curve
        clear $nullgrps;   

    }
    
    return $nulls;
}


One response to “Maya: Locators to CVs Script”

  1. Matthew says:

    Updated this tool Feb. 4, 2013

Leave a Reply

Downloads

mls_nullsToCVs.mel

Twitter

Subscribers

    396