Jump to content

Viewport Scale


woodman78

Recommended Posts

I am setting up a list to set a dimstyle and leader style as default based on the Viewport scale. (If the drawings is at 1:100 then that style becomes default). I am making this a manual process but in trying to work out the viewport scale (custom scale) all I can come up with is this from JTB World:;;; getvpscale.lsp

;;;
;;; Get Viewport Scale in active viewport or in selected
;;; Supports viewports with clipping boundary
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved
;;; Website: [url="http://www.jtbworld.com"]www.jtbworld.com[/url]
;;; E-mail: [email="info@jtbworld.com"]info@jtbworld.com[/email]
;;; 2000-05-03 - First release
;;; 2000-05-09 - Detects perspective view
;;; Tested on AutoCAD 2000
(defun c:getvpscale (/ ss ent)
(defun printscale (/  data cvsize cvhgt)
 (setq cvscale (vla-get-customscale (vlax-ename->vla-object ent)))
 (princ "\nPS:MS == ")
 (cond
   ((> cvscale 1)
    (princ (rtos cvscale 2))
    (princ ":1")
   )
   (T
    (princ "1:")
    (princ (rtos (/ 1 cvscale) 2))
   )
 )
)
 (vl-load-com)
 (if (= (getvar "tilemode") 0)
   (if (= (getvar "cvport") 1)
     (if (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil)
       (if (/= 1 (logand 1 (cdr (assoc 90 (entget (setq ent (ssname ss 0)))))))
         (printscale)
         (princ "\n Command not allowed in perspective view.")
       )
       (princ " No viewport found.")
     )
     (progn
       (setq ent (vlax-vla-object->ename
                   (vla-get-activepviewport
                     (vla-get-activedocument (vlax-get-acad-object)))))
       (if (/= 1 (logand 1 (cdr (assoc 90 (entget ent)))))
         (printscale)
         (princ "\n Command not allowed in perspective view.")
       )
     )
   )
   (princ "\n Command not allowed unless TILEMODE is set to 0.") 
 )
 (princ)
)
;;; return viewport scale if allowed else nil
(defun getvpscale1 (/ ss ent)
 (vl-load-com)
 (if (= (getvar "tilemode") 0)
   (if (= (getvar "cvport") 1)
     (if (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil)
       (if (/= 1 (logand 1 (cdr (assoc 90 (entget (setq ent (ssname ss 0)))))))
         (vla-get-customscale (vlax-ename->vla-object ent))
       )
     )
     (progn
       (setq ent (vlax-vla-object->ename
                   (vla-get-activepviewport
                     (vla-get-activedocument (vlax-get-acad-object)))))
       (if (/= 1 (logand 1 (cdr (assoc 90 (entget ent)))))
         (vla-get-customscale (vlax-ename->vla-object ent))
       )
     )
   )
 )
)
;;; return viewport scale if allowed else nil
;;; no support for perspective view
(defun getvpscale2 (/ ss vpno vpsc)
 (if (= (getvar "tilemode") 0)
   (if (= (getvar "cvport") 1)
     (if (/= (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) nil)
       (progn
         (setq vpno (cdr (assoc 69 (entget (ssname ss 0)))))
         (command "_.mspace")
         (setvar "cvport" vpno)
         (setq vpsc (caddr (trans '(0 0 1) 2 3)))
         (command "_.pspace")
         vpsc
       )
     )
     (caddr (trans '(0 0 1) 2 3))
   )
 )
)
;;; return viewport scale
;;; no support for viewports with clipping boundary
;;; no support for perspective view
(defun getvpscale3(/ vpno vpsc)
 (setq vpno (cdr (assoc 69 (entget (car (entsel))))))
 (command "mspace")
 (setvar "cvport" vpno)
 (setq vpsc (caddr (trans '(0 0 1) 2 3)))
 (command "pspace")
 vpsc
)
;;; return scale in active viewport
;|
(caddr (trans '(0 0 1) 2 3))
|;

 

 

Do I need to go through all this to get the viewport scale??

Link to comment
Share on other sites

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • woodman78

    13

  • David Bethel

    8

  • rkmcswain

    3

  • alanjt

    3

Top Posters In This Topic

Posted Images

Another, for those with an aversion to VL...

 

(defun VPScale ( / e )
 (cond
   (
     (and (setq e (car (entsel)))
          (eq "VIEWPORT" (cdr (assoc 0 (setq e (entget e)))))
     )
     (/ (cdr (assoc 45 e)) (cdr (assoc 41 e)))
   )
 )
)

Link to comment
Share on other sites

Thanks Guys,

This is what I have so far for a lisp that I want to use to load dim and leader styles and set a default based on the viewport scale.

 
(defun c:dim_Load(/e b c)
(command "_.insert" "CCC_Drawing_Dim_Leader_Styles=" nil)
(command "_.purge" "_b" "CCC_Drawing_Dim_Leader_Styles" "_n")
(progn
(cond
   (
     (and (setq e (car (entsel)))
          (eq "VIEWPORT" (cdr (assoc 0 (setq e (entget e)))))
     )
     (/ (cdr (assoc 45 e)) (cdr (assoc 41 e)))
   )
 )
)
(progn
   (cond
     ((= e 0.02)(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
     ((= e 0.04)(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
     ((= e 0.05)(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
     ((= e 0.1)(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
     ((= e 0.2)(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
     ((= e 0.4)(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
     ((= e 0.5)(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
     ((= e 0.(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
     ((= e 1)(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
     ((= e 2)(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
     ((= e 4)(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
     ((= e 5)(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
     ((= e (setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
     ((= e 10)(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
     ((= e 20)(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
     ((= e 40)(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
     ((= e 50)(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
     ((= e 100)(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
   )
)
(command "_.dimstyle" "r" b)
 
(princ)
)

 

I am getting a few errors about "too few arguements". Can someone point out where the error is? Thanks

Link to comment
Share on other sites

woodman78,

 

You did it again, Slow down!

;
You have this.
(defun c:dim_Load(/e b c)
;
Do this.
(defun c:dim_Load[color=red] (/[/color][color=red] e[/color] b c)
;

 

Leave a space between the slash & the e.

I mentioned to you several times before. You really need to practice better formatting.

 

Another thing and it has nothing to do with this problem.

Get rid of progn, Its not needed if you are using cond. If it was if, Thats another story.

[color=red](progn[/color]
[color=red][color=black](cond[/color]
[color=black]([/color]
[color=black]  (and (setq e (car (entsel)))[/color]
[color=black]       (eq "VIEWPORT" (cdr (assoc 0 (setq e (entget e)))))[/color]
[color=black]  )[/color]
[color=black]  (/ (cdr (assoc 45 e)) (cdr (assoc 41 e)))[/color]
[color=black])[/color]
[color=black])[/color]
[/color][color=red])[/color]
[color=red](progn[/color]
   (cond
     ((= e 0.02)(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
     ((= e 0.04)(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
     ((= e 0.05)(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
     ((= e 0.1)(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
     ((= e 0.2)(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
     ((= e 0.4)(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
     ((= e 0.5)(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
     ((= e 0.(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
     ((= e 1)(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
     ((= e 2)(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
     ((= e 4)(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
     ((= e 5)(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
     ((= e (setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
     ((= e 10)(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
     ((= e 20)(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
     ((= e 40)(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
     ((= e 50)(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
     ((= e 100)(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
   )
[color=red])[/color]

Edited by The Buzzard
Link to comment
Share on other sites

(/ (cdr (assoc 45 e)) (cdr (assoc 41 e)))

)

)

)[/code]

 

Maybe group 40 in lieu on 45?

 

(trans '(0 0 1) 2 3)

 

Watch out for the 2 parameter if the TARGET and CAMERA sysvars are not WCS oriented '(0 0 0) vs '(0 0 1)

 

(command "_.MSPACE" "_.DVIEW" "" "_PO" '(2 3 4) '(4 5 6) "")

 

-David

Link to comment
Share on other sites

I have been trying to see if the variable e is set to the viewport scale. I've added an alert box to display value of e but I keep getting errors.

 

 
(defun c:dim_Load(/ e b c)
(command "_.insert" "CCC_Drawing_Dim_Leader_Styles=" nil)
(command "_.purge" "_b" "CCC_Drawing_Dim_Leader_Styles" "_n")
(cond
   (
     (and (setq e (car (entsel)))
          (eq "VIEWPORT" (cdr (assoc 0 (setq e (entget e)))))
     )
     (/ (cdr (assoc 40 e)) (cdr (assoc 41 e)))
   )
 )
 (alert "Viewport Scale"e)
   (cond
     ((= e 0.02)(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
     ((= e 0.04)(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
     ((= e 0.05)(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
     ((= e 0.1)(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
     ((= e 0.2)(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
     ((= e 0.4)(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
     ((= e 0.5)(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
     ((= e 0.(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
     ((= e 1)(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
     ((= e 2)(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
     ((= e 4)(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
     ((= e 5)(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
     ((= e (setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
     ((= e 10)(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
     ((= e 20)(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
     ((= e 40)(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
     ((= e 50)(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
     ((= e 100)(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
   )
(command "_.dimstyle" "r" b)
 
(princ)
)

Link to comment
Share on other sites

I don't quite understand what you are trying to do but:

 

[b][color=BLACK]([/color][/b]defun c:db-vps [b][color=FUCHSIA]([/color][/b]/ cv ss en ed ys vs[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]/= [b][color=MAROON]([/color][/b]getvar [color=#2f4f4f]"TILEMODE"[/color][b][color=MAROON])[/color][/b] 0[b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]setvar [color=#2f4f4f]"TILEMODE"[/color] 0[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]/= [b][color=MAROON]([/color][/b]getvar [color=#2f4f4f]"CVPORT"[/color][b][color=MAROON])[/color][/b] 1[b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]progn
        [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 [color=#2f4f4f]"VIEWPORT"[/color][b][color=RED])[/color][/b][b][color=RED]([/color][/b]cons 69 [b][color=PURPLE]([/color][/b]getvar [color=#2f4f4f]"CVPORT"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
              en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b]
              ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
              cv [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 69 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
              ys [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 41 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_.MSPACE"[/color][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]setvar [color=#2f4f4f]"CVPORT"[/color] cv[b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]setq vs [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"VIEWSIZE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nThe VIEWPORT Scale is 1 = "[/color] [b][color=BLUE]([/color][/b]rtos [b][color=RED]([/color][/b]/ vs ys[b][color=RED])[/color][/b] 2 4[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nThe VIEWPORT Scale is "[/color] [b][color=BLUE]([/color][/b]rtos [b][color=RED]([/color][/b]/ ys vs[b][color=RED])[/color][/b] 2 8[b][color=BLUE])[/color][/b] [color=#2f4f4f]" = 1"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]alert [color=#2f4f4f]"\nYour Are Not In An Active MODELSPACE Viewport"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

(/ dxf40 dxf41) only gives you the x vs y scale of the viewport. Not much use.

 

 

And if you're going to use a comparison, you need to use (equal) with fuzz. -David

Link to comment
Share on other sites

I have been trying to see if the variable e is set to the viewport scale. I've added an alert box to display value of e but I keep getting errors.

 

 
(defun c:dim_Load(/ e b c)
(command "_.insert" "CCC_Drawing_Dim_Leader_Styles=" nil)
(command "_.purge" "_b" "CCC_Drawing_Dim_Leader_Styles" "_n")
(cond
(
(and (setq e (car (entsel)))
(eq "VIEWPORT" (cdr (assoc 0 (setq e (entget e)))))
)
(/ (cdr (assoc 40 e)) (cdr (assoc 41 e)))
)
)
(alert "Viewport Scale"e)
(cond
((= e 0.02)(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
((= e 0.04)(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
((= e 0.05)(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
((= e 0.1)(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
((= e 0.2)(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
((= e 0.4)(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
((= e 0.5)(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
((= e 0.(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
((= e 1)(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
((= e 2)(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
((= e 4)(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
((= e 5)(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
((= e (setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
((= e 10)(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
((= e 20)(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
((= e 40)(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
((= e 50)(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
((= e 100)(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
)
(command "_.dimstyle" "r" b)

(princ)
)

 

I am not sure exactly what your doing either. I do know your not getting that argument error as before. The program was looking for something I think was the dimstyle which you did not supply, So checking any further was limited.

Link to comment
Share on other sites

Surely that would be just getting the Viewport size ratio, not the scale?

 

 

AhaH I see they have added 45 ( the viewsize in mspace ).

 

     A U T O C A D (R)
Copyright (c) 1982-1998  Autodesk, Inc.  All Rights Reserved.
Release 14.01 (4/21/98) Microsoft Windows NT Version 5.1 (x86)
Entity Information ....

Select objects: 1 found

Select objects:      <RO> Entity Name - (-1 . <Entity name: 4e21618>)
   <RO> Entity Type - (0 . "VIEWPORT")
        <RO> Handle - (5 . "223")
      <RO> SubClass - (100 . "AcDbEntity")
        Paper Space - (67 . 1)
              Layer - (8 . "PLOT")
              Color - (62 . 6)
      <RO> SubClass - (100 . "AcDbViewport")
        First Point - (10 53.5 59.75 0.0)
         <RO> Width - (40 . 35.0)
        <RO> Height - (41 . 23.5)
        <RO> Status - (68 . 6)
            <RO> ID - (69 . 5)
         <RO> APPID - (-3 ("ACAD" (1000 . "MVIEW") (1002 . "{") (1070 . 16) 
(1010 0.0 0.0 0.0) (1010 0.0 0.0 1.0) (1040 . 0.0) (1040 . 585.0) (1040 . 
339.638) (1040 . 221.5) (1040 . 50.0) (1040 . 0.0) (1040 . 0.0) (1070 . 0) 
(1070 . 50) (1070 . 1) (1070 . 1) (1070 . 1) (1070 . 0) (1070 . 0) (1070 . 1) 
(1040 . 0.0) (1040 . 0.0) (1040 . 0.0) (1040 . 1.0) (1040 . 1.0) (1040 . 12.0) 
(1040 . 12.0) (1070 . 1) (1002 . "{") (1003 . "1D") (1003 . "2D") (1003 . 
"FS-EL") (1003 . "FS-DIM") (1003 . "FS-PL") (1003 . "FS-GA") (1003 . "FS-") 
(1003 . "FS-SLAB") (1003 . "CL") (1003 . "FS-WB") (1003 . "FS-PVC") (1003 . 
"FS-ST") (1003 . "FS-RF") (1003 . "200") (1003 . "200-2D-ONLY") (1003 . "204") 
(1003 . "204-2D-ONLY") (1003 . "206") (1003 . "206-2D-ONLY") (1003 . 
"206-KCL-DO") (1003 . "206-KCL-DS") (1003 . "400") (1003 . "406") (1003 . 
"450") (1003 . "460") (1003 . "470") (1003 . "480") (1003 . "490") (1003 . 
"350") (1003 . "201") (1003 . "201-2D-ONLY") (1003 . "202") (1003 . 
"202-2D-ONLY") (1003 . "700") (1003 . "700-3D-ONLY") (1003 . "300") (1003 . 
"306") (1003 . "205") (1002 . "}") (1002 . "}")))

 

A R14 DXF Dump

 

-David

Link to comment
Share on other sites

(defun _VPScale (obj)
 (cond
   ((eq (type obj) 'VLA-OBJECT) (/ 1. (vla-get-customscale obj)))
   ((eq (type obj) 'ENAME) ((lambda (e) (/ (cdr (assoc 45 e)) (cdr (assoc 41 e)))) (entget obj)))
 )
)

Link to comment
Share on other sites

Guys I am trying to get the viewport scale and based on that set a dimstyle and leader style to be current. I seem to be getting a bit lost though. Can anyone help?

 

 
(defun c:vpdisp (/ cv ss en ed ys vs vps b c)
(command "_.insert" "CCC_Drawing_Dim_Leader_Styles=" nil)
(command "_.purge" "_b" "CCC_Drawing_Dim_Leader_Styles" "_n")
        (command "_.MSPACE")
 (if (/= (getvar "TILEMODE") 0)
     (setvar "TILEMODE" 0))
 (if (/= (getvar "CVPORT") 1)
     (progn
        (setq ss (ssget "X" (list (cons 0 "VIEWPORT")(cons 69 (getvar "CVPORT"))))
              en (ssname ss 0)
              ed (entget en)
              cv (cdr (assoc 69 ed))
              ys (cdr (assoc 41 ed)))
        (command "_.PSPACE")
        (setvar "CVPORT" cv)
        (setq vs (getvar "VIEWSIZE")
    vps (rtos (/ vs ys) 2 4))
        (princ (strcat "\nThe VIEWPORT Scale is 1 = " vps)))
   (cond
     ((= vps 0.02)(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
     ((= vps 0.04)(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
     ((= vps 0.05)(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
     ((= vps 0.1)(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
     ((= vps 0.2)(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
     ((= vps 0.4)(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
     ((= vps 0.5)(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
     ((= vps 0.(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
     ((= vps 1)(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
     ((= vps 2)(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
     ((= vps 4)(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
     ((= vps 5)(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
     ((= vps (setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
     ((= vps 10)(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
     ((= vps 20)(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
     ((= vps 40)(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
     ((= vps 50)(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
     ((= vps 100)(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
   )
(command "_.dimstyle" "r" b)
     (alert "\nYour Are Not In An Active MODELSPACE Viewport"))
 (prin1))

Link to comment
Share on other sites

I have been looking at this over the last few days and I keep getting syntax errors. Can anyone help with it??

 

 
(defun c:vpdisp (/ cv ss en ed ys vs vps b c)
(command "_.insert" "CCC_Drawing_Dim_Leader_Styles=" nil)
(command "_.purge" "_b" "CCC_Drawing_Dim_Leader_Styles" "_n")
        (command "_.MSPACE")
 (if (/= (getvar "TILEMODE") 0)
     (setvar "TILEMODE" 0))
 (if (/= (getvar "CVPORT") 1)
     (progn
        (setq ss (ssget "X" (list (cons 0 "VIEWPORT")(cons 69 (getvar "CVPORT"))))
              en (ssname ss 0)
              ed (entget en)
              cv (cdr (assoc 69 ed))
              ys (cdr (assoc 41 ed)))
        (command "_.PSPACE")
        (setvar "CVPORT" cv)
        (setq vs (getvar "VIEWSIZE"))
        (setq vps (rtos (/ vs ys) 2 4))
     (alert "\nYour Are Not In An Active MODELSPACE Viewport")
   (cond
     ((= vps 0.02)(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
     ((= vps 0.04)(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
     ((= vps 0.05)(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
     ((= vps 0.1)(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
     ((= vps 0.2)(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
     ((= vps 0.4)(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
     ((= vps 0.5)(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
     ((= vps 0.(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
     ((= vps 1)(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
     ((= vps 2)(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
     ((= vps 4)(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
     ((= vps 5)(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
     ((= vps (setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
     ((= vps 10)(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
     ((= vps 20)(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
     ((= vps 40)(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
     ((= vps 50)(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
     ((= vps 100)(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
   ))
 (prin1))

Link to comment
Share on other sites

Generally speaking, syntax errors are easy to find/fix.

If you are editing in the VLIDE, run the "Check text in Editor" command. This will tell you if there is an error in your static code.

If it isn't apparent, then put your cursor next to the opening parenthesis [next to the (defun...], and double click.

Does all your code highlight? If not, there is your problem - the parenthesis do not match.

In this case, it looks like you are simply missing one more closing parenthesis at the end of the file.

Link to comment
Share on other sites

Thanks for the tips. To be honest I have kind of steared clear of the vlide because I have always found it difficult to use. I took your advice and made good progress though. I'll refer my errors to vlide first in future. This is what I have so far:

 

 
(defun c:vpdisp (/ cv ss en ed ys vs vps b c)
(command "_.insert" "CCC_Drawing_Dim_Leader_Styles=" nil)
(command "_.purge" "_b" "CCC_Drawing_Dim_Leader_Styles" "_n")
        (command "_.MSPACE")
 (if (/= (getvar "TILEMODE") 0)
     (setvar "TILEMODE" 0))
 (if (/= (getvar "CVPORT") 1)
     (progn
        (setq ss (ssget "X" (list (cons 0 "VIEWPORT")(cons 69 (getvar "CVPORT"))))
              en (ssname ss 0)
              ed (entget en)
              cv (cdr (assoc 69 ed))
              ys (cdr (assoc 41 ed)))
        (command "_.PSPACE")
        ;(setvar "CVPORT" cv)
        (setq vs (getvar "VIEWSIZE"))
        (setq vps (rtos (/ vs ys) 2 4))
;(princ (strcat "\nThe VIEWPORT Scale is 1 = " vps))
         ;(setq vps "0.8")
     ;(alert "\nYour Are Not In An Active MODELSPACE Viewport")
   )
 )
 (cond
     ((= vps "0.02")(setq b "CCC_1_50000_Dims")(setq c "CCC_Leader_1_50000"))
     ((= vps "0.04")(setq b "CCC_1_25000_Dims")(setq c "CCC_Leader_1_25000"))
     ((= vps "0.05")(setq b "CCC_1_20000_Dims")(setq c "CCC_Leader_1_20000"))
     ((= vps "0.1")(setq b "CCC_1_10000_Dims")(setq c "CCC_Leader_1_10000"))
     ((= vps "0.2")(setq b "CCC_1_5000_Dims")(setq c "CCC_Leader_1_5000"))
     ((= vps "0.4")(setq b "CCC_1_2500_Dims")(setq c "CCC_Leader_1_2500"))
     ((= vps "0.5")(setq b "CCC_1_2000_Dims")(setq c "CCC_Leader_1_2000"))
     ((= vps "0.8")(setq b "CCC_1_1250_Dims")(setq c "CCC_Leader_1_1250"))
     ((= vps "1")(setq b "CCC_1_1000_Dims")(setq c "CCC_Leader_1_1000"))
     ((= vps "2")(setq b "CCC_1_500_Dims")(setq c "CCC_Leader_1_500"))
     ((= vps "4")(setq b "CCC_1_250_Dims")(setq c "CCC_Leader_1_250"))
     ((= vps "5")(setq b "CCC_1_200_Dims")(setq c "CCC_Leader_1_200"))
     ((= vps "8")(setq b "CCC_1_125_Dims")(setq c "CCC_Leader_1_125"))
     ((= vps "10")(setq b "CCC_1_100_Dims")(setq c "CCC_Leader_1_100"))
     ((= vps "20")(setq b "CCC_1_50_Dims")(setq c "CCC_Leader_1_50"))
     ((= vps "40")(setq b "CCC_1_25_Dims")(setq c "CCC_Leader_1_25"))
     ((= vps "50")(setq b "CCC_1_20_Dims")(setq c "CCC_Leader_1_20"))
     ((= vps "100")(setq b "CCC_1_10_Dims")(setq c "CCC_Leader_1_10"))
   )
 (command "_.dimstyle" "r" b)
 (prin1))

 

The problem I have is that the viewport scale isn't being calculated correctly and so no dimension is being set. I set the vps variable to be a standard value and it sets the dimstyle fine. I looked at Alanjt's method for getting viewport scale but I don't know how to incorporate it. I keep getting errors trying to put it into the code.

 

Can anyone help with the viewport scale calc?

 

Thanks.

Link to comment
Share on other sites

try

 

(equal (/ vs ys) 0.02 1e-2)
or
(= vps "0.0200")

 

for each value.

 

Make sure DIMZIN is set 0 if you use the string comparison. -David

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