PS:MS Scale Based on Nearest Set Scale

PS:MS Scale Based on Nearest Set Scale

Anonymous
Not applicable
2,082 Views
15 Replies
Message 1 of 16

PS:MS Scale Based on Nearest Set Scale

Anonymous
Not applicable

In paper space we zoom to our title block which is in model space using zoom-object. When we do that the object comes in close to scale (VPSCALE - PS:MS = 1:24.01428). Is there a way that I could create a lisp that will perform a zoom-object and then set the scale to the nearest set scale (PS:MS = 1:24). Our set scales would be 1:1, 1:2, 1:4, 1:8, 1:12, 1:16, 1:24, 1:32, 1:48, 1:64, 1:96. Any help on this would be great.

0 Likes
Accepted solutions (1)
2,083 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable

Is there a command or variable that will give me a reference of just the model space units after I zoom?

 

I'm thinking ZOOM nXP could work if I could reference the MS units. For example, once I zoom an object and the VPSCALE comes in at 1:24.01428, if I could TRUNCATE the MS value (24.01428 = 24) then I could continue the routine and set the nXP value to 1/'truncated_ms_value'XP. But I can't find a reference to MS units other than VPSCALE.

0 Likes
Message 3 of 16

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

In paper space we zoom to our title block which is in model space using zoom-object. When we do that the object comes in close to scale (VPSCALE - PS:MS = 1:24.01428). Is there a way that I could create a lisp that will perform a zoom-object and then set the scale to the nearest set scale (PS:MS = 1:24). Our set scales would be 1:1, 1:2, 1:4, 1:8, 1:12, 1:16, 1:24, 1:32, 1:48, 1:64, 1:96. Any help on this would be great.


Try below code. Minimal testing and no error trap.

(defun c:somefunc  (/ cvp dat3 ent etdata etdata2 ss1 zf)
 (and (zerop (getvar 'tilemode))
      (> (setq cvp (getvar 'cvport)) 1)
      (setq ent (car (entsel "\nSelect object to zoom to: ")))
      (vl-cmdf "._zoom" "_o" ent "")
      (setq ss1 (ssget "_x" (list '(0 . "viewport") (cons 69 cvp) (cons 410 (getvar 'ctab)))))
      (setq zf   (/ (cdr (assoc 41 (setq etdata (entget (setq ent (ssname ss1 0)))))) (cdr (assoc 45 etdata)))
            dat3 (mapcar '(lambda (x)
                           (cons (cdr (assoc 300 (setq etdata2 (entget (cdr x)))))
                                 (apply '/ (reverse (cdr (reverse (mapcar 'cdr (member (assoc 140 etdata2) etdata2))))))))
                         (vl-remove-if-not '(lambda (x) (= 350 (car x))) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
      (setpropertyvalue ent
                        "ViewHeight"
                        (/ (cdr (assoc 41 etdata))
                           (cdr (assoc (caar (vl-sort (mapcar '(lambda (x) (cons (car x) (abs (- zf (cdr x))))) dat3)
                                                      '(lambda (x y) (< (cdr x) (cdr y)))))
                                       dat3)))))
 (princ))

zoom_object_scale.gif

 

0 Likes
Message 4 of 16

Anonymous
Not applicable

Ranjit,

 

The code works great for zooming to scale. After testing though the CANNOSCALE remains unchanged. Is there a way to get it to set the CANNOSCALE to the zoomed scale?

0 Likes
Message 5 of 16

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

Ranjit,

 

The code works great for zooming to scale. After testing though the CANNOSCALE remains unchanged. Is there a way to get it to set the CANNOSCALE to the zoomed scale?


OK. Try below code.

(defun c:somefunc  (/ cvp dat3 ent etdata etdata2 sc ss1 zf)
 (and (zerop (getvar 'tilemode))
      (> (setq cvp (getvar 'cvport)) 1)
      (setq ent (car (entsel "\nSelect object to zoom to: ")))
      (vl-cmdf "._zoom" "_o" ent "")
      (setq ss1 (ssget "_x" (list '(0 . "viewport") (cons 69 cvp) (cons 410 (getvar 'ctab)))))
      (setq zf   (/ (cdr (assoc 41 (setq etdata (entget (setq ent (ssname ss1 0)))))) (cdr (assoc 45 etdata)))
            dat3 (mapcar '(lambda (x)
                           (cons (cdr (assoc 300 (setq etdata2 (entget (cdr x)))))
                                 (apply '/ (reverse (cdr (reverse (mapcar 'cdr (member (assoc 140 etdata2) etdata2))))))))
                         (vl-remove-if-not '(lambda (x) (= 350 (car x))) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
      (setpropertyvalue ent
                        "ViewHeight"
                        (/ (cdr (assoc 41 etdata))
                           (cdr (assoc (setq sc (caar (vl-sort (mapcar '(lambda (x) (cons (car x) (abs (- zf (cdr x))))) dat3)
                                                               '(lambda (x y) (< (cdr x) (cdr y))))))
                                       dat3)))))
 (somefunc2 ent sc)
 (princ))
(defun somefunc2  (x y / etdata)
 (setq etdata (cdr (assoc 360 (entget (cdr (assoc 360 (entget x)))))))
 (setq etdata (entget (cdr (assoc 340 (entget etdata)))))
 (entmod (subst (cons 300 y) (assoc 300 etdata) etdata)))

zoom_object_scale_2.gif

 

0 Likes
Message 6 of 16

Anonymous
Not applicable

Ranjit,

 

When I run the new code, it adds new annotative scales and I can't delete them. Now, I have multiple annotative scales of 1/2" = 1'-0" with percentages of 4.17% and 8.33%.

 

12-21-2017 1-07-22 PM.jpg

0 Likes
Message 7 of 16

Anonymous
Not applicable

Actually, it's renaming the pspace anno scale to the mspace anno scale.

0 Likes
Message 8 of 16

Anonymous
Not applicable

Is there anyway to have it perform "CANNOSCALE" after and have it reference the "Standard scale" as it shows in the properties for the viewport?

 

https://www.screencast.com/t/og8bybymLkB

 

0 Likes
Message 9 of 16

Ranjit_Singh
Advisor
Advisor
Accepted solution

Your suggestion might just do the trick. Try below code. Again there is no error trap and minimal testing so test it on a test drawing.

(defun c:somefunc  (/ cvp dat3 ent etdata etdata2 sc ss1 zf)
 (and (zerop (getvar 'tilemode))
      (> (setq cvp (getvar 'cvport)) 1)
      (setq ent (car (entsel "\nSelect object to zoom to: ")))
      (vl-cmdf "._zoom" "_o" ent "")
      (setq ss1 (ssget "_x" (list '(0 . "viewport") (cons 69 cvp) (cons 410 (getvar 'ctab)))))
      (setq zf   (/ (cdr (assoc 41 (setq etdata (entget (setq ent (ssname ss1 0)))))) (cdr (assoc 45 etdata)))
            dat3 (mapcar '(lambda (x)
                           (cons (cdr (assoc 300 (setq etdata2 (entget (cdr x)))))
                                 (apply '/ (reverse (cdr (reverse (mapcar 'cdr (member (assoc 140 etdata2) etdata2))))))))
                         (vl-remove-if-not '(lambda (x) (= 350 (car x))) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
      (setpropertyvalue ent
                        "ViewHeight"
                        (/ (cdr (assoc 41 etdata))
                           (cdr (assoc (setq sc (caar (vl-sort (mapcar '(lambda (x) (cons (car x) (abs (- zf (cdr x))))) dat3)
                                                               '(lambda (x y) (< (cdr x) (cdr y))))))
                                       dat3)))))
 (command "._cannoscale" sc)
 (princ))
Message 10 of 16

Anonymous
Not applicable

For some reason it is still making me select the annotation scale in order for the view port and annotation scales to match.

12-21-2017 2-25-14 PM.jpg

Sorry for being difficult.

0 Likes
Message 11 of 16

Ranjit_Singh
Advisor
Advisor


No need to be sorry. I am just not sure I understand it is still making me select the annotation scale in order for the view port and annotation scales to match. Maybe post a screencast. Below is how it works at my end.zoom_object_scale_3.gif

0 Likes
Message 12 of 16

Anonymous
Not applicable
0 Likes
Message 13 of 16

Anonymous
Not applicable

My sincerest apologies... I did not examine the code closely enough and thought you had just entered (command "._cannoscale" sc) at the end of the routine... I copied it fresh and it ran perfectly. Sorry for assuming everything was the same except that line of code.

 

You are a champ!

0 Likes
Message 14 of 16

Ranjit_Singh
Advisor
Advisor

Glad it worked.

0 Likes
Message 15 of 16

Jeremiah.Dillashaw
Contributor
Contributor

Hello Ranjit, 

Is this routine setup in a way that lines 4 and 5 could replaced with a different code block to add an option for the user to select the zoom window manually instead of only selecting the object? Or would everything below the "setq ent..." line have to change to accomodate the two options?

 

Could you point me in the right direction as to how that could be done? Thanks for your time, this routine is a huge timesaver as is! 🙂

 

 

(defun c:somefunc  (/ cvp dat3 ent etdata etdata2 sc ss1 zf)
 (and (zerop (getvar 'tilemode))
      (> (setq cvp (getvar 'cvport)) 1)
      (setq ent (car (entsel "\nSelect object to zoom to: ")))   ;; these are the two lines i'm asking about
      (vl-cmdf "._zoom" "_o" ent "")                             ;; these are the two lines i'm asking about
      (setq ss1 (ssget "_x" (list '(0 . "viewport") (cons 69 cvp) (cons 410 (getvar 'ctab)))))
      (setq zf   (/ (cdr (assoc 41 (setq etdata (entget (setq ent (ssname ss1 0)))))) (cdr (assoc 45 etdata)))
            dat3 (mapcar '(lambda (x)
                           (cons (cdr (assoc 300 (setq etdata2 (entget (cdr x)))))
                                 (apply '/ (reverse (cdr (reverse (mapcar 'cdr (member (assoc 140 etdata2) etdata2))))))))
                         (vl-remove-if-not '(lambda (x) (= 350 (car x))) (dictsearch (namedobjdict) "ACAD_SCALELIST"))))
      (setpropertyvalue ent
                        "ViewHeight"
                        (/ (cdr (assoc 41 etdata))
                           (cdr (assoc (setq sc (caar (vl-sort (mapcar '(lambda (x) (cons (car x) (abs (- zf (cdr x))))) dat3)
                                                               '(lambda (x y) (< (cdr x) (cdr y))))))
                                       dat3)))))
 (command "._cannoscale" sc)
 (princ))

 

0 Likes
Message 16 of 16

Ranjit_Singh
Advisor
Advisor

Try replacing the 2 lines with this one

(null (command-s "._zoom" "_w"))
0 Likes