Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Viewport Zoom Out to nearest Scale

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
kieran.leadbetter
720 Views, 15 Replies

Viewport Zoom Out to nearest Scale

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.

15 REPLIES 15
Message 2 of 16

locked VPs ignore or un/relock?

 

also post your current lisp

Message 3 of 16

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
Message 4 of 16

Post your lisp.

Message 5 of 16

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

Message 6 of 16

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

 

Message 7 of 16

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?
Message 8 of 16

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.

 

Message 9 of 16

Woah, thank you, thats also brilliant 

Thank you so much

Tags (1)
Message 10 of 16


@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

 

 

Message 11 of 16

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

 

Message 12 of 16

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
)
Message 13 of 16

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
Message 14 of 16

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)
    )
Message 15 of 16

(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
Message 16 of 16

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
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report