Spawn locators on object verts?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  05 May 2013
Spawn locators on object verts?

Hi, does anyone know how to spawn locators on an objects vertices? I'd like to create an array of lights in after effects and need locators where the polygons verts are. Thanks
  05 May 2013
I posted a question about my attempts to do this with cubes is here:
The script I used with the fix suggested by haggi and Naughty Nathan is here:
	// select verts and run
	string $allVerts[] = `ls -sl -fl`;
	string $eachVert;
        int $i = 1;
     for ($eachVert in $allVerts)
	//Get vertex world position
	float $vertPos[] = `pointPosition -w $eachVert`;
	//Create a cube for each vert
        string $cube[] = `polyCube -name ("vertCube_"+$i+"_PLY")`;
	//Sets the translates of the locators to the stored variables
	setAttr ($cube[0] + ".translateX") $vertPos[0];
	setAttr ($cube[0] + ".translateY") $vertPos[1];
	setAttr ($cube[0] + ".translateZ") $vertPos[2];

I think you can take it from there.
Hope that helps
  05 May 2013
Thanks Ben. I tried to modify it to work with a locator but no dice (i'm new to MEL). Could you please point me in the right direction?
  05 May 2013
no worries, the basic idea is that anything with a $ in front is a variable so the actual name of it doesn't matter...the value of the variable is all that matters.
In this case all you need to do is change the line:
string $cube[] = `polyCube -name ("vertCube_"+$i+"_PLY")`;


string $cube[] = `spaceLocator -name ("vert_"+$i+"_LOC")`;

Technically, you don't even need to change the -name section, but this should give you an idea how to customize the names of your locators.
Hope that helps.
  05 May 2013
i posted an answer on your reddit post:

 // copy the script to a mel window, change start/end frames, select your vertices and run
 int $start = 0;
 int $end = 10;
 string $vertices[] = `ls -sl -fl`;
 string $locators[];
 for($v in $vertices){

     string $newLoc[] = `spaceLocator`;
     $locators[size($locators)] = $newLoc[0];
     currentTime $i;
     for($j = 0; $j<size($vertices);$j++){
         float $pos[] = `xform -q -ws -t $vertices[$j]`;
         setAttr ($locators[$j]+".translate") $pos[0] $pos[1] $pos[2];
         setKeyframe ($locators[$j]+".translate");
maya@reddit r/maya
  05 May 2013
Whoa, I didn't know time was involved.
Deep thoughts.
  05 May 2013
Thank you both, the scripts work like a treat!
  05 May 2013
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 11:43 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.