Saturday, October 9, 2010

MEL: Select Similar Objects

So here 's small script which will select similar Polygon objects in a maya Scene: Just select the base object and execute the script, and viola, all similar objects are selected for you. This is specially useful for large scenes.
  1. int $c = 1;
  2. global proc SelSimObj(string $every)
  3. {
  4. int $c = 1;
  5. string $every = $every;
  6. int $sel[3] = `polyEvaluate -v -e -f $every`;
  7. string $b[] = `ls -typ mesh`;
  8. for ($each in $b)
  9. {
  10. int $counter[3] = `polyEvaluate -v -e -f $each`;
  11. if ($counter[0] == $sel[0] && $counter[1] == $sel[1] && $counter[2] == $sel[2]){
  12. select -add $each;
  13. clear $counter;
  14. };

  15. };
  16. clear $sel;
  17. clear $b;

  18. }

  19. string $SelList[] = `ls -dag -typ "mesh" -sl`;
  20. for($every in $SelList)
  21. SelSimObj ($every);
  22. clear $SelList;

3 comments:

  1. Hi there,

    Just wanted to point out two things in your script.

    First: This script is dangerous in big scenes because it doesn't select similar objects, it selects objects with the same number of vertices, edges and faces, which are not necessarily similar objects.

    Second: your last object is selected twice, so if you transform it, it transforms double.

    I wrote a similar script called he_selectSimilar and it is on creative crash. Take a look at it. It selects similar objects based on the number of vertices AND the area of the geometry. You can download it here: http://www.creativecrash.com/maya/downloads/scripts-plugins/polygon/c/he_selectsimilar

    I hope that was helpful.

    All the best,

    Hesham Eissa

    ReplyDelete
  2. both scripts are useful to me. I used the first to select objects with similar topology, the later to select duplicate objects before batch transfer UVs with AJ UV

    ReplyDelete
  3. Thanks so much for this script, i realy need this script thank you

    ReplyDelete