Scale LISP

Scale LISP

Anonymous
Not applicable
8,053 Views
25 Replies
Message 1 of 26

Scale LISP

Anonymous
Not applicable

Hello all

 

This is my idea. You are at a layout and there is a viewport. Then you draw a line at paperspace of 10 units (mm) for example and you say it is 1 meter in real scale. So the lisp should display the scale. In this sample, it will prompt 1/100.

 

I ask for this because i usually work with rescaled drawings and the viewport scale is not the final scale.

 

Thanks.

0 Likes
Accepted solutions (1)
8,054 Views
25 Replies
Replies (25)
Message 2 of 26

cadffm
Consultant
Consultant
You really want a program that calculate 1000/10? If your plot-scale is 1:1.

You can use the quickcalc
http://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-0797E82E-FE80-43D6-8464-398725546A2A

Type on the length or use the object selection option, then calculate *10

Curious or missunderstood?

Sebastian

0 Likes
Message 3 of 26

cadffm
Consultant
Consultant
0 Likes
Message 4 of 26

Moshe-A
Mentor
Mentor

Casals,

 

in AutoCAD you draw your 2d/3d model in model space (always) at 1:1 scale, whereas in paper space you only put your title block also at 1:1 scale and set the plot scale for the viewport - are we agree with that?

 

in paper space you can measure any linear graphics seen from model space with DIST command and get the real (scaled) measurement. you can also use dimension commands to draw dimensions on paper space of object on model space.

 

Moshe

 

 

 

0 Likes
Message 5 of 26

Anonymous
Not applicable

Hi 

 

 

 

0 Likes
Message 6 of 26

Moshe-A
Mentor
Mentor

well, it's clear 'your' other peoples do not think about anyone beside them selves. they don't even mind or aware the damage they leave in drawings.

 

you can not fix the 'world'.

 

 

 

 

 

 

0 Likes
Message 7 of 26

Moshe-A
Mentor
Mentor

well, after more thoughts...are you familiar  with dimension line factor (dimlfac)?

then you could set some dimstyles with the appropriate dimlfac.

 

another tool is to create a special DIST command that make use of the current dimlfac

 

something like this called NDIST

 

enjoy

moshe

 

(defun c:ndist (/ prtm calc_angle_from_xy  ; local functions
		  dimlfac pt1 pt2)

 (defun prtm (lst)
  (foreach a lst (princ a))
 )

 (defun calc_angle_from_xy (/ cx hx)
  (setq cx (distance (list (car pt1) (cadr pt1)) (list (car pt2) (cadr pt2))))
  (setq hx (- (caddr pt2) (caddr pt1)))
  (atan (/ hx cx)) 
 )
  
 (setq dimlfac (getvar "dimlfac"))

 (if (and
       (setq pt1 (getpoint "\nSpecify first point: ")) 
       (setq pt2 (getpoint pt1 "\nSpecify first point: ")) 
     )
  (progn
   (prtm (list "\nDistance = " (rtos (* (distance pt1 pt2) dimlfac))
	       ",  Angle in XY plane = "   (angtos (angle pt1 pt2))
	       ",  Angle from XY plane = " (angtos (calc_angle_from_xy))
	 )
   )
	 
   (prtm (list  "\nDelta X = " (rtos (* (- (car   pt2) (car   pt1)) dimlfac))
	       ",  Detla Y = " (rtos (* (- (cadr  pt2) (cadr  pt1)) dimlfac))
	       ",  Delta Z = " (rtos (* (- (caddr pt2) (caddr pt1)) dimlfac))
	 )
   )
  ); progn
 ); if

 (princ)
) 
0 Likes
Message 8 of 26

Anonymous
Not applicable

Hello Moshe-A

I am not familiar with dimension line factor. I tried your tool and I think I dont know to use it.

 

My goal is:

1. Specify first and last points (parperspace). For example 10 units

2. Now you enter the real distance (model space). For example 1 meter

3. It prompts the final scale. In the example, 1/100.

 

Thanks.

0 Likes
Message 9 of 26

Moshe-A
Mentor
Mentor

Casals,

 

some how i now notice that the situation you are talking about is this:

model space units is in cm

paper space units is in mm

view port scale is 1:10

 

acutual drawing scale is at 1/100

is this right?

 

moshe

 

 

0 Likes
Message 10 of 26

Anonymous
Not applicable

Hello Moshe-A

 

The example i am talking is this.

model space units is in m (meters). An example 1 meter (1000 milimeters)

paper space units is in mm (milimeters) An example 10 milimeters

view port scale i think is not usefull because it's not real

 

So the final scale (mix between model and viewport strange scales), will be 1000/10--> 1/100

 

It is very easy to do once, but... in the same drawing 10 or 15 times with differents scales and many viewports in the same layout....my head explodes...

 

I expect you understand my example hehe..

Thanks.

0 Likes
Message 11 of 26

Moshe-A
Mentor
Mentor

hi,

 

sorry for this delay but i'm still at work so i will be here tonight and we will solve this

 

0 Likes
Message 12 of 26

maratovich
Advisor
Advisor

Like this ?

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 13 of 26

Moshe-A
Mentor
Mentor

@Anonymous,

 

although this not the way AutoDesk 'thought' us to use AutoCAD unfortunately many user do and this is a direct result of lowtech  AutoCAD course\training plus working without template or lack of  supervision at offices.

anyhow the paper space is totally unsynchronized with model space (there is a gap of 1000mm between them) but it works and the plot (plot scale 1=1) will come out ok.

 

the viewport scale by the way is:

for 1:100 is zoom 10xp

for 1:50   is zoom 20xp

for 1:25   is zoom 40xp

 

the mathematics here is simple 1000mm div by scale  (e.g 1000 : 100 = 10xp) 

 

now you have 2 options:

flow with it

or

scale down the layouts by 1/1000 (make in meters) than set the right scale for the viewports

e.g 1/100xp for 1:100, 1/50 for 1:50 and so on.

 

and remember that the plot scale should now be 1000=1

 

if you post an example dwg I will fix the first layout for you

 

Moshe

 


 

0 Likes
Message 14 of 26

Moshe-A
Mentor
Mentor

if you choose the second option then there is another issue i forgot to mention last night and it is linetypes\linetype scale but that also has solution.

 

0 Likes
Message 15 of 26

Anonymous
Not applicable

Hello Moshe-A

 

Yes i know how works scale in modelspace and paperspace if you work with meters.

I am trying to make the code on my own, but i am not very good at lisp. This is my code now (based on yours):

(defun c:ndist ()
       (setq pt1 (getpoint "\nSpecify first point: ")) 
       (setq pt2 (getpoint pt1 "\nSpecify second point: ")) 
	(setq ptt (getdist "\nSpecify real distance in meters: "))
	(setq pttx (* ptt 1000))
	(setq pttd (/ pttx pt2))
   	(prompt "Scale = 1/!pttd")
 (princ)
) 
0 Likes
Message 16 of 26

Moshe-A
Mentor
Mentor

to tell you the truth i do not understand to where are you going?

cause if you are in paper space and use dist command you will get the real measurement you need (also with dimensions)

under each viewport add a text to specify the scale.

 

does this solves you problem?

 

 

 

 

 

 

 

0 Likes
Message 17 of 26

Moshe-A
Mentor
Mentor

Casalas,

 

here is an extension to the previous lisp now called VPDIST cause it works only in paper space

the view port scale will show along the second prompt of 'dist' command.

it work only with rectangle viewports.

 

enjoy

moshe

 

 

 

(defun c:vpdist (/ prtm calc_angle_from_xy get_vp_scale ; local functions
		   p0 p1 ss0 ss1 i ename0 ename1 elist0 vpscale flag)

 (defun prtm (lst)
  (foreach a lst (princ a))
 )

 (defun calc_angle_from_xy (/ cx hx)
  (setq cx (distance (list (car p0) (cadr p0)) (list (car p1) (cadr p1))))
  (setq hx (- (caddr p1) (caddr p0)))
  (atan (/ hx cx)) 
 )
  
 (defun get_vp_scale (/ cen c40 c41 c45 pt0 pt1 ss1)
  (if (not (assoc '340 elist0))      ; only rectangle viewport allowed
   (progn 	   
    (setq cen (cdr (assoc '10 elist0)))
    (setq c40 (cdr (assoc '40 elist0)))
    (setq c41 (cdr (assoc '41 elist0)))
    (setq c45 (cdr (assoc '45 elist0)))
    (setq pt0 (list (- (car cen) (/ c40 2)) (- (cadr cen) (/ c41 2))))
    (setq pt1 (list (+ (car cen) (/ c40 2)) (+ (cadr cen) (/ c41 2))))

    (if (and
	 (setq ss1 (ssget "_c" pt0 pt1 (list '(0 . "line") (cons '410 (getvar "ctab")))))
	 (ssmemb ename1 ss1)
	)
     (/ c45 c41) ; return viewport scale
    ); if
   ); progn
  ); if
 ); get_vp_scale

  
 (setvar "tilemode" 0) ; switch to layout
 (command "_.pspace")  ; make sure in paper space

 (if (and
      (setq p0 (getpoint "\nSpecify first point: "))
      (setq p1 (getpoint p0 "\nSpecify second point: "))
     ) 
  (if (setq ss0 (ssget "_x" (list '(0 . "viewport") (cons '410 (getvar "ctab")))))
   (progn
    (command "._line" p0 p1 "")
    (setq ename1 (entlast))
    (setq i -1)
    (while (and (not flag)
		(setq ename0 (ssname ss0 (setq i (1+ i))))
	   )
     (setq elist0 (entget ename0))
     (if (> (cdr (assoc '69 elist0)) 1) ; skip main viewport
      (if (setq vpscale (get_vp_scale))
       (progn
        (prtm (list "\nDistance = " (rtos (* (distance p0 p1) vpscale))
	            ",  Angle in XY plane = "   (angtos (angle p0 p1))
	            ",  Angle from XY plane = " (angtos (calc_angle_from_xy))
	      )
        )
	 
        (prtm (list  "\nDelta X = "  (rtos (* (- (car   p1) (car   p0)) vpscale))
	             ",  Detla Y = " (rtos (* (- (cadr  p1) (cadr  p0)) vpscale))
	             ",  Delta Z = " (rtos (* (- (caddr p1) (caddr p0)) vpscale))
		     ",  Scale = 1:" (rtos (* vpscale 1000) 2 0)
	      )
        )

	(setq flag nil) ; stop while
       ); progn
      ); if
     ); if
    ); while
    (entdel ename1)  
   ); progn
  ); if  
 ); if
 
 (princ)
); c:ndist

 

 

Message 18 of 26

Moshe-A
Mentor
Mentor

Casals,

 

Attached ndist.lsp my last update. i have changed it again to NDIST cause now it will work in any space meaning if you invoke it in model space it would work like standard DIST command. 

it's now also support non rectangular viewports who basiclly contains straight lines.

 

enjoy

moshe

 

0 Likes
Message 19 of 26

Anonymous
Not applicable

Hello Moshe-A

 

Sorry for late, I have been very busy. I dont see your last attached lsp.

 

In general my idea is to specify the distance in paperspace (first part of the lisp that you have code) and then you write the real length, so the lisp will show the real scale (for special drawings like mine). If you dont understad, it doesnt matter, i am trying to make myself.

 

Thanks for the effort.

0 Likes
Message 20 of 26

maratovich
Advisor
Advisor

I asked you, did you see the video?

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes