Jump to content

Recommended Posts

Posted

Hi,

 

Any chance someone can help me with a lisp code on zooming in to a specific attribute tag in a block? There's only one instance of the block in every tab and that block contains multiple attributes.  I saw some codes about zooming to attribute values but not to a tag.  

 

Thanks.

Posted (edited)

Hi,

Something like this?

(defun c:Test (/ tag int sel ent vla zom lft rgt)
 (setq tag "YourTag") ;; tag name.
 (if (and (setq tag (strcase tag) int -1 sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'CTAB)))))
          (progn
            (while (and (setq ent (ssname sel (setq int (1+ int))))
                        (setq vla (vlax-ename->vla-object ent))
                        (not (vl-some '(lambda (x)
                                         (and (= (strcase (vla-get-tagstring x)) tag)
                                              (setq zom vla)
                                              )
                                         )
                                      (vlax-invoke vla 'getattributes)
                                      )
                             )
                        )
              )
            (if zom (progn (vla-getboundingbox zom 'lft 'rgt) t)))
          )
   (vla-ZoomWindow (vlax-get-acad-object) lft rgt)
   (alert "No tag string found!")
   )
  (princ)
) (vl-load-com)

 

Edited by Tharwat
Posted

Many thanks  Tharwat for responding to my query.  I just tested it and it's zooming to the extent of the block where the tag resides.  Is it possible to make it zoom in only to the tag string

Posted

You should be able to get at the attributes properties this is a test code.

 


(setq atts (vlax-invoke (vlax-ename->vla-object (car (entsel "\nPick block attribute")))'getattributes))
(foreach att atts
(princ (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint att)))) ; multi points should appear
)

 

 

Tharwat has written good code and it would be best for him to add your specific request as a slightly different version. For me finding the block should be good enough.

Posted (edited)

Beautifull code indeed!

 

about the request , all OP has to do is change (setq zom vla) to (setq zom x) ... somewhere in the middle of the code

 

p.s. assuming TAG has a boundingbox (isn't empty) else you would need a zoom center on its insertion point or zoom to the block anyway (untested) :


(defun c:Test2 (/ tag int sel ent vla zom lft rgt)
 (setq tag "YourTagname") ;; tag name or replace with getstring (setq tag (getstring "\nEnter tagname to search for : "))
 (if (and (setq tag (strcase tag) int -1 sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'CTAB)))))
          (progn
            (while (and (setq ent (ssname sel (setq int (1+ int))))
                        (setq vla (vlax-ename->vla-object ent))
                        (not (vl-some '(lambda (x) (and (= (strcase (vla-get-tagstring x)) tag)(setq zom x)))
                                       (vlax-invoke vla 'getattributes)))))
            (and zom ;if tagname was found, and it has boundingbox , use it , else use block boundingbox
              (or (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list zom 'lft 'rgt))))
                  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list vla 'lft 'rgt))))))))
   (vla-ZoomWindow (vlax-get-acad-object) lft rgt)  (alert (strcat "Tagstring " tag " not found")))
  (princ)
)

Edited by rlx
Posted (edited)

Zoom C Scale on the tag insertion position but need to know the scale factor maybe still use bounding box with a fuzz factor say 1/4 box size for scale value

Edited by BIGAL
Posted

Thanks very much Thartwat, Bigal & rlx for all your help.  Greatly appreciated.

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...