Viewport Scale Equal To Annotation Scale - LISP

Viewport Scale Equal To Annotation Scale - LISP

chancevv
Participant Participant
541 Views
1 Reply
Message 1 of 2

Viewport Scale Equal To Annotation Scale - LISP

chancevv
Participant
Participant

Hi! Running into an interesting situation when trying to scale the viewport of my layout with LISP.

 

Quick rundown: I'm trying to automate scaling the viewport to 1" = 750' by calling a custom command made with LISP. When doing this manually usingmouse and keyboard, I noticed in the command line that it uses the command _.MSPACE to enter the model space of the viewport, _CANNOSCALE to adjust the scale of the viewport to the predefined scales on the list, and then ._PSPACE to exit the viewport. Seems simple.

 

1.png

Here's what the command line looks like:

Command: _.MSPACE
Command: _CANNOSCALE
Enter new value for CANNOSCALE <"1" = 500'">: 1" = 750'
Command: _.PSPACE


If I click back into the viewport and type VPSCALE, the scale corresponds with the value chosen from the list. Ex: the command line will show PS:MS == 1:750 for this example.

 

Now I want to apply this into LISP code. Based on what the command line was showing while doing this manually, I created the following:

(defun c:scaleadjustment()
(setq desiredscale "1\" = 750'")
(command "._mspace")
(command "_cannoscale" desiredscale)
(command "._pspace")
(princ)
)

 

Upon calling the command, the command line looks virtually the same:

 

Command: SCALEADJUSTMENT
Command: ._mspace
Command: _cannoscale
Enter new value for CANNOSCALE <"1" = 500'">: 1" = 750'
Command: ._pspace

However, it does not increase or decrease the zoom of my viewport like it would if I am using the button at the bottom of the screen and clicking the corresponding value. If I type in _CANNOSCALE after calling the command, it has the value CANNOSCALE <1" = 750'">: , but if I type VPSCALE it will show the initial scale value. Therefore, when using _CANNOSCALE in LISP, it doesn't automatically match the viewport scale with the updated annotation scale.

There is a button to the right of the scale value for this, but from what I can (or can't) find, there is not a command to queue this. Does anyone know how it can be replicated in LISP, or if there is a different way to tackle this?

 

2.png

Really appreciate any insight!

0 Likes
Accepted solutions (1)
542 Views
1 Reply
Reply (1)
Message 2 of 2

CodeDing
Advisor
Advisor
Accepted solution

@chancevv ,

 

Based on your screenshots, it would appear to me that your Paper Space is setup to be INCHES and your Model Space to be FEET. If I am correct in those 2 assumptions, then this code below should work for you. I have set it up in a way so that when you input your desired scales, you can enter both your decimal/engineering scales (e.g. 1"=30') and your architectural scales (e.g. 1/8"=1').

(defun c:TEST ( / errMsg paperInch drawingFoot ssVP vp cScale lockState)
  ;; initial checks to be sure we're in paper space
  (if (or (not (= 1 (getvar 'CVPORT)))
          (not (zerop (getvar 'TILEMODE))))
    (setq errMsg "\nMust be in Paper Space.")
  );if
  (if errMsg (progn (alert (princ errMsg)) (exit)))
  ;; get vp scale inputs from user [or we can use defaults if desired]
  ;; (setq paperInch 1)
  ;; (setq drawingFoot 30)
  (initget 7) (setq paperInch (getreal "\nEnter Paper Inches (e.g. if 1\"=30' then enter '1'): "))
  (initget 7) (setq drawingFoot (getreal "\nEnter Drawing Feet (e.g. if 1\"=30' then enter '30'): "))
  (prompt "Select VIEWPORT to change scale: ")
  (if (setq ssVP (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
    (progn
      (setq vp (ssname ssVP 0))
      (setq cScale (/ (* 12.0 paperInch) (* 12.0 drawingFoot)))
      (setq lockState (getpropertyvalue vp "Locked"))
      (setpropertyvalue vp "Locked" 0) 
      (setpropertyvalue vp "CustomScale" cScale)
      (setpropertyvalue vp "Locked" lockState)
      (prompt "\nCustom Viewport scale successfully set.")
    );progn
  ;else
    (prompt "\nViewport not selected. No action taken.")
  );if
  (princ)
);defun

 

Best,

~DD

0 Likes