Jump to content

Zoom to Block with Unique Attribute Value


Recommended Posts

Posted

I have a block that when I insert it into the drawing, it has an attribute that prompts me to enter a number. I usually have a lot of these blocks inserted into the drawing, all with different values. Having a search command to help me locate any one of these blocks would save me a lot of time that I usually use for visually hunting them down. I would like to know if there is a way to have a command that prompts you to enter the value entered for the attribute of that block and when the command finds that block with the unique value, it will zoom to that block. Can anyone help me with this? I have no experience creating lisp routines.

Posted

It can be done in simple terms just need name of block create a list of all of the singular block name then go through list checking attribute value once found return insert point then zoom point etc

 

I can give you example Vba code for searching blocks and find the one single answer any where in a drawing (are blocks only in model space makes it easier ?) I dont have insert point but some one here would supply that bit.

 

(search forum here BIGAL I have already pasted the code elsewhere a couple of times)

Posted

Just use autocads find program (go to edit then find)

In the dialog box, enter the attribute value in the ”find text string box”

Leave the replace box empty

Click on the options button next to the replace box and only check “block attribute value”

And click ok. (it will remember the settings)

Click the find button and it will list all blocks with that value

Click the zoom button and there you are.

Posted

Thanks to you both. I didn't even know about the find command. That works perfectly for me. I may have to pursue the route that BIGAL suggested if I need to have a search for different blocks with the same values though. But for now, we are only searching our drawings for this one block and they all have different values, so it makes it real easy. It will even allow you to search for the block in xrefs. FYI - it automatically zooms to the block after I enter the value of the attribute.

Posted

Here is pretty generic rotuine that will search and zoom in for ATTRIButes in INSERTs in the current tab.

 

[b][color=BLACK]([/color][/b]defun c:find-att [b][color=FUCHSIA]([/color][/b]/ ov ss i en ed an ad ah[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not ov[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq ov [b][color=MAROON]([/color][/b]getstring t [color=#2f4f4f]"\nATTRIB Value To Search For:   "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][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]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b]
                                [b][color=BLUE]([/color][/b]cons 66 1[b][color=BLUE])[/color][/b]
                                [b][color=BLUE]([/color][/b]if [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=RED])[/color][/b]
                                    [b][color=RED]([/color][/b]cons 410 [b][color=PURPLE]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                                    [b][color=RED]([/color][/b]cons 67 [b][color=PURPLE]([/color][/b]- 1 [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"TILEMODE"[/color][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][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]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [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=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b]
                   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][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 [b][color=PURPLE]([/color][/b]entget an[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b]
                          ah [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 40 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                          an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]strcase ov[b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]strcase [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 1 ad[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                        [b][color=BLUE]([/color][/b]progn
                           [b][color=RED]([/color][/b]command [color=#2f4f4f]"_.ZOOM"[/color] [color=#2f4f4f]"_C"[/color] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 10 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]* ah 66[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]redraw en 3[b][color=RED])[/color][/b]
                           [b][color=RED]([/color][/b]getstring [color=#2f4f4f]"\nPress Enter To Continue Searching..."[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][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]redraw[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

Posted

Thanks David. I tried the lisp and after I type in the text, the prompt "Press Enter to Continue Searching" pops up. I press enter, but the command closes out. Any ideas why and is there a way to make this not actually select the block? Selecting the block forces me to hit the escape key to deselect it. I am just using this command to view the area, not continue with another command. Thanks again.

Posted

This will prevent the highlighting, but the "Enter" prompt seems to work fine.

 

(defun c:find-att (/ 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

This is great and it works much faster than the AutoCad find command. But, is there a way to make this search inside xrefs as well?

Posted

Could the enter command on my end be affected by my right-click preferences?

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