Jump to content

block selection by attribute value


Campa150

Recommended Posts

i'm pretty new to Autolisp so don't really know if this can be done with a lisp but here it goes.

i need a lisp that can select a block based on a attribute value, for example i have a drawing with a dozen blocks all with the same name "DFUBLANK1", this blocks have several attribute but i need to select only the block with the attribute tag "PART" with a value of "10". Any ideas?

Link to comment
Share on other sites

This is close not tested

 

; simple find block
; by Alan H nov 2013

(setq ans (getstring "\nEnter attribute value"))
(setq oldtag1 "yourattibute") ;attribute tag name
(setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "yourblockname")(410 . "Model"))) ; change block name
(setq inc (sslength ss1))
(repeat inc      
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc))) )'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(progn
(if (= ans (vla-get-textstring att ))
(progn  
(setq pt1 (vla-get-insertionpoint att))
(command "zoom" "c" pt1 100) ; zooms in on block
) ; end progn
) ; end if ans 
)); end if oldtag1
) ; foreach att
) ; end repeat
(princ)

Link to comment
Share on other sites

Welcome to CADTutor :)

 

Try this .

 

(defun c:Test (/ ss in sn en it ad ok)
 (if (setq ad (ssadd)
           ss (ssget "_X"
                     (list '(0 . "INSERT")
                           '(2 . "DFUBLANK1")
                           '(66 . 1)
                           (cons 410 (getvar 'CTAB))
                     )
              )
     )
   (repeat (setq in (sslength ss))
     (setq sn (ssname ss (setq in (1- in)))
           it sn
           ok nil
     )
     (while
       (and
         (not ok)
         (/= (cdr (assoc 0 (setq en (entget (setq sn (entnext sn))))))
             "SEQEND"
         )
       )
        (if (and (eq (strcase (cdr (assoc 2 en))) "PART")
                 (eq (cdr (assoc 1 en)) "10")
            )
          (setq ok t
                ad
                   (ssadd it ad)
          )
        )
     )
   )
 )
 (sssetfirst nil ad)
 (princ)
)

Link to comment
Share on other sites

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