2006-07-27

I know how to pick em: SelectSimilar routine

EDIT 4/6/2010: SelectSimilar has been present in vertical products such as AutoCAD Architecture, however, due to the popularity of this post, I'd like to note that in AutoCAD 2010, this command was included in a package of extra tools offered to subscription users, and in 2011, it is present in vanilla AutoCAD as a native command.

In MAP3D 2006 there is a tool, accessed by most via the right-click menu, called SelectSimilar.

Once you’ve selected an object(s), you use this command to add all other similar entities throughout the drawing to your selection set. (I believe this tool is also available in Architectural Desktop [ADT])

I’ve heard quite a buzz on the newsgroups from MAP users who’ve upgraded to 2007 and are disappointed to see that this command is no longer available in it’s current form. That made me upset, so I’d been keeping my eyes open to see if anyone had come up with a routine which will accomplish the same thing… even going so far as asking people if they knew what sorts of things a command like that would look at and could they write something up.

Well… I finally found that special someone who could help me! Adam Wuellner, whose acquaintance I made via the Autodesk Newsgroups. He has kindly allowed me permission to post his code here:
(edit: Adam updated his code, and I am posting the new in here 7/28/06)



;;; Select Similar
;;; (based on a command found in a few versions of AutoCAD)
;;; written by Adam Wuellner
;;; all rights released

;--------> MAIN ROUTINE
(defun c:selsim  (/ ss1 i ent filter_list type-layer filter sstemp)
  (if (not (setq ss1 (cadr (ssgetfirst))))
    (setq ss1 (ssget)))
  (setq i           0
        filter_list '())
  (repeat (sslength ss1)
    (setq ent (entget (ssname ss1 i))
          i   (1+ i))
    (setq type-layer (list (assoc 0 ent) (assoc 8 ent)))
    (if (not (member type-layer filter_list))
      (setq filter_list (cons type-layer filter_list))))
  (foreach filter  filter_list
    (princ (strcat "selecting all " (cdar filter) " entities on layer " (cdadr filter) "...\n"))
    (setq sstemp (ssget "X" filter))
    (setq ss1    (ss:union ss1 sstemp)
          sstemp nil))
  (sssetfirst nil ss1)
  (princ))

;--------> UNION
(defun ss:union  (ss1 ss2 / ename ss-smaller ss-larger c)
  (cond ((and ss1 ss2)
         (setq c 0)
         (if (< (sslength ss1) (sslength ss2))
           (setq ss-smaller ss1
                 ss-larger ss2)
           (setq ss-larger ss1
                 ss-smaller ss2))
         (while (< c (sslength ss-smaller))
           (setq ename (ssname ss-smaller c)
                 c     (1+ c))
           (if (not (ssmemb ename ss-larger))
             (ssadd ename ss-larger)))
         ss-larger)
        (ss1 ss1)
        (ss2 ss2)
        (t nil)))


I have used this with success in MAP2005 as well as 2006.


If you’re not sure how to use this code, here are the steps to take:

Copy the above code, paste into notepad, save as SelectSimilar.lsp into an appropriate location on your hard drive.

When in AutoCAD (whatever flavor) type APPLOAD at the command line, navigate to the .lsp file you’ve just created (while accessing APPLOAD look for the little briefcase icon, where you can set to have the routine load on startup).

Once the routine is loaded: select an object, then type ‘selsim’ to run.

Look for my next post on how to add this command to your right-click menu in AutoCAD 2005 and below.

10 comments:

Anonymous said...

I love select similar in ADT, mystified why it's not a core AutoCAD feature?

Would put ADT's object isolate/hide in the same category. Select Similar then isolate or hide eliminates need for lots of layer control when editing.

Mistress of the Dorkness said...

it is an awesome command and i'm mystified why it isn't in map07. ~shrug~ luckily it won't matter since i've got this routine now. it's too cool. 8)

object isolate? seems I saw a routine that would do that floating around somewhere... might have to look that up again and try it out.

Anonymous said...

Thank you! Thank you! Thank you!

Ward Romberger said...

Melanie,

You can format your code with the <pre> tag. Check out Toggling TILEMODE by way of example.

Mistress of the Dorkness said...

ward, thanks for the tip, I'll go back and try that when I get home tonight.

Anonymous said...

I'm getting this error message:

; error: no function definition: SS:UNION

any idea why?



-curious student

Adam said...

@anonymous -

The code for the helper function SS:UNION got a little mangled. Melanie said she'd try and fix it, but in the meantime, here is the complete code for SS:UNION...

(defun ss:union (ss1 ss2 / ename ss-smaller ss-larger c)
(cond ((and ss1 ss2)
(setq c 0)
(if (< (sslength ss1) (sslength ss2))
(setq ss-smaller ss1
ss-larger ss2)
(setq ss-larger ss1
ss-smaller ss2))
(while (< c (sslength ss-smaller))
(setq ename (ssname ss-smaller c)
c (1+ c))
(if (not (ssmemb ename ss-larger))
(ssadd ename ss-larger)))
ss-larger)
(ss1 ss1)
(ss2 ss2)
(t nil)))

- Adam W.

holy s**t said...

i am so glad i found this site.
i have been needing select simuar badly,
this was so helpful, thank you!!

-ash

Imad Habash said...

Thank you Melanie it's nice article and for you adam..

Mistress of the Dorkness said...

If you'd like to try a different iteration of a similar tool, you can download here:

http://caddons.svn.sourceforge.net/viewvc/caddons/General/selsim.lsp?revision=64&view=markup