Jump to content

Find attrubutes in a block/s


ketongin

Recommended Posts

I would like ask if you cad gurus has a code on finding attributes. I'm new to lisp so I don't know where to start.

 

I would like to search for 2 attributes in a blocks or blocks. Some thing like this:

 

"Enter 1st attribute to search :" ....

"Enter 2nd attribute to search :" ...

 

Routine will search for all blocks in the drawing which has those 2 attributes in a block and zoom in to the block with the same viewsize (variable) before the lisp is executed and stop on every block which have those strings until the end of the list or user press escape.

Link to comment
Share on other sites

Find Blocks where two specific tags are present?

or the blocks doesnt necessarily have just 2 attributes as long as the both tags are present on that block?

 

Zoom into the location and prompt for Editing?

 

Try this:

(defun FindTagEdit ( Tag1 Tag2 / dcledit TagVal a b c TagCheck blk str)
;;;       pBe 29July2011  ;;;
(vl-load-com)      
(defun dcledit (txt / attlist NewTxt ddatt_dcl)
   (and
     (setq oldtxt txt
           dcl    (load_dialog "ACAD")
     )
     (new_dialog "acad_txtedit" dcl)
     (set_tile "text_edit" txt)
     (action_tile "text_edit" "(setq txt $value)")
     (action_tile "cancel" "(setq txt oldtxt)")
     (start_dialog)
     (unload_dialog dcl)
   )
   txt
 )
(defun TagVal  (ent nme)
     (mapcar '(lambda (j)
                    (vl-list* (vla-get-tagstring j) j))
             (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes)
             )
     )      
(cond ((and 
(while
     (setq a (tblnext "BLOCK" (null a)))
          (if (equal '(70 . 2) (assoc 70 a))
                (setq b (cons (cdr (assoc 2 a)) b)
                      )))
(foreach
      AtBlk  b
     (if (setq c (ssget "_X"
                        (list (cons 2 AtBlk)
                              (cons 410 (getvar 'CTAB)))))
           (progn
                 (setq TagCheck
                            (mapcar 'car
                                    (Tagval (ssname c 0) AtBlk)))
                 (if (and (member Tag1 TagCheck)
                          (member Tag2 TagCheck))
                       (repeat (sslength c)
                             (vla-getboundingbox
                                   (
                                    vlax-ename->vla-object
                                         (setq blk
                                                    (ssname c 0)))
                                   'LL
                                   'UR)
                             (vla-ZoomWindow
                                   (vlax-get-acad-object)
                                   ll
                                   ur)
                             (foreach
                                    Tag  (list Tag1 Tag2)
                                   (vla-put-textstring
                                         (setq str  (cdr  (assoc
                                                                tag
                                                                (Tagval blk AtBlk)
                                                                )))
                                         (dcledit
                                               (vla-get-textstring
                                                     str)))
                                   )
                             (setq c (ssdel blk c)))))
                                   )
                             )
                     )
                 )
         )
     (princ)
     )

 

Usage:

(FindTagEdit "Tagname1" Tagname2")

Link to comment
Share on other sites

I'd try something like this:

 

[b][color=BLACK]([/color][/b]defun c:findmatt [b][color=FUCHSIA]([/color][/b]/ i tn tl en ed an ad ss[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq i 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not tn[b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]/= tn [color=#2f4f4f]""[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq tn
          [b][color=MAROON]([/color][/b]strcase
            [b][color=GREEN]([/color][/b]getstring
              [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"\nTag "[/color] [b][color=RED]([/color][/b]itoa i[b][color=RED])[/color][/b] [color=#2f4f4f]" To Serach [b][color=RED]([/color][/b] Enter To Exit [b][color=RED])[/color][/b]:  "[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]/= tn [color=#2f4f4f]""[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]setq tl [b][color=GREEN]([/color][/b]cons tn tl[b][color=GREEN])[/color][/b]
                   i [b][color=GREEN]([/color][/b]1+ i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearching For Tagnames: "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1 tl[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b]
                   i 0[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]/= [color=#2f4f4f]"SEQEND"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]member [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 2 ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] tl[b][color=BLUE])[/color][/b]
                        [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= i [b][color=BLUE]([/color][/b]length tl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]progn
                   [b][color=BLUE]([/color][/b]command [color=#2f4f4f]"_.ZOOM"[/color] [color=#2f4f4f]"_C"[/color] [b][color=RED]([/color][/b]trans [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 10 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] en 1[b][color=RED])[/color][/b] [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]redraw en 3[b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]getstring [b][color=RED]([/color][/b]strcat [color=#2f4f4f]"\n"[/color] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                      [color=#2f4f4f]" Press Enter To Continue..."[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearch Complete   "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

Hopefully, the blocks and inserts are made without duplicate tagnames in a single definition.

 

-David

Edited by David Bethel
Fixed (itoa i) strcat
Link to comment
Share on other sites

Nice David,

 

in my post. I think i zoomed in too much that you cant see the entities sorrounding the block

your approach is better

 

 

BTW:

(strcat "\nTag[b][color=blue] "[/color][/b] (itoa i) [color=blue][b]" [/b][/color]To Serach ( Enter To Exit ):  ")

Link to comment
Share on other sites

Nice David,

 

BTW:

(strcat "\nTag[b][color=blue] "[/color][/b] (itoa i) [color=blue][b]" [/b][/color]To Serach ( Enter To Exit ):  ")

 

Good Catch Thanks!

 

I'm not real proficient at reading VL code. It looks like your were doing a bounding box to zoom to. I would have thought that would have worked. -David

Link to comment
Share on other sites

Thanks for the code but for some reason I don't know how to call the command on PBE. I'm getting an error.

 

I like David's code but can it just find the blocks without selecting object and my blocks have more that 2 attributes, usually 4 or 6. Below is what I use for quite some time now and I love it. The only thing about it is when I'm looking for an attribute is I have to go with all the blocks one by one until I find the right one. I think this code is also written by David.

 

If I want to find "VAV" and "M2". It will automatically zoom it that block. With this code I would have to step thru with all the VAV until I find VAV M2.

 

(defun c:find2 (/ ov ss i en ed an ad)
 (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)
                    ad (entget an))
              (while (/= "SEQEND" (cdr (assoc 0 ad)))
                     (if (= (strcase ov)
                            (strcase (cdr (assoc 1 ad))))
                         (progn
                            (command "_.ZOOM" "_C" (cdr (assoc 10 ed)) "")
                            (getstring "\nPress Enter To Continue Searching...")))
                     (setq an (entnext an)
                           ad (entget an)))))
 (prin1))

Link to comment
Share on other sites

This should search all INSERTs and Zoom on those that contain both "VAV" & "M2":

 

[b][color=BLACK]([/color][/b]defun c:findkatt [b][color=FUCHSIA]([/color][/b]/ i tl en ed an ad ss[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq tl '[b][color=NAVY]([/color][/b][color=#2f4f4f]"VAV"[/color] [color=#2f4f4f]"M2"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearching For Tagnames: "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1 tl[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b]
                   i 0[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]/= [color=#2f4f4f]"SEQEND"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]member [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 2 ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] tl[b][color=BLUE])[/color][/b]
                        [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= i [b][color=BLUE]([/color][/b]length tl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]progn
                   [b][color=BLUE]([/color][/b]command [color=#2f4f4f]"_.ZOOM"[/color] [color=#2f4f4f]"_C"[/color] [b][color=RED]([/color][/b]trans [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 10 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] en 1[b][color=RED])[/color][/b] [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]redraw en 3[b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]getstring [b][color=RED]([/color][/b]strcat [color=#2f4f4f]"\n"[/color] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                      [color=#2f4f4f]" Press Enter To Continue..."[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearch Complete   "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

Manipulate the list 'tl for different tagnames. In the previous routine, you can simply say "_All" to the selection query. It should filter out INSERTs accordingly.

 

-David

Link to comment
Share on other sites

I tried it several times different drawings but it didn't work. Any idea?

 

This should search all INSERTs and Zoom on those that contain both "VAV" & "M2":

 

[b][color=BLACK]([/color][/b]defun c:findkatt [b][color=FUCHSIA]([/color][/b]/ i tl en ed an ad ss[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq tl '[b][color=NAVY]([/color][/b][color=#2f4f4f]"VAV"[/color] [color=#2f4f4f]"M2"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearching For Tagnames: "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1 tl[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b]
                   i 0[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]/= [color=#2f4f4f]"SEQEND"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]member [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 2 ad[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] tl[b][color=BLUE])[/color][/b]
                        [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= i [b][color=BLUE]([/color][/b]length tl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]progn
                   [b][color=BLUE]([/color][/b]command [color=#2f4f4f]"_.ZOOM"[/color] [color=#2f4f4f]"_C"[/color] [b][color=RED]([/color][/b]trans [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 10 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] en 1[b][color=RED])[/color][/b] [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]redraw en 3[b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]getstring [b][color=RED]([/color][/b]strcat [color=#2f4f4f]"\n"[/color] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                      [color=#2f4f4f]" Press Enter To Continue..."[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearch Complete   "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

Manipulate the list 'tl for different tagnames. In the previous routine, you can simply say "_All" to the selection query. It should filter out INSERTs accordingly.

 

-David

Link to comment
Share on other sites

They are attributes. I'm looking for something like in post #6 but will find 2 attributes in a block.

 

To be specific I have a block with 2 , 4 or 6 attributes. They serve as my equipment tag.

The one that you coded in post no 6 is a good one but I need to press enter each time until I find a block with a "VAV" attribute on it. So now I'm looking for one that can find both attributes in a block so it will automatically zoom on to it or to the next if there are more than one block with the same attributes. Try the code posted on post #6 to better understand my request. Sorry for my poor english, it's not my native language. Thanks David for your time, I really appreciate it.

 

Are VAV ans M2 Tagnames or block names?

FIND.jpg

Link to comment
Share on other sites

A quick modification of David's routine to search attribute values:

 

(defun c:findkatt (/ i tl en ed an ad ss)

 (setq tl '("VAV" "M2"))
 (princ "\nSearching For Tagnames: ")
 (prin1 tl)

 (and (setq ss (ssget "X" '((0 . "INSERT")(66 . 1))))
      (while (setq en (ssname ss 0))
             (setq ed (entget en)
                   an (entnext en)
                   ad (entget an)
                   i 0)
             (while (/= "SEQEND" (cdr (assoc 0 ad)))
                    (if (member (strcase (cdr (assoc 1 ad))) tl)
                        (setq i (1+ i)))
                    (setq an (entnext an)
                          ad (entget an)))
             (if (= i (length tl))
                 (progn
                   (command "_.ZOOM" "_C" (trans (cdr (assoc 10 ed)) en 1) "")
                   (redraw en 3)
                   (getstring (strcat "\n" (cdr (assoc 2 ed))
                                      " Press Enter To Continue..."))))
             (ssdel en ss)))
 (princ "\nSearch Complete   ")
 (redraw)
 (prin1))

Link to comment
Share on other sites

Yes Lee, that one has multiple occurrences also.

 

Maybe I'm stating the obvious, but can't you just search for 'M2', or does this have multiple occurrences too?
Link to comment
Share on other sites

Your almost there but VAV and M2 are not static. Both attributes have any values. VAV are equipment type and M2 are equipment number. VAv can be RTU, CEF, SP etc. and M2 can be A1 ,B2 C3 etc.

 

 

A quick modification of David's routine to search attribute values:

 

(defun c:findkatt (/ i tl en ed an ad ss)

 (setq tl '("VAV" "M2"))
 (princ "\nSearching For Tagnames: ")
 (prin1 tl)

 (and (setq ss (ssget "X" '((0 . "INSERT")(66 . 1))))
      (while (setq en (ssname ss 0))
             (setq ed (entget en)
                   an (entnext en)
                   ad (entget an)
                   i 0)
             (while (/= "SEQEND" (cdr (assoc 0 ad)))
                    (if (member (strcase (cdr (assoc 1 ad))) tl)
                        (setq i (1+ i)))
                    (setq an (entnext an)
                          ad (entget an)))
             (if (= i (length tl))
                 (progn
                   (command "_.ZOOM" "_C" (trans (cdr (assoc 10 ed)) en 1) "")
                   (redraw en 3)
                   (getstring (strcat "\n" (cdr (assoc 2 ed))
                                      " Press Enter To Continue..."))))
             (ssdel en ss)))
 (princ "\nSearch Complete   ")
 (redraw)
 (prin1))

 

 

I tried this one but it didn't work also

 

(defun c:findkatt (/ i tl en ed an ad ss unit unitno)

[color="blue"](setq unit (getstring "\n Enter unit type:  "))[/color]
[color="blue"](setq unitno (getstring "\n Enter unit type:  "))[/color]

 (setq tl '([color="blue"]unit[/color] [color="blue"]unitno[/color]))
 (princ "\nSearching For Tagnames: ")
 (prin1 tl)

 (and (setq ss (ssget "X" '((0 . "INSERT")(66 . 1))))
      (while (setq en (ssname ss 0))
             (setq ed (entget en)
                   an (entnext en)
                   ad (entget an)
                   i 0)
             (while (/= "SEQEND" (cdr (assoc 0 ad)))
                    (if (member (strcase (cdr (assoc 1 ad))) tl)
                        (setq i (1+ i)))
                    (setq an (entnext an)
                          ad (entget an)))
             (if (= i (length tl))
                 (progn
                   (command "_.ZOOM" "_C" (trans (cdr (assoc 10 ed)) en 1) "")
                   (redraw en 3)
                   (getstring (strcat "\n" (cdr (assoc 2 ed))
                                      " Press Enter To Continue..."))))
             (ssdel en ss)))
 (princ "\nSearch Complete   ")
 (redraw)
 (prin1))

Link to comment
Share on other sites

it looks like you are searching for attribute values, not tagnames:

 

[b][color=BLACK]([/color][/b]defun c:findmatv [b][color=FUCHSIA]([/color][/b]/ fl tl en ed an ad av ss[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq tl '[b][color=NAVY]([/color][/b][color=#2f4f4f]"VAV"[/color] [color=#2f4f4f]"M2"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearching For Attrib Values: "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1 tl[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                   an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b]
                   fl nil[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]/= [color=#2f4f4f]"SEQEND"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq av [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 1 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]member av tl[b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]not [b][color=RED]([/color][/b]member av fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                         [b][color=BLUE]([/color][/b]setq fl [b][color=RED]([/color][/b]cons av fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b]
                          ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= [b][color=BLUE]([/color][/b]length fl[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]length tl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]progn
                   [b][color=BLUE]([/color][/b]command [color=#2f4f4f]"_.ZOOM"[/color] [color=#2f4f4f]"_C"[/color] [b][color=RED]([/color][/b]trans [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 10 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] en 1[b][color=RED])[/color][/b] [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]redraw en 3[b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]getstring [b][color=RED]([/color][/b]strcat [color=#2f4f4f]"\n"[/color] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                      [color=#2f4f4f]" Press Enter To Continue..."[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSearch Complete   "[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

-David

Link to comment
Share on other sites

Thank you David and Lee. Appreciate your help. This is the one that I've been looking for. l learned a lot. Thanks again...

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