Jump to content

Recommended Posts

Posted

I have a lisp routine here and it is works great for searching for a specific value of an attribute if that attribute is in the drawing. Is there a way to make this search the xrefs that are overlayed in the main drawing file as well as the main drawing?

 

 
(defun c:fatt (/ ov ss i en ed an ad ah)
 (while (not ov)
        (setq ov (getstring t "\nATTRIB Value To Search For:   ")))
 (and (setq ss (ssget "X" (list (cons 0 "INSERT")
                                (cons 66 1)
                                (if (getvar "CTAB")
                                    (cons 410 (getvar "CTAB"))
                                    (cons 67 (- 1 (getvar "TILEMODE")))))))
      (setq i (sslength ss))
      (while (not (minusp (setq i (1- i))))
             (setq en (ssname ss i)
                   ed (entget en)
                   an (entnext en))
             (while (/= "SEQEND" (cdr (assoc 0 (entget an))))
                    (setq ad (entget an)
                          ah (cdr (assoc 40 ad))
                          an (entnext an))
                    (if (= (strcase ov)
                           (strcase (cdr (assoc 1 ad))))
                        (progn
                           (command "_.ZOOM" "_C" (cdr (assoc 10 ed)) (* ah 66))
                           ;(redraw en 3)
                           (getstring "\nPress Enter To Continue Searching..."))))))
 ;(redraw)
 (prin1))

Posted

Nobody wants to take a stab at this? Does anyone know if it is even possible?

Posted

Hi,

 

(ssget "X" (list (cons 0 "INSERT")...

Is piece of the code that searches the current drawing for all blocks.

 

If a block is in an Xref, the "ssget" function does not work. The blocks with its attributes are nested therefore you must use the "nentsel" function. And that works only on a selection of 1 entity.

 

How to solve this is a riddle to me for I have tried to find a solution myself often.

 

If others out there have a solution or if I am totally mistaken here, please comment.

Posted

I made a start, just searching the block definition, not sure if it helps at all.

 

(defun c:Find_Att (/ itemp getname getnestattribblocks BLKS BLOCK ENT I LST NLST SS TMP)
 ;; Lee Mac  ~  23.03.10

 (setq *str (strcase
              (cond ((/= "" (setq tmp (getstring t "\nATTRIB Value to Search For: "))) tmp)
                    (*str))))
 

 (defun itemp (collection item / result)
   (if (not (vl-catch-all-error-p
              (setq result
                     (vl-catch-all-apply (function vla-item)
                       (list collection item)))))
     result))


 (defun GetName (object)
   (if (vlax-property-available-p object 'EffectiveName)
     (vla-get-EffectiveName object)
     (vla-get-name Object)))
 
 
 (defun GetNestAttribBlocks (object / result sub)
   
   (setq blks (cond (blks) ((vla-get-Blocks
                              (vla-get-ActiveDocument
                                (vlax-get-acad-object))))))
   
   (vlax-for sub object
     (if (and (eq "AcDbBlockReference" (vla-get-ObjectName sub))
              (eq :vlax-true (vla-get-hasAttributes sub)))
       (setq result (cons sub (GetNestAttribBlocks (itemp blks (GetName sub)))))))
   
   result)


 (if (setq i -1 ss (ssget "_X" (list (cons 0 "INSERT")
                                     (cons 66 1)
                                     (cons 410 (getvar 'CTAB)))))
   
   (while (setq ent (ssname ss (setq i (1+ i))))
     (setq bName (cdr (assoc 2 (entget ent))))                 
     
     (while (/= "SEQEND" (cdr (assoc 0 (entget (setq ent (entnext ent))))))
       
       (if (eq *str (strcase (cdr (assoc 1 (entget ent)))))
         
         (setq Lst (cons (cons bName ent) Lst))))))
 

 (vlax-for block (vla-get-Blocks
                   (vla-get-ActiveDocument (vlax-get-acad-object)))
    
   (setq nLst
     (cons
       (apply (function append)
              (mapcar
                (function
                  (lambda (block)
                    (vl-remove 'nil
                      (mapcar
                        (function
                          (lambda (attrib)
                            (if (eq (strcase (vla-get-TextString attrib)) *str)
                              (cons (GetName block) (vlax-vla-object->ename attrib)))))
                        
                        (vlax-invoke block 'GetAttributes)))))
                
                (GetNestAttribBlocks block)))
         
     nLst)))

 (print (vl-remove 'nil (apply (function append) nLst)))
 (princ))

 

 

Posted

Thanks guys for replying. Lee Mac, I can't get this to work with a block that is in the drawing or in an xref. I am thinking along the lines of AutoCad's "Find" command. It has the capabilities to do what I want, but the regeneration process takes way too long on the size files I deal with. The lisp I posted regenerates a lot faster, it just isn't searching in the xref for the attribute.

Posted

ksperopoulos,

 

The posted code will only print a list of Block Names and the entity name of the attribute in which it appears - it is only a start, and would need much refinement.

Posted

Sorry, I must have misunderstood before. I do not know how to write lisp routines and know very little how to manipulate them. I thought maybe someone already may have encountered this before and had something they would be willing to share.

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