Jump to content

Recommended Posts

Posted

I have a work routine that LeeMac cleaned up for me back in 2010.
It began as a way to highlight certain Inserts or Block References.
I have modified a copy to accept a user input, which highlights an attribute region based on the Object Type entry in its block definition.
The tag is OBJTYPE, and the entry could be EQ, PP, LDB and many, many more. There are typically several, sometimes dozens, of each scattered about the drawing, and this routine helps locate all of a specific Object Type quickly.

What I can't seem to figure out is how to modify this thing so that if the Object Type being searched for does not exist in the drawing, Alert Box to inform the user. Not a print to the command line, but an Alert Box.
Currently, if an Object type does not exist, the program just quits without drama.
That's okay, but I'd like to eliminate the delays caused by searching bit-by-bit across some very large drawings, and just tell the user there are none of what's being searched for.
Any help or hints would be appreciated and I uploaded a drawing (2010 format) with some regions if you're game.

Thanks,
Steve

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Original by LeeMac @ cadtutor.net 16 NOV 2010
;; So long ago the saved link is broken.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Mod by SteveJ July 2022 to highlight all of specified OBJ TYPE.

(defun c:OBJ (/ ot ss attLst Box ul lr)
  (vl-load-com)

  (setq ot (strcase (getstring "Enter OBJ TYPE to locate: ")))

  (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
    (progn
      (command "regen");erases current highlighting for next search.
      (foreach Obj (mapcar 'vlax-ename->vla-object
                     (mapcar 'cadr (ssnamex ss)))
        (setq attLst nil)
        (foreach att (vlax-safearray->list
                       (vlax-variant-value
                         (vla-getAttributes Obj)))
          (setq attLst (cons (cons (vla-get-TagString att)
                                   (vla-get-TextString att)) attLst)))
        (if (and (assoc "OBJTYPE" attLst)
                 (eq ot (cdr (assoc "OBJTYPE" attLst)))
                 (setq Box (assoc "BOXSIZE" attLst)
                       Box (read (cdr Box))))
          (progn
            (setq ul (list (car Box) (cadr Box))
                  lr (list (caddr Box) (cadddr Box)))
            (grvecs (list 1 lr (list (car lr) (cadr ul)) ;RIGHT
                          1 ul (list (car lr) (cadr ul)) ;TOP
                          1 lr (list (car ul) (cadr lr)) ;BOTTOM
                          1 ul (list (car ul) (cadr lr)) ;LEFT
					))))))
    (princ "\n<!> No Attributed Blocks Found <!>"))
  (princ))


;;
;;(alert "No Such Animal")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

OBJ_TYPE.dwg

Posted (edited)

Simple enough Added a counter. If you don't like/want the found message just delete the 2nd alert line in the last if statement.

 

Alert.png.e31f44f119c970091786df68500b4c42.png

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Original by LeeMac @ cadtutor.net 16 NOV 2010
;; So long ago the saved link is broken.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Mod by SteveJ July 2022 to highlight all of specified OBJ TYPE.
(defun c:OBJ (/ i ot ss attLst Box ul lr)
  (vl-load-com)
  (setq i 0) ;added line
  (setq ot (strcase (getstring "Enter OBJ TYPE to locate: ")))
  (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
    (progn
      (command "regen")  ;erases current highlighting for next search.
      (foreach Obj (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))
        (setq attLst nil)
        (foreach att (vlax-safearray->list (vlax-variant-value (vla-getAttributes Obj)))
          (setq attLst (cons (cons (vla-get-TagString att) (vla-get-TextString att)) attLst))
        )
        (if (and (assoc "OBJTYPE" attLst)
                 (eq ot (cdr (assoc "OBJTYPE" attLst)))
                 (setq Box (assoc "BOXSIZE" attLst)
                       Box (read (cdr Box))
                 )
            )
          (progn
            (setq ul (list (car Box) (cadr Box))
                  lr (list (caddr Box) (cadddr Box))
            )
            (grvecs (list 1 lr (list (car lr) (cadr ul))  ;RIGHT
                          1 ul (list (car lr) (cadr ul))  ;TOP
                          1 lr (list (car ul) (cadr lr))  ;BOTTOM
                          1 ul (list (car ul) (cadr lr))  ;LEFT
                    )
            )
            (setq i (1+ i)) ;added line
          )          
        )
      )
    )
    (princ "\n<!> No Attributed Blocks Found <!>")
  )
  (if (eq i 0) ;added if statement
    (alert (strcat "No Attributed Blocks Found With Object Type \"" ot "\""))
    (alert (strcat "Found " (itoa i) " Attributed Blocks With Object Type \"" ot "\""))
  )
  (princ)
)

 

Edited by mhupp
marked all added lines of code
  • Thanks 1
Posted

Wow. What a treat to see how you solved this.

I was expecting something a bit more complicated, but your solution is easy to see and comprehend.

Thanks for such an elegant solution.

 

Steve

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...