Viewport Zoom Out to nearest Scale

kieran.leadbetter
Advocate
Advocate

Viewport Zoom Out to nearest Scale

kieran.leadbetter
Advocate
Advocate

Hello, does anyone know of a command or does anyone have a lisp I could use which would zoom my viewport outwards to the nearest available scale value

I generally use 1:25,50,100,250,500 and 1000

Currently I have a lisp which zooms everything in, but it doesn't zoom to the nearest scale value afterwards.

Thank you for anyone who helps.

0 Likes
Reply
Accepted solutions (1)
722 Views
15 Replies
Replies (15)

ВeekeeCZ
Consultant
Consultant

locked VPs ignore or un/relock?

 

also post your current lisp

kieran.leadbetter
Advocate
Advocate
I've set up my template so that they are currently unlocked, so preferably unlocked and allow any locked viewports to remain as they are if possible
0 Likes

ВeekeeCZ
Consultant
Consultant

Post your lisp.

kieran.leadbetter
Advocate
Advocate

This is the current lisp I have, I didn't make it but I am trying to learn it

0 Likes

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try and see.

 

(defun c:ZoomViewportOut (/ oldcmdecho vplist curcvport nr vpss ms en x scales cs ns)

  (setq oldcmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq vplist (mapcar 'car (vports)))
  (setq curcvport (getvar "cvport"))
  (setq scales '(0.04 0.02 0.01 0.004 0.002 0.001 0.0005 0.0002))
  
  (if (= (getvar "tilemode") 0)
    (progn
      (if (= (setq ms (getvar "cvport")) 1)(command "._mspace"))

      (setq nr 0 vpss (ssget "_x" (list '(-4 . "<AND") '(0 . "VIEWPORT")(cons 410 (getvar "ctab")) '(-4 . "<NOT") '(69 . 1) '(-4 . "NOT>") '(-4 . "AND>"))))
      (if vpss
        (repeat (sslength vpss)
          (setq en (entget (setq e (ssname vpss nr))))

	  (if (and (= 0 (logand 1 (cdr (assoc 90 en))))
		   (< 0 (cdr (assoc 68 en)))
		   (/= 16384 (logand 16384 (cdr (assoc 90 en)))))
            (progn
	      (setq cs (getpropertyvalue e "CustomScale"))
	      (if (setq ns (cond ((cadr (member cs (vl-sort (cons cs scales) '>)))) (cs)))
		(setpropertyvalue e "CustomScale" ns))))
	      
          (setq nr (+ 1 nr))
        )
      )
      (if (= ms 1) (command "._pspace"))
    )
    (foreach x vplist (setvar "cvport" x) (command "._zoom" "_e"))
  )
  (setq vpss nil)(setvar "cvport" curcvport)(setvar "cmdecho" oldcmdecho)
  (princ)
)

 

kieran.leadbetter
Advocate
Advocate
Wow... that works genuinely perfect, thank you

can you explain some of that lisp or where I could learn to write things like that

I understand the quotations and bracket functions and things

Its more the setq, sslength, vpss, etc.

Different command line prompts I think they're called?
0 Likes

ВeekeeCZ
Consultant
Consultant

Well, I guess you want to start with something simpler than this.

 

Mostly, THIS LISP tutorial is recommended as a good place to start. 

 

setq and sslength are the functions. vpss is a variable.

 

kieran.leadbetter
Advocate
Advocate

Woah, thank you, thats also brilliant 

Thank you so much

0 Likes

ВeekeeCZ
Consultant
Consultant

@kieran.leadbetter wrote:
Wow... that works genuinely perfect, thank you

can you explain some of that lisp or where I could learn to write things like that

I understand the quotations and bracket functions and things

Its more the setq, sslength, vpss, etc.

Different command line prompts I think they're called?

 

 

Type VLIDE into the command line. Create a new and copy/paste the code in there to see something like this:

 

BeekeeCZ_2-1666794168067.png

 

Blue are functions, black are variables. Green are integers, dark green reals. Strings are in magenta. And red... parentheses... 

 

BeekeeCZ_4-1666794527500.png

 

 

0 Likes

Sea-Haven
Mentor
Mentor

There is a simple way to set a scale in a viewport no code, if your metric, turn on the toolbar viewports, it has a current scale box so for metre units just put a number in the box and it will zoom to that scale. 

 

The number is a simple 1000/scale so 250=4, 100=10, 500=2.

 

View not right just change number again and yes lock viewport when happy.

 

SeaHaven_0-1666840735774.png

 

0 Likes

kieran.leadbetter
Advocate
Advocate
Would you know how to fix this lisp, been trying to import the scales I would generally use, but it requires an IF function I think for when a scale already exists, because when a scale already exists it causes the lisp to break

(defun C:ViewportScaleImportNWG ()
(command "-SCALELISTEDIT" "D" "*" "E")
(command "-SCALELISTEDIT" "A" "1:25" "N" "1:25" "E")
(command "-SCALELISTEDIT" "A" "1:50" "N" "1:50" "E")
(command "-SCALELISTEDIT" "A" "1:100" "N" "1:100" "E")
(command "-SCALELISTEDIT" "A" "1:250" "N" "1:250" "E")
(command "-SCALELISTEDIT" "A" "1:500" "N" "1:500" "E")
(command "-SCALELISTEDIT" "A" "1:1000" "N" "1:1000" "E")
(command "-SCALELISTEDIT" "A" "1:2000" "N" "1:2000" "E")
(command "-SCALELISTEDIT" "A" "1:2500" "N" "1:2500" "E")
(command "-SCALELISTEDIT" "A" "1:5000" "N" "1:5000" "E")
(princ) ;clean exit
)
0 Likes

kieran.leadbetter
Advocate
Advocate
That's what I normally used, but I've got a lot of drawings so it would be faster to create a lisp which will fully automate the viewport part of the project and then go through them and double check for any drawings which need adjusted slightly
0 Likes

ВeekeeCZ
Consultant
Consultant

Here's the IF func... 

 

 

(vl-load-com)

(defun C:ViewportScaleImportNWG ( / scales)

  (command "-SCALELISTEDIT" "D" "*" "E")
  (setq scales (mapcar '(lambda (x) (cdr (assoc 300 (entget (cdr x))))) (vl-remove-if '(lambda (x) (/= (car x) 350)) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
  
  (if (vl-position "1:25" scales)
    (it exists)
    (it's not)
    )
0 Likes

kieran.leadbetter
Advocate
Advocate
(vl-load-com)

(defun C:ViewportScaleImportNWG ( / scales)

(command "-SCALELISTEDIT" "D" "*" "E")
(setq scales (mapcar '(lambda (x) (cdr (assoc 300 (entget (cdr x))))) (vl-remove-if '(lambda (x) (/= (car x) 350)) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))

(if (vl-position "1:25" scales)
(it exists)
(it's not)
)
(princ) ;clean exit
)

So is this how my lisp should appear for scale 1:25?

It says

Command: ; error: no function definition: IT
0 Likes

ВeekeeCZ
Consultant
Consultant

First of all, I don't really understand what you wanted to do by this:

(command "-SCALELISTEDIT" "A" "1:25" "N" "1:25" "E")

it's You: Add 1:25, then ACAD: Hey, it exists. Redefine? You: No, then 1:25... what?!

 

(vl-load-com)

(defun C:ViewportScaleImportNWG ( / scales)

  (command "-SCALELISTEDIT" "D" "*" "E")
  (setq scales (mapcar '(lambda (x) (cdr (assoc 300 (entget (cdr x))))) (vl-remove-if '(lambda (x) (/= (car x) 350)) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
  
  (if (not (vl-position "1:25" scales))
    (command "-SCALELISTEDIT" "A" "1:25" "1:25" "E"))   ; create new
  							; ELSE: do nothing is already exists

  ;; or
  (if (not (vl-position "1:25" scales))
    (command "-SCALELISTEDIT" "A" "1:25" "1:25" "E")       ; create new
    (command "-SCALELISTEDIT" "A" "1:25" "_Y" "1:25" "E")) ; redefine
    

;; accordingly all the next

    (if (not (vl-position "1:50" scales))
      (command "-SCALELISTEDIT" "A" "1:50" "1:50" "E"))  ; create new

  
(princ) ;clean exit
)

 

0 Likes