Jump to content

zoom to a specific text lisp


svorgodne

Recommended Posts

I have several layouts in a template autocad file, which will be used several times due to size of the project and also because of the phase itself, so I need to divide the whole site A0 1:50 scale, decimal type. I have created already all the layouts, although the MVIEW is zoomed to the same point since I was only copying the layouts with subsequent numbers. Each tile from the grid I used for dividing the site is having also subsequent numbers, so afterwards on each layout I can zoom precisely to this entity by filtering contents to get thatt specific entity (number) and so on on each layout. Each number in the middle of each tile is unique and susequent to be able to zoom it in every layout in order to have the whole puzzle of the site.

 

I found a little routine on the web that can filter the content of the text of the whole drawing:

 

(ssget "_X" '((0 . "TEXT,MTEXT")(1 . "501")))

 

501 would be one of these text content to be zoomed to a specific scale in ll the different layouts. I want to avoid to do it manually sincethis implies a lot of steps, so I think it could be possible to setup a variable with setq liusp command which could add one value everytime the routine is running so when I go to the next layout and run the routine the number would be 502.

 

The problem I found is the number cannot be subsituted by the value of a variable defined by setq lisp command, therefore the whole routine is not useful.

 

This is the routine I am using:

 

(defun c:sss ()

(ssget "_X" '((0 . "TEXT,MTEXT") (1 . "501")))

(command "zoom" "o" "p" ""

"zoom" "1000/50xp")

)

 

I need to substitue the "501" for a variable defined previously by a setq. Is that possible?

 

Plase help me, it is extremly urgent.

 

Thanks

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    9

  • dchilders

    7

  • lfe011969

    3

  • svorgodne

    2

Top Posters In This Topic

Yes it's possible.

 

You'll first need to convert the variable 'number' to 'text', as in;

 

(setq Numtxt (rtos num 2 0));;if var is a real or int

 

or

 

(setq Numtxt (itoa num));;if var is an integer

 

then

 

(ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 1 Numtxt)))

Link to comment
Share on other sites

  • 1 year later...

Hello,

I'm having trouble getting this routine to work. Please bear with me I do not know how to write lisp code. I usually just find something that will work and load it. Any help with this would be greatly appreciated.

 

When I run this one I get this error:

; error: bad argument type: fixnump: nil

 

(defun c:sss ()

(setq Numtxt (itoa num));;

(ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 1 Numtxt)))

(command "zoom" "o" "p" ""

"zoom" "1000/200xp")

)

 

When I run this one I get this error:

 

; error: bad argument type: numberp: nil

 

(defun c:sss ()

(setq Numtxt (rtos num 2 0));;

(ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 1 Numtxt)))

(command "zoom" "o" "p" ""

"zoom" "1000/200xp")

)

 

Basically what I have is a grid in model space and hundreds of layout tabs named according to each grid number (3548A1, 3548A2, 3548A3....). I would like to go to a layout, go inside thr viewport and run this routine. Hopefully the routine will promt me for a grid number (text) and find it and zoom it to a certain scale. Thanks in advance for any help with this.

Link to comment
Share on other sites

I need to substitue the "501" for a variable defined previously by a setq. Is that possible?Thanks

 

Does the value in quotes correspond to the layout number? Meaning on Layout1 would your ssget statement be this:

 

(ssget "_X" '((0 . "TEXT,MTEXT")(1 . "1")))

 

then Layout2 would be "2" and so on?

Link to comment
Share on other sites

To be honest I don't know. I'm really not sure how to write code. Is there anyway to have this routine promt me to input the grid number text I want it to zoom to?

 

Thanks

Link to comment
Share on other sites

To be honest I don't know. I'm really not sure how to write code. Is there anyway to have this routine promt me to input the grid number text I want it to zoom to?

 

Thanks

 

To ask the user for a string use this:

 

(setq str (getstring "\nEnter text string to search for: "))

 

Others:

 

real number = getreal

integer = getint

point = getpoint

keyword = getkword

Link to comment
Share on other sites

Haven't read the whole thread, but maybe this will offer some insight:

 

(defun c:FindText nil
 (sssetfirst nil
   (ssget "_X"
     (list
       (cons 0 "TEXT,MTEXT")
       (cons 1 (strcat "*" (getstring t "\nSpecify Text to Search for <All> : ") "*"))
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

The problem I found is the number cannot be subsituted by the value of a variable defined by setq lisp command, therefore the whole routine is not useful.

 

To understand why, read this:

http://www.cadtutor.net/forum/showpost.php?p=258390&postcount=20

Link to comment
Share on other sites

I tried running the code below, it promts me to enter a text string. For instance I entered 3647B3, and hit enter, it zooms to the scale I want but doesn't go to that text, it just zooms to a random spot? Thanks agian for all your help, this will be a life saver!

 

(defun c:sss ()

(setq str (getstring "\nEnter text string to search for: "))

(command "zoom" "o" "p" ""

"zoom" "1/100xp")

)

Link to comment
Share on other sites

quickly put together. To understand go to developer help and search for textbox

 

(defun c:test (/ ent ang lst)
 (if (setq ent (car (entsel)))
   (progn
     (setq ang (cdr (assoc 50 (setq ent (entget ent))))
           lst
       (mapcar 
        '(lambda (x) 
           (list 
             (+ (car (cdr (assoc 10 ent)))
               (- (* (car x) (cos ang))(* (cadr x) (sin ang)))
             )
             (+ (cadr (cdr (assoc 10 ent)))
               (+ (* (car x) (sin ang))(* (cadr x) (cos ang)))
             )
           )
         )
         (textbox (list (assoc 1 ent)))
       )
     )
     (command "_.zoom" (nth 0 lst)(nth 1 lst))
   )
 )
 (princ)
)

Link to comment
Share on other sites

Try:

 

(defun c:sss ( / ss )
 (if
   (setq ss
     (ssget "_X"
       (list
         (cons 0 "TEXT,MTEXT")
         (cons 1 (strcat "*" (getstring t "\nSpecify Text to Search for <All> : ") "*"))
       )
     )
   )
   (command "_.zoom" "_o" ss "" "_.zoom" "1/100xp")
   (princ "\n** Not Found **")
 )
 (princ)
)

Note that if more than more text object is found, all will be included in the zoom. If you wish to zoom to each object in turn, you will have to iterate through the selectionset.

Link to comment
Share on other sites

I also tried this, and it work great for finding the text, but when I add the zoom cammand to it, it zooms to a random spot?

 

(defun c:FindText nil

(sssetfirst nil

(ssget "_X"

(list

(cons 0 "TEXT,MTEXT")

(cons 1 (strcat "*" (getstring t "\nSpecify Text to Search for : ") "*"))

)

)

)

(princ)

(command "zoom" "o" "p" ""

"zoom" "1/100xp")

)

Link to comment
Share on other sites

Some fun:

 

;; ZoomText © Lee Mac 2011

(defun c:ZoomText ( / ss ac l p1 p2 x ) (vl-load-com)
 (if
   (ssget "_X"
     (list (cons 0 "TEXT,MTEXT")
       (cons 1
         (strcat "*"
           (vl-list->string
             (apply 'append
               (mapcar
                 (function
                   (lambda ( c )
                     (if (vl-position c '(35 64 46 42 63 126 91 123 44 96))
                       (list 96 c)
                       (list c)
                     )
                   )
                 )
                 (vl-string->list
                   (getstring t "\nSpecify Text to Search for <All> : ")
                 )
               )
             )
           )
           "*"
         )
       )
     )
   )
   (progn
     (vlax-for o
       (setq ss
         (vla-get-ActiveSelectionSet
           (vla-get-ActiveDocument
             (setq ac (vlax-get-acad-object))
           )
         )
       )
       (setq l
         (cons
           (cons o
             (progn
               (vla-getBoundingBox o 'p1 'p2) (list p1 p2)
             )
           )
           l
         )
       )
     )
     (vla-delete ss)
     (while (setq x (car l))
       (vla-ZoomWindow ac (cadr x) (caddr x))
       
       (initget "Next Exit")
       (setq l
         (if (eq "Exit" (getkword "\nZoom to Next Object? [Next/Exit] <Next> : ")) nil (cdr l))
       )
     )
   )
   (princ "\n** None Found **")
 )

 (princ)
)
         

Edited by Lee Mac
Link to comment
Share on other sites

I also tried this, and it work great for finding the text, but when I add the zoom cammand to it, it zooms to a random spot?

 

Note that if more than more text object is found, all will be included in the zoom. If you wish to zoom to each object in turn, you will have to iterate through the selectionset.

 

^^ Could be why

Link to comment
Share on other sites

Hey, sorry about not following the code posting guidelines, I'll make sure to do so in the future. Lee I ran that last routine, it works in model space, but when I go to a layout and open a viewport it does seem to work. Is it possible to do something like this from within a viewport or is this just a pipe dream. I basically tring to call up my grid number to a 1/100 scale. Thank you very much for your help

Link to comment
Share on other sites

Hey, sorry about not following the code posting guidelines, I'll make sure to do so in the future.

 

No worries :)

 

Lee I ran that last routine, it works in model space, but when I go to a layout and open a viewport it does seem to work. Is it possible to do something like this from within a viewport or is this just a pipe dream. I basically tring to call up my grid number to a 1/100 scale. Thank you very much for your help

 

Sorry, I've now updated my code to remove the Layout filter, please try it again :)

Link to comment
Share on other sites

Sweet, it works great! One last thing, with your Zoomtext routine, is there anywhere I can go in and change the scale becuase I have to do this periodicaly and the scales change? I looked thru it to see, but at this point most of these lisp codes look like hyroglifics to me. I'm very new to Autolisp.

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