XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : connecting vertex x,y,z to other vertex x,y,z ?

01-13-2004, 01:53 PM
I'd like to connect the pntx, pnty, pntz of every vertex in two polygon objects... but I can't seem to get the syntax right.
The following line of code works fine (not very usefull for my purposes though)...

connectAttr -f pCubeShape1.pnts[0].pntx pCubeShape2.pnts[0].pntx;
But I get syntax error on the third line in the following code...
string $selection[] = `ls -sl -fl`;

string $shapeNodes[] = `listRelatives -s $selection`;

connectAttr -f $shapeNodes[0].pnts[0].pntx $shapeNodes[1].pnts[0].pntx;
(never mind the [0] and [1], they read something like [$i] and [$j] in my code)

My question is... how do I write the third line of code??

01-14-2004, 03:26 AM
After some sleep and some further struggling I finally got it to work :)

By calling connectAttr with function syntax and doing some string concatenation the syntax error was fixed. The "trick" is highlighted with blue text. Removed some code for checking various stuff (orange comments).

Here is the code (hope it will be of some help to someone):

// Connect the pntx / pnty / pntz attributes of all vertexes in the last selected
// object ( $shapeNodes[ $lastobj ] ) to the same attribute on corresponding vertex
// in every previously selected object ( $shapeNodes[ $i ] ),
// i.e. when a vertex in the last selected object is moved, the same vertex in the
// other selected objects move acordingly.

string $selection[]; // array of selected objects //
string $shapeNodes[]; // array of shape nodes for the selected objects //

string $pntj; // will hold ".pnts[" + $j + "]" i.e. ".pnts[#]" where # is an int //

int $nvertex[]; // number of vertices in the polygon objects //
int $vcount; // number of vertices in the 1st polygon object //
int $lastobj; // index of the last selected object
int $i; // for-loop counter (objects) //
int $j; // for-loop counter (vertexes) //

$selection = `ls -sl -fl`; // get all selected objects //

// excluded code: check number of selected objects >1 and that all is in object mode //

$shapeNodes = `listRelatives -s $selection`; // get shape nodes //

// excluded code: check all selected objects are poly mesh objects //

$nvertex = `polyEvaluate -vertex $selection[0]`; // get no vertexes in the first selected object //

$vcount = $nvertex[0];

// excluded code: check same number of vertexes in all selected poly mesh objects //

$lastobj = size( $shapeNodes ) - 1; // get index of the last selected object //

// Connect the pnts.pntx/pnty/pntz attributes
for ( $i = 0; $i < $lastobj; $i++ ) // cycle through all selected object except the last one //
for ( $j = 0; $j < $vcount; $j++ ) // cycle through all vertexes //
$pntj = ".pnts[" + $j + "]"; // ".pnts[#]" # is an int //

connectAttr( "-f", $shapeNodes[ $lastobj ] + $pntj + ".pntx", $shapeNodes[ $i ] + $pntj + ".pntx" );
connectAttr( "-f", $shapeNodes[ $lastobj ] + $pntj + ".pnty", $shapeNodes[ $i ] + $pntj + ".pnty" );
connectAttr( "-f", $shapeNodes[ $lastobj ] + $pntj + ".pntz", $shapeNodes[ $i ] + $pntj + ".pntz" );
There is still a few more lines of code to add before my first script is complete... the vertexes of the controlled objects are supposed to move in the opposite direction (mirrored in user selected xy/xz/yz plane)... back to work! :)

01-14-2004, 10:04 PM
connectAttr( "-f", $shapeNodes[ $lastobj ] + $pntj + ".pntx", $shapeNodes[ $i ] + $pntj + ".pntx" );

could be:

connectAttr -f ($shapeNodes[ $lastobj ] + $pntj + ".pntx") ($shapeNodes[ $i ] + $pntj + ".pntx" );

if you don't want to use the function syntax. Maya can't group the string concatenations in two different arguments on its own, so each argument needs to be in parentheses.

-- Mark

CGTalk Moderation
01-17-2006, 04:00 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.