View Full Version : listRelatives question

 drGonzo07 July 2005, 11:56 AMlistRelatives -ad -type "joint" \$selectedJoint[0] -ad: Returns all the children, grand-children etc. of this dag node. If a descendent is instanced, it will appear only once on the list returned. Note that it lists grand-children before children. Is there a way to have children first and then grand-children? I tried: //sort (`listRelatives -ad -type "joint"\$selectedJoint[0]`); But when I have more then 10 joints, I get: // Result: joint10 joint11 joint12 joint2 joint3 joint4 joint5 joint6 joint7 joint8 joint9 // I want: joint 2 joint 3 joint 4 joint 5 joint 6 joint 7 joint 8 joint 9 etc...
A_New_Hope
07 July 2005, 05:07 PM
to get another sort result you must eighter rename the joints to 01 02 03 etc
or make your own sort function

here is a messy sort hack
it looks like it works as long as the name isnt over 99.
pCube99 works but pCube100 will be sorted after 19

// David Häggström / A New Hope
// mel@anewhope.se || anewhope.se
//
// messy quick sort hack
// looks like it works as long as the name isnt over 99
//
// if it over 99 then it ****s up :(
// pCube9, pCube10, ...., pCube19, pCube100, pCube20
//
//
//
global proc string[] anhSort( string \$ArrayToSort[] )
{
int \$antal;
int \$i;
int \$j;
string \$temp;

\$antal = `size( \$ArrayToSort )`;

for( \$i=0; \$i < \$antal-1; \$i++ )
{
for( \$j = \$i+1; \$j < \$antal; \$j++ )
{
\$temp = anhSortCompare( \$ArrayToSort[\$i], \$ArrayToSort[\$j] );
if( \$ArrayToSort[\$i] != \$temp )
{
\$temp = \$ArrayToSort[\$i];
\$ArrayToSort[\$i] = \$ArrayToSort[\$j];
\$ArrayToSort[\$j] = \$temp;
}
}
}
return \$ArrayToSort;
}

proc string anhSortCompare( string \$Word1, string \$Word2 )
{
int \$AntalL1 = `size( \$Word1 )`;
int \$AntalL2 = `size( \$Word2 )`;
int \$AntalL;

if( \$AntalL1 <= \$AntalL2 )
{
\$AntalL = \$AntalL1;
}
else
{
\$AntalL = \$AntalL2;
}

for ( \$q = 1; \$q <= \$AntalL ;\$q++ )
{
\$letterW1 = `substring \$Word1 \$q \$q`;
\$letterW2 = `substring \$Word2 \$q \$q`;

if( \$letterW1 != \$letterW2 )
{
string \$sortArray[];
\$sortArray[0]= \$letterW1;
\$sortArray[1]= \$letterW2;
\$sortArray = `sort( \$sortArray )`;

if( \$letterW2 == \$sortArray[0] )
{
if( \$q != \$AntalL1 || \$AntalL1 == \$AntalL2 )
{
return \$Word2;
}
else
{
return \$Word1;
}
}
else
{
if( \$q == \$AntalL && \$AntalL2 < \$AntalL1 )
{
return \$Word2;
}
else
{
return \$Word1;
}
}
}
else
{
if( \$q == \$AntalL && \$AntalL1 != \$AntalL2 )
{
if( \$AntalL1 == \$AntalL )
{
return \$Word1;
}
else
{
return \$Word2;
}
}
}
}
}

drGonzo
07 July 2005, 07:05 AM
Heh thanks bro. i didnt think anybody was going to reply ;-)
My mentor came up with this after I posted:

global proc string[] listChain(string \$root[])
{
string \$bones[];
string \$list[]=getNextJoints(\$root[0], \$bones);
return \$list;
}

global proc string[] getNextJoints(string \$root, string \$bones[])
{
string \$children[]=`listRelatives -c -type "joint" \$root`;
if (size(\$children)) {
for (\$c in \$children) {
appendStringArray(\$bones, {\$c}, 1);
getNextJoints(\$c, \$bones);
}
}
return \$bones;
}

chalbers
07 July 2005, 06:58 AM
Yep ! That's the right way to go . Recurse through children with same proc and add it all to the same array.

I had to do this many times.

Frank

Heh thanks bro. i didnt think anybody was going to reply ;-)
My mentor came up with this after I posted:

global proc string[] listChain(string \$root[])
{
string \$bones[];
string \$list[]=getNextJoints(\$root[0], \$bones);
return \$list;
}

global proc string[] getNextJoints(string \$root, string \$bones[])
{
string \$children[]=`listRelatives -c -type "joint" \$root`;
if (size(\$children)) {
for (\$c in \$children) {
appendStringArray(\$bones, {\$c}, 1);
getNextJoints(\$c, \$bones);
}
}
return \$bones;
}

Pickman
08 August 2005, 12:13 PM
Heya guys, I don't understand how this is actually working on a jointchain, let's say you have a top node named creature and want to iterate through its joints, how would you use this proc ?

I tried picking the first joint, or the top node then typing listchain; in the commandline and it returns:
// Error: Wrong number of arguments on call to listChain. //

?? what am I missing here ?

CGTalk Moderation
08 August 2005, 12:13 PM
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.

1