Mel, Duplicate object at vertex locations

Mel, Duplicate object at vertex locations

RickFalck
Advocate Advocate
1,819 Views
3 Replies
Message 1 of 4

Mel, Duplicate object at vertex locations

RickFalck
Advocate
Advocate

Mel Noob... 

Trying to duplicate a bone at the location of each vertices of a selected object. 

Trying to cast vertex selection to an array, and i think that works, but then when trying to match transforms i get 'need to have two objects selected' error.

Was trying to modify an earlier script that works ok when replacing other objects, but i think im missing something with how vertex names are stored.

here is the code

//Duplicate joint0 at Selected vert Locations 

if (`objExists joint0`)
{
    // Cast the vertices of selected into an array
    string $selVerts[] = `polyListComponentConversion -tv -fe`;

    // See if nothing is selected
    if ($selVerts[0] != "") 
    { 
      // Perform for each selected
        for ( $i=0; $i<size($selVerts); $i++ ) 
        {
            //Selects and duplicates joint0
            select -r joint0;
            duplicate -n newJoint;
            //Moves duplicate joint to selected pin location
            matchTransform -pos newJoint $selVerts[$i];
             
			print ("Duplicated successfully. \n");
          }// end of for
      }// // end of if
      else 
      {
        string $s ="Error: Something went Wrong! \n";
        print $s;
       }// // end of if objExists
}

else
{
print "joint0 object is missing. \n";
}  


I feel like im close but missing something probably obvious.

0 Likes
Accepted solutions (1)
1,820 Views
3 Replies
Replies (3)
Message 2 of 4

RickFalck
Advocate
Advocate

any ideas on this? is there a way to store all vertex locations in an array?

0 Likes
Message 3 of 4

mspeer
Consultant
Consultant

Hi!

 

There are several errors in this code, so besides the basic idea you are not very close.

 

Problem 1:

matchTransform does not work with components, this only works with objects.

 

Problem 2:

polyListComponentConversion only provides one entry OBJECTNAME.vtx[*]

 

I recommend to test the individual commands before creating the final code.

Message 4 of 4

RickFalck
Advocate
Advocate
Accepted solution

Thanks yes i figured out matchTransform does not work with components. After that it started to come together.


Probably a cleaner or easier way to do this, but here is what it looks like. 

*Updated*

 

string $MyObj[] = `ls -sl`;
//Creates array of vertex IDs
int $selVerts[] = `polyEvaluate -v $MyObj`;

int $i = 0;
    for($i; $i < $selVerts[0]; $i++)
    {
        //Selects and duplicates joint0
        select -r joint0;
        duplicate -n newJoint;  
        //Creates float array that = XYZ of vertexIDs
        float $fVtxPos[] = `xform -q -ws -t ($MyObj[0] + ".vtx["+$i+"]")`;
        print($obj + ".vtx["+$i+"] " + $fVtxPos[0] + " " + $fVtxPos[1] + " " + $fVtxPos[2] + "\n");
        //moves newJoint and renames
        move -a $fVtxPos[0] $fVtxPos[1] $fVtxPos[2] newJoint;
        rename duplicatedJoint;

    }

 

 

0 Likes