January 18, 2017

AutoLISP: Selecting-Gripping Objects by Handle

The AutoCAD® Architecture SHOWDISPLAYOVERRIDES command is a great way to find objects that have a style- or object-level display override associated with them. At least, in a relatively small file it is. Running the command allows you to select either type of override or both, and it will list the objects at the command line as well as highlight them in the drawing canvas. If your drawing extents are fairly tight, you may be able to start zoomed all of the way out and still see the highlighted objects. But if your drawing extents are larger, then it will be hard to see the highlighting when zoomed out. Unfortunately, the command does not actually select the items, or activate the grips on them. You can use the mouse wheel to zoom in afterwards without losing the highlights, but unless you know where to look, that can be frustrating.

The command line output lists the Display Representation with the override, the override type, the object type and the handle of the object for object-based overrides or the handle of the style for style-based overrides.
Command: SHOWDISPLAYOVERRIDES
Show Display Overrides [byObject/byStyle/Both]: b
Massing Element Display Representation Plan High Detail Object based override found on Mass Element ("460F")
Massing Element Display Representation Plan High Detail Style based override found on Mass Element Style "Standard (2)" ("461C")
Massing Element Display Representation Plan High Detail Object based override found on Mass Element ("4733")
Massing Element Display Representation Plan High Detail Object based override found on Mass Element ("4737")

I wrote a quick AutoLISP® routine that will allow me to type in the handles given for the object-based overrides, that will then select and grip these objects. Provided you do not exceed the maximum number of objects for which AutoCAD will show grips at one time (GRIPOBJLIMIT system variable), you should be able to see where the objects that have been gripped are, even when zoomed out. Please note that you should NOT enter the handle of a Style-based override, as there is no graphical object which can be gripped in that case, and the SSFIRSTSET function will throw an error and crash the routine. A test for that could be added, prior to adding the entity to the selection set, but given the manual nature of entering the handles, I did not think that was necessary here.
(defun C:SELHAND (   ; No arguments.
    / ;_ Local variables:
    ename   ; Entity name of object with entered handle [entity name].
    sHand   ; User entered string of object handle [string].
    ss1   ; Selection set of objects whose handles were entered [selection set].
    ) ;_ End arguments and local variables.
  (setq ss1 (ssadd))   ; Initialize ss1 as an empty selection set.
  ;; Ask user for handle strings, until a null response is received.
  (while (/= "" (setq sHand (getstring "\nEnter handle string: ")))
    (setq ename (handent sHand)) ; Try to get entity name from handle string.
    (if ename    ; If an entity was found...
      (setq ss1 (ssadd ename ss1)) ; ...add entity to selection set.
      (prompt    ; ...else, report failure to find object.
 (strcat
   "\nNo entity with handle -->"
   sHand
   "<-- found. "
 ) ;_ End strcat.
      ) ;_ End prompt.
    ) ;_ End if.
  ) ;_ End while.
  (if (> (sslength ss1) 0)  ; If at least one valid handle was entered...
    (sssetfirst nil ss1)  ; ...select item(s), turning on grips.
    (prompt "\nNo valid handles entered.  Nothing to do! ")
     ; ...else, notify user.
  ) ;_ End if.
  (prin1)
) ;_ End C:SELHAND.

No comments: