Jump to content

AutoLisp to set viewport scale and dimension scale


KRBeckman

Recommended Posts

I'm haveing a hard time with this, can someone tell me what I've got wrong:

 

(defun c:bv ()
 (setq viewport_scale       (getreal "\nPlease input the viewport scale you would like to try in decimal format:"))
 (setq dimension_scale      (/ 1 viewport_scale))
 (setq viewport_scale_str   (rtos viewport_scale 2 4))
 (setq viewport_zoom_factor (strcat viewport_scale "XP"))
 (command "dimlfac" dimension_scale)
 (command "-dimstyle" "save" "SPECIALS - MODEL" "Y")
 (command "_.mspace")
 (command "cvport" "2")
 (command "zoom" "extends")
 (command "zoom" "scale" viewport_zoom_factor)
 (command "cvport" "4")
 (command "zoom" "extends")
 (command "zoom" "scale" viewport_zoom_factor)
 (command "cvport" "5")
 (command "zoom" "extends")
 (command "zoom" "scale" viewport_zoom_factor)
 (command "_.pspace")
 (command "zoom" "window" "-0.5,-0.5" "11,8.5")
)

 

I think it has something to do with combining a real variable with a string variable, so i tried the rtos function, but its still not working.

 

Any ideas?

Link to comment
Share on other sites

Try this:

 

(defun c:bv (/ obj ss DimObj Dim)
 (vl-load-com)
 (setq Dim "SPECIALS - MODEL")  ;; << Dimstyle
 
 (setq *doc    (cond (*doc) ((vla-get-ActiveDocument
                               (vlax-get-acad-object))))
       *defscl (cond (*defscl) (0.5)))

 (if (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'CTAB))))
   (progn
     (setq *defscl
       (cond ((getreal (strcat "\nSpecify Viewport Scale (Decimal) <"
                               (rtos *defscl) "> : ")))
             (*defscl)))
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc))
       (vla-put-CustomScale obj *defscl))
     (vla-delete ss)

     (setvar 'DIMLFAC (/ 1. *defscl))
     (if (not (vl-catch-all-error-p
                (setq DimObj
                  (vl-catch-all-apply (function vla-item)
                    (list (vla-get-Dimstyles *doc) Dim)))))
       
       (vla-CopyFrom DimObj *doc)))

   (princ "\n** No Viewports Found **"))

 (princ))


Link to comment
Share on other sites

I had to change it up a bit, because the decimals I was using were rounded to four decimal places and were causing rounding issues, here's the new one, can you make improve this?:

 

(defun c:bv ()
 (setq viewport_scale_fraction (getstring "\nPlease input the viewport scale you would like to try in fraction format (Example: 1-1/2):"))
 (setq viewport_scale_decimal  (if (= viewport_scale_fraction "3/32") (/ (+ 0.0 (/ 3.0 32.0)) 12.0)
     (if (= viewport_scale_fraction "3/16") (/ (+ 0.0 (/ 3.0 16.0)) 12.0)
       (if (= viewport_scale_fraction "1/8") (/ (+ 0.0 (/ 1.0 8.0)) 12.0)
         (if (= viewport_scale_fraction "1/4") (/ (+ 0.0 (/ 1.0 4.0)) 12.0)
    (if (= viewport_scale_fraction "3/8") (/ (+ 0.0 (/ 3.0 8.0)) 12.0)
      (if (= viewport_scale_fraction "1/2") (/ (+ 0.0 (/ 1.0 2.0)) 12.0)
        (if (= viewport_scale_fraction "3/4") (/ (+ 0.0 (/ 3.0 4.0)) 12.0)
          (if (= viewport_scale_fraction "1") (/ (+ 1.0 (/ 0.0 1.0)) 12.0)
     (if (= viewport_scale_fraction "1-1/4") (/ (+ 1.0 (/ 1.0 4.0)) 12.0)
       (if (= viewport_scale_fraction "1-1/2") (/ (+ 1.0 (/ 1.0 2.0)) 12.0)
         (if (= viewport_scale_fraction "1-3/4") (/ (+ 1.0 (/ 3.0 4.0)) 12.0)
           (if (= viewport_scale_fraction "2") (/ (+ 2.0 (/ 0.0 1.0)) 12.0)
      (if (= viewport_scale_fraction "3") (/ (+ 3.0 (/ 0.0 1.0)) 12.0)
        (if (= viewport_scale_fraction "4") (/ (+ 4.0 (/ 0.0 1.0)) 12.0)
          (if (= viewport_scale_fraction "16") (/ (+ 16.0 (/ 0.0 1.0)) 12.0) ""))))))))))))))))
 (setq dimension_scale_decimal (/ 1.0 vewport_scale_decimal))
 (setq viewport_scale_str      (rtos viewport_scale_decimal 2 )
 (setq dimension_scale_str     (rtos dimension_scale_decimal 2 14))
 (setq viewport_zoom_factor    (strcat viewport_scale_str "XP"))
 (command "-DIMSTYLE" "R" "SPECIALS - PAPER")
 (setvar "dimlfac" dimension_scale_str)
 (command "-dimstyle" "save" "SPECIALS - PAPER" "Y")
 (command "_.mspace")
 (command "cvport" "2")
 (command "zoom" "e")
 (command "zoom" "scale" viewport_zoom_factor)
 (command "cvport" "4")
 (command "zoom" "e")
 (command "zoom" "scale" viewport_zoom_factor)
 (command "cvport" "5")
 (command "zoom" "e")
 (command "zoom" "scale" viewport_zoom_factor)
 (command "_.pspace")
 (command "zoom" "window" "-0.5,-0.5" "11,8.5")
)

 

Also, notice I had the wrong Dimension style... It needs to be "Specials - Paper"

 

Thanks for all your help

Link to comment
Share on other sites

Why not look at the distof function?

 

(defun c:bv (/ obj ss scl DimObj Dim)
 (vl-load-com)
 (setq Dim "SPECIALS - PAPER")  ;; << Dimstyle
 
 (setq *doc    (cond (*doc) ((vla-get-ActiveDocument
                               (vlax-get-acad-object)))))

 (if (and (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'CTAB))))
          (setq scl (getstring "\nSpecify Viewport Scale: ")))
   
     (if (setq scl (distof scl 5))
       (progn
         
         (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc))
           (vla-put-CustomScale obj scl))
         (vla-delete ss)
         
         (setvar 'DIMLFAC (/ 1. scl))
         (if (not (vl-catch-all-error-p
                    (setq DimObj
                           (vl-catch-all-apply (function vla-item)
                             (list (vla-get-Dimstyles *doc) Dim)))))
           
           (vla-CopyFrom DimObj *doc)))

       (princ "\n** Invalid Scale Entered **"))

   (princ "\n** No Viewports Found **"))

 (princ))

Link to comment
Share on other sites

Cause I'm a rookie and have never heard of that command, let alone how to use it. If you have a better way to achieve what I'm trying to do, I'm all ears.

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