Finding Selected Components Of Specific Object

Hey all,

I'm not sure how to fix my last problem, so I'm moving on to another problem. I have a script that calls for querying the selected components of a specific object. Is there a way to do that that doesn't involve messy matching and whatnot?

say I have pSphere1.vtx[0], pSphere1.vtx[1] and pCylinder1.vtx[0] pCylinder1.vtx[1] selected.

How could I store
pSphere1.vtx[0] and pSphere1.vtx[1]
to one list and
pCylinder1.vtx[0] and pCylinder1.vtx[1] to another list?

You can't, because maya doesn't store the order of selection of components so you cannot know in what order the user selected them thuus you have NO idea what the combination will be. Or atleast sortof you can go agheda and parse the info form the undo queue. But thats hellofalot of much MORE messy parsing than you were thinking, and quite frankkly it has a very limitted scope. (if you ant this theres a script WAY back that does just this)

However theres a more natural way you can make a tool that saves the selection as you go and look at scriptCtx, offcourse the downside is that users need to select thet tool BEFRE they do the selection

hello good morning!

As I see he is not interested in the order, but in the belonging!
And if you checked Joojaa you'd have recognised: If you really select stuff on different shapes Maya DOES store the selection order for some obscure reason!

@combustible: don't think you will come past "messy" matching ;]
but it isn't that messy at all.
I don't know whats faster. You could either check the parent of each selected component, or dismember the string (e.g. to "pSphere1" and "vtx[0]")

The bigger problem (and old problem of mel too) is you'd have an arbitrary number of lists!

CODE
{
     string $sel[] = sort(ls -fl -sl);
     string $selShapes[] = stringArrayRemoveDuplicates(listRelatives -p);
     string $membershipArray[];
     int $countIndex = 0;
     int $thisMemberCount;
     int $allMembersCount = 0;
     // for each shape thats selected
     for ($shape in $selShapes)
     {
         // reserve spot for a new count
         $countIndex = $allMembersCount;
         $membershipArray[$allMembersCount++] = 0;
         // reset number of this components
         $thisMemberCount = 0;

         // browse all components
         for ($s in $sel)
         {
             // if its parent it the current shape sort it
             if (getArrayIndex0(listRelatives -p $s) == $shape)
             {
                 $membershipArray[$allMembersCount++] = $s;
                 $thisMemberCount++;
             }
         }

         // set the countIndex to the evaluated count
         $membershipArray[$countIndex] = $thisMemberCount;
     }

     // which group do you want? Set it here: 0-based!
     int $getGroup = 1;

     // get the full range for this group
     int $range[] = getRange $membershipArray $getGroup;

     // example printout
     print ("example for group number: " + $getGroup + "\n");
     for ($i = ($range[0] + 1); $i <= $range[1]; $i++)
         print("$membershipArray[$i]: " + $membershipArray[$i] + "\n");
}

proc int[] getRange(string $array[], int $group)
{
     int $range[1] = {0, (int) $array[0]};
     for ($loop = 0; $loop < $group; $loop++)
     {
         $range[0] = $range[1] + 1;
         $range[1] = $range[1] + (int) $array[$range[0]] + 1;
     }
     return $range;
}

proc string getArrayIndex0(string $array[])
{
     return $array[0];
}

QUOTE
And if you checked Joojaa you'd have recognised: If you really select stuff on different shapes Maya DOES store the selection order for some obscure reason!

It does, blimey. Talk about not being consequent. But alas it dont work perfectly! it appears to:

make 2 cubes.

QUOTE
file -f -new;
polyCube;
polyCube;
select -r pCube2.vtx[2] ;
select -tgl pCube1.vtx[3] ;
select -tgl pCube2.vtx[1] ;
select -tgl pCube1.vtx[2] ;
ls -sl;

so far so good but

QUOTE
file -f -new;
polyCube;
polyCube;
select -r pCube2.vtx[2] ;
select -tgl pCube1.vtx[3] ;
select -tgl pCube1.vtx[1] ;
select -tgl pCube2.vtx[4] ;
ls -sl;

The shit craps up so the store token is the change of object, but the order goes totaly haywire. So unless it truly interleaves its going to be broken anyway. Code not to be trusted.

QUOTE
The bigger problem (and old problem of mel too) is you'd have an arbitrary number of lists!

But in that case its rather simple, What you have is a interleave wich to all effect is a 2 dimensional array. (but )

And managing that interleave is rather simple
CODE
for ($i=0;$i<length($list);$i=$i+2){
  $newlist={$list[$i],$list[$i+1]};
  //use this list in this block next time around its the next list.
}

if not tricky or you could use soemthing like

CODE
global proc string getInterleave(string $list[],int $i){
  if (size($list)<$i*2+1) return {};
  return {$list[$i*2],$list[$i*2+1]};
}

if you need arbitrary access. So you could use something like:
CODE
$list1=getInterleave($list,0);
$list2=getInterleave($list,2);

And do something to the interleaved parts and then yoiu can reuse the lists in your code, if you need to update the main list make a

CODE
global proc string insertInterleave(string $list[],$newlist[],int $i){
  list[$i*2]=$newlist[0];
  list[$i*2+1]=$newlist[1];
}