Author Topic: How to calculate magnification zoom in viewport  (Read 6103 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How to calculate magnification zoom in viewport
« on: June 28, 2012, 05:53:10 AM »
for scale 1:100
how to calculate magnification
Code: [Select]
(vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point mp) magnification)
Thanks

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: How to calculate magnification zoom in viewport
« Reply #1 on: June 28, 2012, 06:44:00 AM »
Use the ZoomCenter method with any arbitrary zoom magnification to position the objects in the Viewport, then set the CustomScale property of the Viewport to obtain the correct scale (or, in your case with a scale of 1:100, you can use the StandardScale property with the acVp1_100 enum).

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to calculate magnification zoom in viewport
« Reply #2 on: June 28, 2012, 07:02:27 AM »
But not working, There is something missed
Code: [Select]
(setq scl (cond ((getint (strcat "\nWhat is Viewport Scale 1: <" (itoa (setq scl (cond (scl) (50)))) ">: " ))) (scl)))
(setq VPDoc (vla-get-PaperSpace doc))
(setq VPp (vlax-3D-point (getpoint "\nSelect Point for Viewport")))
(setq VP (vla-AddPViewport  VPDoc VPp (/ (- (car p2) (car p1)) scl) (/ (- (cadr p2) (cadr p1)) scl)))
(vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point mp) 1)
(vla-put-StandardScale VP (* 1000 scl))
(vla-put-customscale VP (* 1000 scl))

ribarm

  • Gator
  • Posts: 3282
  • Marko Ribar, architect
Re: How to calculate magnification zoom in viewport
« Reply #3 on: June 28, 2012, 07:46:43 AM »
Here is for model space - you must measure active AutoCAD with area on your monitor...

Code: [Select]
(vl-load-com)

(defun magnif ( / proportion wid magnification )
  (initget 6)
  (setq proportion (getreal "\nEnter proportion ratio (1:100=0.01) <0.01> : "))
  (if (null proportion) (setq proportion 0.01))
  (initget 6)
  (setq wid (getreal "\nEnter with of screen active AutoCAD area in cm <36.0 cm> : "))
  (if (null wid) (setq wid 36.0))
  (vl-cmdf "_.zoom" "w" '(0.0 0.0 0.0) (list wid 0.0 0.0))
  (setq magnification (* (getvar 'viewsize) (/ 1.0 proportion)))
  (vl-cmdf "_.zoom" "p")
  magnification
)

(defun c:zoomratio ( / mp )
  (setq mp (getpoint "\nPick center point for zoom : "))
  (vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point mp) (magnif))
  (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
(princ)
)

M.R.

Supose you can do the same for paperspace viewport (I think measure VP width in cm)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to calculate magnification zoom in viewport
« Reply #4 on: June 28, 2012, 07:57:53 AM »
try to get some info from here
1. draw closed object over viewport
2. type det
3. select viewport
4. select object
5. pick point and scale
works only with world ucs
kruuger

jvillarreal

  • Bull Frog
  • Posts: 332
Re: How to calculate magnification zoom in viewport
« Reply #5 on: June 28, 2012, 09:21:06 AM »
You should use a combination of MP's VPCORDS function and Gile's PCS2WCS function.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to calculate magnification zoom in viewport
« Reply #6 on: June 30, 2012, 09:48:19 AM »
you must measure active AutoCAD with area on your monitor...
How to measure this area?

Edit:
Is it (getvar "screensize")

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to calculate magnification zoom in viewport
« Reply #7 on: June 30, 2012, 09:51:14 AM »
Is this solution good?
 
Code: [Select]
  (vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point mp) 1.0)
  (vl-cmdf "_.zoom" SCL)
  (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
  ;(vla-put-StandardScale VP (/ 1.0 sc))
  ;(vla-put-customscale VP (/ 1.0 sc))

ribarm

  • Gator
  • Posts: 3282
  • Marko Ribar, architect
Re: How to calculate magnification zoom in viewport
« Reply #8 on: June 30, 2012, 09:55:08 AM »
You take real tape with measurments (cm), and measure width of active model space viewport, or if you are in paper space, you measure active viewport and apply the code with active MSPACE (viewport)... The result is scale 1:100 on the screen (100 dwg units = 100 cm = 1 m => 1:100 (1 cm on screen)...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to calculate magnification zoom in viewport
« Reply #9 on: June 30, 2012, 10:29:11 AM »
...
The result is scale 1:100 on the screen (100 dwg units = 100 cm = 1 m => 1:100 (1 cm on screen)...
M.R.

I am working in mm so
(100 dwg units = 10 cm = 0.1 m => 1:10 (0.1 cm on screen)
Is it correct?

ribarm

  • Gator
  • Posts: 3282
  • Marko Ribar, architect
Re: How to calculate magnification zoom in viewport
« Reply #10 on: June 30, 2012, 11:03:25 AM »
...
The result is scale 1:100 on the screen (100 dwg units = 100 cm = 1 m => 1:100 (1 cm on screen)...
M.R.

I am working in mm so
(100 dwg units = 10 cm = 0.1 m => 1:10 (0.1 cm on screen)
Is it correct?

No, this is correct :
(100 dwg units = 10 cm = 0.1 m => 1:100 (0.1 cm on screen)
(100 dwg units = 10 cm = 0.1 m => 1:10 (1 cm on screen)

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3282
  • Marko Ribar, architect
Re: How to calculate magnification zoom in viewport
« Reply #11 on: June 30, 2012, 11:17:20 AM »
I think that my code is confusing you, for you are working in mm...

So the code should be :

Code: [Select]
(vl-load-com)

(defun magnif ( / proportion wid magnification )
  (initget 6)
  (setq proportion (getreal "\nEnter proportion ratio (1:100=0.01) <0.01> : "))
  (if (null proportion) (setq proportion 0.01))
  (initget 6)
  (setq wid (getreal "\nEnter with of screen active AutoCAD area in cm <360 mm> : "))
  (if (null wid) (setq wid 360))
  (vl-cmdf "_.zoom" "w" '(0.0 0.0 0.0) (list wid 0.0 0.0))
  (setq magnification (* (getvar 'viewsize) (/ 1.0 proportion)))
  (vl-cmdf "_.zoom" "p")
  magnification
)

(defun c:zoomratio ( / mp )
  (setq mp (getpoint "\nPick center point for zoom : "))
  (vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point mp) (magnif))
  (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
(princ)
)

Note : You must measure width of active viewport in mm - this is your measurment setting...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to calculate magnification zoom in viewport
« Reply #12 on: June 30, 2012, 11:37:17 AM »
Is it mean for scale 1:100 we use wind 360mm?
so we can make relation like this

Code: [Select]
(setq scl (cond ((getint (strcat "\nWhat is Viewport Scale 1: <" (itoa (setq scl (cond (scl) (50)))) ">: " ))) (scl)))
(setq wid (* 3.6 scl))
(vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point mp) (* (getvar 'viewsize) scl))


Another solution
Could we do this
Code: [Select]
(setq sc (cond ((getint (strcat "\nWhat is Viewport Scale 1: <" (itoa (setq sc (cond (sc) (50)))) ">: " ))) (sc)))
(setq scl (strcat (RTOS (/ 1.0 SC)) "xp"))
...
(vl-cmdf "_.zoom" SCL)

Thanks for your quick reply

ribarm

  • Gator
  • Posts: 3282
  • Marko Ribar, architect
Re: How to calculate magnification zoom in viewport
« Reply #13 on: June 30, 2012, 11:52:34 AM »
Look HasanCAD, my settings of AutoCAD active model space viewport measured on my monitor with real tape is 36 cm, and therefore I put that value into my code... This can be modified to suite any one's needs, as there are various types of monitors, and settings of AutoCAD may also vary... So consider to implement your standard into code measured with measurments that you use (mm) - someone maybe use inches, so he/she must measure width in inches and modify standard into the code... My code is made to consider all possible ratio proportions (100:1; 10:1, 2:1, 1:1, 1:2, 1:10, 1:100, 1:1000, ...) so when executing the code my set standard was as you wanted 1:100 (0.01), so be careful when entering ratios as screen representation of proportions for sure is dependable on what user enter...

Test my revised code for your needs and enter width of viewport in your measurment system (mm)... Representation on screen should meet required scale ratio that you enter... So 100 dwg=10 cm=0.1 m=100 mm => width in mm, 1:10 => 100 mm in real world will become 10 times smaller 10 mm = 1 cm...

This should be true on screen...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: How to calculate magnification zoom in viewport
« Reply #14 on: July 02, 2012, 07:47:41 AM »
To get the current scale use:
Code - Auto/Visual Lisp: [Select]
  1. (caddr (trans '(0 0 1) 2 3))
the rest as mentioned

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18