Author Topic: Viewport zoom to specific attribute lisp... Anyone have?  (Read 3144 times)

0 Members and 1 Guest are viewing this topic.

T-Square

  • Guest
Viewport zoom to specific attribute lisp... Anyone have?
« on: September 18, 2009, 12:23:51 AM »
I have hundreds of layouts to create. I will basically have a layout tab for each room. Equipment check off type thing for each room. So, I have a lisp to create each layout tab based off of some attribute extraction of the room name block. I then take those room numbers from a tab delimited file(excel), then add the lisp code
Code: [Select]
(command "._layout" "_C" "F5-101" "H5-002")
Each one of those is a room I need to create a viewport for. The code above will create a tab with that room name, then all of the instances of the room on the sheet(layout) use an RTEXT to get the "ctab" value. What I would like to be able to do would be to automatically zoom to the attribute value of the room name block that matches the tab name and then zoom to a scale factor(zoom 1/48xp...type thing). I found a routine that works similar to the "Find", the zooming part. But neither one will allow you to zoom to an attribute value while inside the viewport from paperspace. Thus my dilema.

I have hundreds of these to do.

Any help is greatly appreciated.

I got the code below off the net somewhere. Credit to author.

Code: [Select]
(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))

T-Square

  • Guest
Re: Viewport zoom to specific attribute lisp... Anyone have?
« Reply #1 on: September 18, 2009, 12:37:10 AM »
Ok, so I found a zoom2txt lisp file.

What I can do is make a copy of all room name blocks in a different area and on a non plotting layer. Use express tools to explode the attributes to text. Then I could move the explode blocks with text back to the original location. Then use the zoom2txt routine to zoom to that text.

Round about way of doing it. But, it works.

However... again... I have hundreds of these to do and having an automated way of zooming to a text string or attribute based on the current "ctab" value would be most helpful. Especially if it could do the layout creation and viewport zooming to the current tab name. :-) Now that would be awesome.

Thanks again.

Code: [Select]
;;TIP    :  ZOOM2TXT.LSP (C)1993, Jeffrey R. Foster, Jr.
(defun c:zoom2txt (/ chgtxt zoompt1 zoompt2 sstxt sstxtlen txtent1 txtins dwgscal
                     pt1 pt3 num embed zoomnext txtent1 txtstyl txtlay txtinspt
                     txt_elev txt_height txt_rotate txt_obliq txt_width txt_color
     txt_2_chg txt_chg)
  (setq txt (getstring T "\nEnter text string to zoom to: "))
  (initget 1 "Y N")
  (setq embed (getkword "\nSearch for embedded strings? <Y or N>: "))
  (if (= embed "Y")
    (setq txt (strcat "*" txt "*"))
  )
  (setq zoompt1 (getvar "extmin"))
  (setq zoompt2 (getvar "extmax"))
  (setq search_list
    (list
      (cons 0 "text")
      (cons 1 txt)
    )
  )
  (if (/= (setq sstxt (ssget "X" search_list)) nil)
    (progn
      (setq sstxtlen (sslength sstxt))
      (alert (strcat "\nThere are " (itoa sstxtlen) " text entities meeting your criteria"))
      (setq
        txtent1 (entget (ssname sstxt 0))
        txtins (cdr (assoc '10 txtent1))
        dwgscal (getvar "ltscale")
        pt1 (list (- (car txtins) (* 1.0 dwgscal))
                  (- (cadr txtins) (* 1.0 dwgscal))
            )
        pt3 (list (+ (car txtins) (* 1.0 dwgscal))
                  (+ (cadr txtins) (* 1.0 dwgscal))
            )
      )
      (command "_zoom" "w" pt1 pt3)
      (initget 1 "T P N")
      (setq chgtxt (getkword "\nEdit Text, text Properties or Neither? <T P N>: "))
      (cond ((= chgtxt "T") (command "_ddedit" (ssname sstxt 0) ""))
            ((= chgtxt "P") (txt_prop))
            ((= chgtxt "N") (setq num 1))
      )
      (setq num 1)
      (if (> sstxtlen 1)
        (progn
          (initget 1 "Y N")
          (while (and (/= (setq zoomnext (getkword "\nZoom to next string? <Y or N>: ")) "N") (< num sstxtlen))
            (ssdel (ssname sstxt 0) sstxt)
            (setq
              txtent1 (entget (ssname sstxt 0))
              txtins (cdr (assoc '10 txtent1))
              dwgscal (getvar "ltscale")
              pt1 (list (- (car txtins) (* 1.0 dwgscal))
                        (- (cadr txtins) (* 1.0 dwgscal))
                  )
              pt3 (list (+ (car txtins) (* 1.0 dwgscal))
                        (+ (cadr txtins) (* 1.0 dwgscal))
                  )
            )
            (command "_zoom" "w" pt1 pt3)
            (initget 1 "T P N")
            (setq chgtxt (getkword "\nEdit Text, text Properties or Neither? <T P N>: "))
            (cond ((= chgtxt "T") (command "_ddedit" (ssname sstxt 0) ""))
                  ((= chgtxt "P") (txt_prop))
                  ((= chgtxt "N") (setq num 1))
            )
            (setq num (+ num 1))
            (initget 1 "Y N")
          )
        )
      )
      (command "_zoom" zoompt1 zoompt2)
    )
    (alert (strcat "\nThe text string ,"txt", does not exist in this drawing...  Sorry!!!"))
  )
)

(Defun txt_prop ()
  (setq
    txt_styl (cdr (assoc '7 (entget (ssname sstxt 0))))
    txt_lay (cdr (assoc '8 (entget (ssname sstxt 0))))
    txt_inspt (cdr (assoc '10 (entget (ssname sstxt 0))))
    txt_elev (cdr (assoc '38 (entget (ssname sstxt 0))))
    txt_height (cdr (assoc '40 (entget (ssname sstxt 0))))
    txt_width (cdr (assoc '41 (entget (ssname sstxt 0))))
    txt_rotate (cdr (assoc '50 (entget (ssname sstxt 0))))
    txt_obliq (cdr (assoc '51 (entget (ssname sstxt 0))))
    txt_color (cdr (assoc '62 (entget (ssname sstxt 0))))
  )
  (prompt (strcat "\nCurrent text Style is :           " txt_styl))
  (prompt (strcat "\nCurrent text Layer is :           " txt_lay))
  (prompt (strcat "\nCurrent text Insertion point:     "
                  (if (< (car txt_inspt) 0.0)
                    (strcat "-" (rtos (abs (car txt_inspt)) 2 4))
                    (rtos (car txt_inspt) 2 4)
                  )
                  ","
                  (if (< (cadr txt_inspt) 0.0)
                    (strcat "-" (rtos (abs (cadr txt_inspt)) 2 4))
                    (rtos (cadr txt_inspt) 2 4)
                  )
                  ","
                  (if (< (nth 2 txt_inspt) 0.0)
                    (strcat "-" (rtos (abs (nth 2 txt_inspt)) 2 4))
                    (rtos (nth 2 txt_inspt) 2 4)
                  )
          )
  )
  (if (/= txt_elev nil)
    (prompt (strcat "\nCurrent text Elevation is :       " (rtos txt_elev 2 4)))
    (prompt "\nCurrent text elevation is :       0")
  )
  (prompt (strcat "\nCurrent text Height is :          " (rtos txt_height 2 4)))
  (prompt (strcat "\nCurrent text Width is :           " (rtos txt_width 2 4)))
  (prompt (strcat "\nCurrent text Rotation angle is :  " (rtos txt_rotate 2 4)))
  (prompt (strcat "\nCurrent text Obliquing angle is : " (rtos txt_obliq 2 4)))
  (if (/= txt_color nil)
    (prompt (strcat "\nCurrent text Color is :           " (rtos txt_color 2 4)))
    (prompt "\nCurrent text color is :           Bylayer")
  )
  (setq txt_2_chg 1)
  (while (/= txt_2_chg "Q")
  (initget "S L I E H W R O C Q")
  (setq txt_2_chg (getkword "\nChange which property -
            Style,Layer,Insertion point,Elev,Height,Width,Rotation,Oblique angle,Color, or Quit: ")) 
  (cond
    ((= txt_2_chg "S")
       (command "style" "?" "*")
       (setq txt_styl (getstring "\nWhich text style do you wish to use? : "))
       (txt_2_make)
    )
    ((= txt_2_chg "L")
       (alert "\nLook for the layer you wish")
       (command "_ddlmodes")
       (setq txt_lay (getstring "\nWhich text layer do you wish to use? : "))
       (txt_2_make)
    )
    ((= txt_2_chg "I")
       (setq txt_inspt (getpoint "\nPick new text insertion point: "))
       (txt_2_make)
    )
    ((= txt_2_chg "E")
       (setq txt_elev (getreal "\nEnter the text elevation you wish to use: "))
       (txt_2_make)
    )
    ((= txt_2_chg "H")
       (setq txt_height (getreal "\nEnter the text height you wish to use: "))
       (txt_2_make)
    )
    ((= txt_2_chg "W")
       (setq txt_width (getreal "\nEnter the text width you wish to use: "))
       (txt_2_make)
    )
    ((= txt_2_chg "R")
       (setq txt_rotate (getangle "\nEnter or pick the text rotation you wish to use: "))
       (txt_2_make)
    )
    ((= txt_2_chg "O")
       (setq txt_obliq (* (/ (getreal "\nEnter the text obliquing angle you wish to use: ") 180.0) PI))
       (txt_2_make)
    )
    ((= txt_2_chg "C")
       (setq txt_color (getreal "\nEnter the number for the text color you wish to use: "))
       (txt_2_make)
    )
  )
  )
)

(defun txt_2_make ()
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 7 txt_styl) (assoc 7 txt_chg) txt_chg))
  (entmod txt_chg)
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 8 txt_lay) (assoc 8 txt_chg) txt_chg))
  (entmod txt_chg)
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 10 txt_inspt) (assoc 10 txt_chg) txt_chg))
  (entmod txt_chg)
  (if (/= txt_elev nil)
    (progn
      (setq txt_chg (entget (ssname sstxt 0)))
      (setq txt_chg (subst (cons 38 txt_elev) (assoc 38 txt_chg) txt_chg))
      (entmod txt_chg)
    )
  )
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 40 txt_height) (assoc 40 txt_chg) txt_chg))
  (entmod txt_chg)
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 41 txt_width) (assoc 41 txt_chg) txt_chg))
  (entmod txt_chg)
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 50 txt_rotate) (assoc 50 txt_chg) txt_chg))
  (entmod txt_chg)
  (setq txt_chg (entget (ssname sstxt 0)))
  (setq txt_chg (subst (cons 51 txt_obliq) (assoc 51 txt_chg) txt_chg))
  (entmod txt_chg)
  (if (/= txt_color nil)
    (progn
      (setq txt_chg (entget (ssname sstxt 0)))
      (setq txt_chg (subst (cons 62 txt_color) (assoc 62 txt_color) txt_chg))
      (entmod txt_chg)
    )
  )
)

jmcshane

  • Newt
  • Posts: 83
Re: Viewport zoom to specific attribute lisp... Anyone have?
« Reply #2 on: September 18, 2009, 04:24:00 AM »
I had a similar task to do but it was to do with Keyplans.

I made a block with an attribute whose insertion point would be the center of the viewport.
It would then find the attribute value of the block,
create a tab with the attribute value,
make a viewport
and then scale the viewport.

The only drawback was that the tab that it was copying should not have a viewport created in it.

I used to set that layout tab up with the Legend and Title block so that all the rest of the tabs would be similar.

For what its worth
John.

Civil 3D 2021. Windows 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.