;;; ;;; Program: Simple AR3 Units to Pixel converter (uses DPI) ;;; Author: Ivan Kos ;;; Last edited: 05.april.2003 14:09 ;;; You can contact me at vizikos@email.si ;;; (defun C:DPI() ;;(progn (setq oldCmdEcho (getvar "cmdecho")) ;save command echo mode (princ "\nAuthor: Ivan Kos\n") ;;check if ar3 is loaded (setq acadver (substr (getvar "acadver") 1 2)) ;detect AutoCAD 2000 (version is "13", "14", or "15") (setq ar3exist nil) ;ar3exist is whether or not "accuren3_*.arx" was loaded at the start or not. (cond ((= acadver "15") (progn (foreach n (arx) (if (= n "accuren3_2000.arx") (setq ar3exist T))) ;pretty basic code to find "accuren3_2000.arx" in the (arx) list. (if (not ar3exist) (princ "\nPlease load Accurender first.")) ;; (if (not ar3exist) (arxload "accuren3_2000.arx")) ;load "accuren3_2000.arx" if not loaded already (AutoCAD 2000,2000i,2002) ) ) ((= acadver "14") (progn (foreach n (arx) (if (= n "accuren3_r14.arx") (setq ar3exist T))) ;pretty basic code to find "accuren3_r14.arx" in the (arx) list. (if (not ar3exist) (princ "\nPlease load Accurender first.")) ;; (if (not ar3exist) (arxload "accuren3_r14.arx")) ;load "accuren3_r14.arx" if not loaded already (AutoCAD R14) ) ) (T (progn (foreach n (arx) (if (= n "accuren3_r13c4.arx") (setq ar3exist T))) ;pretty basic code to find "accuren3_r13c4.arx" in the (arx) list. (if (not ar3exist) (princ "\nPlease load Accurender first.")) ;; (if (not ar3exist) (arxload "accuren3_r13c4.arx")) ;load "accuren3_r13c4.arx" if not loaded already (AutoCAD r13) ) ) ) (if (/= ar3exist nil) (progn ;;get Inches or Meters ;; (initget "Inch Meter") ;; (setq InchMeter (getkword "\nUnits [Inch/Meter] : ")) ;; (if (not InchMeter) ;; (progn ;; (setq InchMeter "Inch") ;; ) ;; ) ;;you can also use AR3 units (setq iUnits (ar3_getvar 1001)) (if (= iUnits -1) ;ar3 not yet run for the first time on this DWG (progn ;;you can set your default unit or you can write a comment ;; (princ "\nSetting AR3 units to inches.") ;replace if needed ;; (ar3_setvar 1001 3) ;set unit to inch ;you can set the default value yourself (see the table below) (princ "\nYou must start Accurender at least once before starting this program.") ) (progn ;;get factor meters=>inches (setq dFactor 1) ; inches ;; (if (= InchMeter "Meter") (setq dFactor (/ 1 0.0254)) ) ; meters ;; (princ "\ndFactor=") ;; (princ dFactor) ;;You can also use AR3 units (if (= iUnits 0) (progn (setq dFactor (/ 1 0.0254)) (princ "\nAR3 Unit=meter") )) ; meters ;;values 1 and 2 are switched (typing mistake in "AR3 API.doc") (if (= iUnits 1) (progn (setq dFactor (/ 1 25.4)) (princ "\nAR3 Unit=millimeter") )) ; millimeters (if (= iUnits 2) (progn (setq dFactor (/ 1 2.54)) (princ "\nAR3 Unit=centimeter") )) ; centimeters (if (= iUnits 3) (progn (setq dFactor 1) (princ "\nAR3 Unit=inch") )) ; inches (if (= iUnits 4) (progn (setq dFactor (/ 1 12)) (princ "\nAR3 Unit=foot") )) ; feet ;;get DPI (setq DPI 0) (while (zerop DPI) (progn (setq DPI (getint "\nEnter DPI <200>: ")) (if (not DPI) (setq DPI 200)) (if (zerop DPI) (princ "\nDPI can be small, but not zero.")) );progn );while ;;get SizeX (setq SizeX 0) (while (zerop SizeX) (progn (setq SizeX (getreal "\nEnter Size X <10.0>: ")) (if (not SizeX) (setq SizeX 10.0)) (if (zerop SizeX) (princ "\nSize X can be small, but not zero.")) );progn );while ;;get SizeY (setq SizeY 0) (while (zerop SizeY) (progn (setq SizeY (getreal "\nEnter Size Y <8.0>: ")) (if (not SizeY) (setq SizeY 8.0)) (if (zerop SizeY) (princ "\nSize Y can be small, but not zero.")) );progn );while ;;calculate X (setq iResolutionX (* DPI SizeX)) (setq iResolutionX (* iResolutionX dFactor)) (setq iResolutionX (fix iResolutionX)) (princ "\n Resolution X=") (princ iResolutionX) ;;calculate Y (setq iResolutionY (* DPI SizeY)) (setq iResolutionY (* iResolutionY dFactor)) (setq iResolutionY (fix iResolutionY)) (princ "\n Resolution Y=") (princ iResolutionY) ;;ar3 allows values up to 16000 for X and Y (if (or (> iResolutionX 16000) (> iResolutionY 16000)) (progn (if (> iResolutionX 16000) (progn (setq maxX (/ 16000 DPI dFactor)) (princ "\nResolution X is larger than 16000. Try reducing Size X(max ") (princ maxX) (princ ").") ) ) (if (> iResolutionY 16000) (progn (setq maxY (/ 16000 DPI dFactor)) (princ "\nResolution Y is larger than 16000. Try reducing Size Y(max ") (princ maxY) (princ ").") ) ) (princ "\n Program cancelled.") );progn (progn ;;write to ar3 (initget "Yes No") (setq WriteAR3 (getkword "\nWrite the result to AR3 ? [Yes/No] ")) (if (not WriteAR3) (progn (setq WriteAR3 "Yes") ) ) ;;set values to AR3 Raytrace settings (if (= WriteAR3 "Yes") (progn (setq renderDestination (ar3_getvar 1300)) (if (= renderDestination 10240) (progn (princ "\nSwitching AR3 from rendering to the AutoCAD Viewport to rendering to the WalkAbout Window.") (ar3_setvar 1300 2048) ;set render to WalkAbout Window (ar3_setvar 1301 iResolutionX) ;set resolution X (ar3_setvar 1302 iResolutionY) ;set resolution Y ) (progn (ar3_setvar 1301 iResolutionX) ;set resolution X (ar3_setvar 1302 iResolutionY) ;set resolution Y ) );if (= renderDestination 10240) ) );if (= WriteAR3 "Yes") );progn );if (or (> iResolutionX 16000) (> iResolutionY 16000)) );progn );if (= iUnits -1) ;ar3 not yet run for the first time on this DWG );progn );if (/= ar3exist nil) (setvar "cmdecho" oldCmdEcho) ;restore command echo mode ;;The end (princ) ) ;;;1300 Raytrace, Flags Integer 2028 -- WalkAbout Window ;;; 10240 -- viewport ;;;1301 Raytrace X Resolution Integer -1 -- viewport ;;;1302 Raytrace Y Resolution Integer -1 -- viewport ;;;1001 Model Scale Type Integer 0 -- meters ;;; 1 -- centimeters ;;; 2 -- millimeters ;;; 3 -- inches ;;; 4 -- feet