My goal as follow:
I have 3d solid model in AutoCAD
output to 2D dimetric which know scale ratio by using flatshot
so later on easy for revising or re-editing
in my lisp routine, I prompt for user input on scale ratio options which are
1-half, 2-third, 3-quarter and "Other" scale (between 0 and 1) in av:getUserInput
although "Other" option works when user enter real number but I how can I re-display the real number next time user re-execute the command?
Sorry for long code, anyone help wound be thankful!
;;################################################;;
;; Lisp setup axonometric view point in 3d space ;;
;; with known scale ratio between 0 and 1.0 ;;
;; Phong Huynh ;;
;; avp.lsp ;;
;; ;;
;; Thanks for infomation of the follwing websites ;;
;; compuphase.com/axometr.htm ;;
;; en.wikipedia.org/wiki/Axonometric_projection ;;
;; tamivox.org/redbear/axono/index.html ;;
;; cadtutor.net ;;
;; lee-mac.com ;;
;;################################################;;
(vl-load-com)
(princ)
(defun c:avp (/ vptData aViewPoint old_cmdecho old_osmode old_color old_lweight e1 e2 e3 zoomscalefac strfac)
;;Start error traperr & save vars.
(setq temperr *error*)
(setq *error* traperr)
(setq old_cmdecho (getvar "CMDECHO"))
(setq old_osmode (getvar "OSMODE"))
(setq old_color (getvar "CECOLOR"))
(setq old_lweight (getvar "CELWEIGHT"))
(if (setq vptData (av:getUserInput))
(progn
(setvar "OSMODE" 0)
(setvar "CMDECHO" 0)
(setq e1 1.0)
(setq e2 1.0)
(setq e3 (av:e3calc global:rScale))
(setq zoomscalefac (sqrt (* 0.5 (+ (* 1.0 1.0) (* 1.0 1.0) (* global:rScale global:rScale)))))
(setq strfac (rtos zoomscalefac 2 16))
;; Setup view point location
(if (eq global:zhori "Above")
(cond ((eq global:xydir "Sse")
(setq aViewPoint (list e1 (* e3 -1.0) e2))
)
((eq global:xydir "Ees")
(setq aViewPoint (list e3 (* e1 -1.0) e2))
)
((eq global:xydir "Een")
(setq aViewPoint (list e3 e1 e2))
)
((eq global:xydir "Nne")
(setq aViewPoint (list e1 e3 e2))
)
((eq global:xydir "Nnw")
(setq aViewPoint (list (* e1 -1.0) e3 e2))
)
((eq global:xydir "Wwn")
(setq aViewPoint (list (* e3 -1.0) e1 e2))
)
((eq global:xydir "Wws")
(setq aViewPoint (list (* e3 -1.0) (* e1 -1.0) e2))
)
((eq global:xydir "Ssw")
(setq aViewPoint (list (* e1 -1.0) (* e3 -1.0) e2))
)
)
(cond ((eq global:xydir "Sse")
(setq aViewPoint (list e1 (* e3 -1.0) (* e2 -1.0)))
)
((eq global:xydir "Ees")
(setq aViewPoint (list e3 (* e1 -1.0) (* e2 -1.0)))
)
((eq global:xydir "Een")
(setq aViewPoint (list e3 e1 (* e2 -1.0)))
)
((eq global:xydir "Nne")
(setq aViewPoint (list e1 e3 (* e2 -1.0)))
)
((eq global:xydir "Nnw")
(setq aViewPoint (list (* e1 -1.0) e3 (* e2 -1.0)))
)
((eq global:xydir "Wwn")
(setq aViewPoint (list (* e3 -1.0) e1 (* e2 -1.0)))
)
((eq global:xydir "Wws")
(setq aViewPoint (list (* e3 -1.0) (* e1 -1.0) (* e2 -1.0)))
)
((eq global:xydir "Ssw")
(setq aViewPoint (list (* e1 -1.0) (* e3 -1.0) (* e2 -1.0)))
)
)
)
(vl-cmdf "_vpoint" aViewPoint)
(princ "\nDebug info's\nZoom scale factor to match AutoCAD unit: ")
(princ strfac)
(princ "\n")
(princ "Note: e1 = e2 = 1.0, e3 = ")
(princ e3)
)
(princ)
)
(setvar "CMDECHO" old_cmdecho)
(setvar "OSMODE" old_osmode)
(setvar "CECOLOR" old_color)
(setvar "CELWEIGHT" old_lweight)
(princ)
)
;;-------------------------------------;;
;; Function to get user input keywords ;;
;;-------------------------------------;;
(defun av:getUserInput (/ dScale rScale xydir zhori tmp0 tmp1 tmp2 time)
;; dScale - global: hold default scale ratio keyword when prompt user for input.
;; rScale - global: scale ratio, real number must be between 0 and 1.
;; xydir - keyword: view direction from xy plane.
;; zhori - keyword: view direction from z plan, above or below horizon
;; temp0 - temporary variable 0
;; temp1 - temporary variable 1
;; temp2 - temporary variable 2
;; time - temporary variable
(if (null global:dScale)
(setq global:dScale "3-quarter")
)
(initget "1-half 2-third 3-quarter Other")
(if (setq tmp0 (getkword (strcat "\nScale ratio [1-half/2-third/3-quarter/Other] <" global:dScale ">: ")))
(cond ((= tmp0 "1-half")
(setq global:dScale tmp0)
(setq global:rScale 0.5)
)
((= tmp0 "2-third")
(setq global:dScale tmp0)
(setq global:rScale (/ 2.0 3.0))
)
((= tmp0 "3-quarter")
(setq global:dScale tmp0)
(setq global:rScale 0.75)
)
((= tmp0 "Other")
(setq global:dScale tmp0)
;;--------------Thank to "rkmcswain" @ cadtutor.net/forum ---------
(setq time T)
(while time
(setq global:rScale (getreal (strcat "\nEnter scale ratio: ")))
(if (and (> global:rScale 0.0) (<= global:rScale 1.0))
(setq time nil)
)
)
;;-----------------------------------------------------------------
)
)
)
(if (null global:zhori)
(setq global:zhori "Above")
)
(initget "Above Below")
(if (setq tmp1 (getkword (strcat "\nView angle [Above/Below] Horizon <" global:zhori ">: ")))
(setq global:zhori tmp1)
)
(if (null global:xydir)
(setq global:xydir "Sse")
)
(initget "Sse Ees Een Nne Nnw Wwn Wws Ssw")
(if (setq
tmp2
(getkword
(strcat
"\nLocation on XY Plane [Sse/Ees/Een/Nne/Nnw/Wwn/Wws/Ssw] <" global:xydir ">: "
)
)
)
(setq global:xydir tmp2)
)
(list global:dScale globle:rScale global:zhori global:xydir)
)
;;---------------------------------------;;
;; Function calculate e3 (element e3) ;;
;;---------------------------------------;;
;; Thank Dave Barber http://tamivox.org ;;
;; for axonometric calculator formulars ;;
;;---------------------------------------;;
(defun av:e3calc (m / e1 e2 e3 Lr Cr Rr Ls Cs Rs Li Ci Ri Dr Lu Cu Ru Dd)
(setq e1 1.0)
(setq e2 1.0)
(setq e3 m)
(setq Lr 1.0)
(setq Cr 1.0)
(setq Rr e3)
(setq Dr (sqrt (* 0.5 (+ (* Lr Lr) (* Cr Cr) (* Rr Rr)))))
(setq Ls (/ Lr Dr))
(setq Cs (/ Cr Dr))
(setq Rs (/ Rr Dr))
(setq Lu (- 1.0 (* Ls Ls)))
(setq Cu (- 1.0 (* Cs Cs)))
(setq Ru (- 1.0 (* Rs Rs)))
(setq Li (atan (sqrt (/ (* Lu Cu) Ru))))
(setq Ci (atan (sqrt (/ (* Ru Lu) Cu))))
(setq Ri (atan (sqrt (/ (* Cu Ru) Lu))))
(setq Dd (sqrt (- (/ 1.0 (sin Li)) Lr)))
)
;;----------------------------------------------;;
;; Error traper function restore save variables ;;
;;----------------------------------------------;;
(defun traperr (errmsg)
(setvar "CMDECHO" old_cmdecho)
(setvar "OSMODE" old_osmode)
(setvar "CECOLOR" old_color)
(setvar "CELWEIGHT" old_lweight)
(setq *error* temperr)
(prompt "\Resetting system variables ")
(princ)
)