|
|
#1 |
|
Forum Newbie
|
Greetings all.
I'm making a program for college that creates a bush part fist angle drg from specified dims. I will be using dcls later on but for now im just trying to get my head around error handling and input validation. Code:
(defun jm_dims () ;; Sets all of the user defined variables. Preset for testing! (setq jm_p0 (getpoint "\nPick a Point of Origin: ")) (command "vslide" "BUSH3.sld") (initget 7) (setq jm_dima (getint "\nEnter Dimension A: ")) (initget 7) (setq jm_dimb (getint "\nEnter Dimension B: ")) (initget 7) (setq jm_dimc (getint "\nEnter Dimension C: ")) (initget 7) (setq jm_dimd (getint "\nEnter Dimension D: ")) (initget 7) (setq jm_dime (getint "\nEnter Dimension E: ")) (initget 7) (setq jm_dimf (getint "\nEnter Dimension F: ")) (initget 7) (setq jm_dimg (getint "\nEnter Dimension G: ")) ) ) Whats anoying me is that I can't figure out how to go about making sure Dimension E < Dimension D. I.e. If dimd = 1000 and the user enters 1500 for dime it says "woa 'ang on, dime must be less than dimd... try again chap". Noob question I know but the developers guide has been no help to me and I cant find anything I can adapt on this forum. Cheers in advance. ps heres the full prog so far. Code:
;_______________________________
;
; James Morris
; Morgan Professional Services
; Programming Concepts Project
; Parametric Bush Program
; JM_AUTOBUSH.LSP
;
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
(prompt "loading JM_AUTOBUSH.lsp... ") ;; displays to the user that the program is loading.
(defun jm_dims () ;; Sets all of the user defined variables. Preset for testing!
(setq jm_p0 (getpoint "\nPick a Point of Origin: "))
(command "vslide" "BUSH3.sld")
(initget 7)
(setq jm_dima (getint "\nEnter Dimension A: "))
(initget 7)
(setq jm_dimb (getint "\nEnter Dimension B: "))
(initget 7)
(setq jm_dimc (getint "\nEnter Dimension C: "))
(initget 7)
(setq jm_dimd (getint "\nEnter Dimension D: "))
(initget 7)
(setq jm_dime (getint "\nEnter Dimension E: "))
(initget 7)
(setq jm_dimf (getint "\nEnter Dimension F: "))
(initget 7)
(setq jm_dimg (getint "\nEnter Dimension G: "))
; (setq ;; Picks point of origin and requests dimensions.
;
; jm_dima 75
; jm_dimb 100
; jm_dimc 20
; jm_dimd 200
; jm_dime 50
; jm_dimf 80
; jm_dimg 100
; jm_polywidth 0.25
; )
)
(defun jm_loadlinetypes ()
(setq jm_linelist '(("Center" . "acadiso.lin") ("Hidden" . "acadiso.lin")))
(foreach lin jm_linelist
(if (tblsearch "LTYPE" (car lin))
(command ".-linetype" "_Load" (car lin) (cdr lin) "_Yes" "")
(command ".-linetype" "_Load" (car lin) (cdr lin) "")
)
)
)
(defun jm_pointcalculations () ;; all of the refpoints are defined here.
(setq ;;
; Descided this wasnt what I was after. The plan was to draw half
; then mirror along the centerline. I didn't like how it was
; looking so I binned it.
;
; jm_p1 (getpoint "\nPick Point of origin: ")
; jm_p2 (list (car jm_p1) (- (cadr jm_p1) (/ jm_dimd 2)))
; jm_p3 (list (+ (car jm_p2) jm_dima) (cadr jm_p2))
; jm_p4 (list (car jm_p3) (cadr jm_p1))
; jm_p5 (list (car jm_p3) (- (cadr jm_p1) (/ jm_dimg 2)))
; jm_p6 (list (+ (car jm_p5) jm_dimb) (cadr jm_p5))
; jm_p7 (list (car jm_p6) (cadr jm_p1))
; jm_p8 (list (car jm_p7) (- (cadr jm_p1) (/ jm_dimf 2)))
; jm_p9 (list (+ (car jm_p8) jm_dimc) (cadr jm_p8))
; jm_p10 (list (car jm_p9) (cadr jm_p1))
; jm_p11 (list (car jm_p1) (- (cadr jm_p1) (/ jm_dime 2)))
; jm_p12 (list (car jm_p10) (- (cadr jm_p1) (/ jm_dime 2)))
; jm_p13 (list (+ (car jm_p10) (/ jm_dimd 2)) (cadr jm_p10))
; jm_p14 (list (- (car jm_p1) jm_dimd) (cadr jm_p1))
; jm_p15 (list (- (car jm_p14) jm_dimd) (cadr jm_p1))
; jm_p0 (getpoint "\nPick a Point of Origin: ")
jm_p1 (list (car jm_p0) (- (cadr jm_p0) (/ jm_dimd 2)))
jm_p2 (list (+ (car jm_p1) jm_dima) (cadr jm_p1))
jm_p3 (list (car jm_p2) (+ (cadr jm_p2) jm_dimd))
jm_p4 (list (car jm_p1) (cadr jm_p3))
jm_p5 (list (car jm_p2) (- (cadr jm_p0) (/ jm_dime 2)))
jm_p6 (list (+ (car jm_p5) jm_dimb) (cadr jm_p5))
jm_p7 (list (car jm_p6) (+ (cadr jm_p5) jm_dime))
jm_p8 (list (car jm_p5) (cadr jm_p7))
jm_p9 (list (car jm_p6) (- (cadr jm_p0) (/ jm_dimf 2)))
jm_p10 (list (+ (car jm_p9) jm_dimc) (cadr jm_p9))
jm_p11 (list (car jm_p10) (+ (cadr jm_p9) jm_dimf))
jm_p12 (list (car jm_p9) (cadr jm_p11))
jm_p13 (list (car jm_p1) (- (cadr jm_p0) (/ jm_dimg 2)))
jm_p14 (list (car jm_p10) (cadr jm_p13))
jm_p15 (list (car jm_p1) (+ (cadr jm_p0) (/ jm_dimg 2)))
jm_p16 (list (car jm_p10) (cadr jm_p15))
jm_p17 (list (- (car jm_p0) (* jm_dimd 2)) (cadr jm_p0))
jm_p18 (list (- (car jm_p0) jm_dimd) (cadr jm_p0))
jm_p19 (list (+ (car jm_p10) (/ jm_dimd 2)) (cadr jm_p0))
)
)
(defun jm_drawthe****** ()
; I've binned these for the same reason as the points above
;
; (command "pline" jm_p1 jm_p2 jm_p3 jm_p4)
; (command)
; (command "pline" jm_p5 jm_p6 jm_p7)
; (command)
; (command "pline" jm_p8 jm_p9 jm_p10)
; (command)
; (command "line" jm_p11 jm_p12)
; (command)
; (command "Circle" jm_p14 "d" jm_dimd)
; (command)
; (command "Circle" jm_p14 "d" jm_dime)
; (command)
; (command "Circle" jm_p14 "d" jm_dimf)
; (command)
; (command "Circle" jm_p14 "d" jm_dimg)
; (command)
; (command "line" jm_p15 jm_p13)
; (command)
(command "-layer" "Make" "PART" "Color" "Green" "" "") (command) ;; sets the layer prior to drawing the line.
; (command "pline" jm_p1 "w" jm_polywidth "" jm_p2 jm_p3 jm_p4 "c") (command) ;; polylines look ****
; (command "pline" jm_p5 "w" jm_polywidth "" jm_p6 jm_p7 jm_p8) (command)
; (command "pline" jm_p9 "w" jm_polywidth "" jm_p10 jm_p11 jm_p12) (command)
(command "line" jm_p1 jm_p2 jm_p3 jm_p4 "c") (command)
(command "line" jm_p5 jm_p6 jm_p7 jm_p8) (command)
(command "line" jm_p9 jm_p10 jm_p11 jm_p12) (command)
(command "circle" jm_p18 "d" jm_dimd) (command)
(command "circle" jm_p18 "d" jm_dime) (command)
(command "circle" jm_p18 "d" jm_dimf) (command)
(command "circle" jm_p18 "d" jm_dimg) (command)
(command "-layer" "Make" "HIDDEN" "Color" "Blue" "" "Ltype" "Hidden" "" "") (command)
(command "line" jm_p13 jm_p14) (command)
(command "line" jm_p15 jm_p16) (command)
(command "-layer" "Make" "CENTER" "Color" "Red" "" "Ltype" "Center" "" "") (command)
(command "line" jm_p17 jm_p19) (command)
(command "-layer" "Set" "0" "") (command)
(command "regenall") (command)
(command "Zoom" "Extents") (command)
(princ)
)
(defun c:jm_start ()
(setq ;;
jm_oldosmode (getvar "osmode")
jm_oldcmdecho (getvar "cmdecho")
)
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(jm_dims)
(jm_pointcalculations)
(jm_loadlinetypes)
(jm_drawthe******)
(jm_debug) ;; activated when wanting to print all variables and quantities to commandline.
(setvar "osmode" jm_oldosmode)
(princ)
(setvar "cmdecho" jm_oldcmdecho)
(princ)
)
(defun jm_debug () ; Debugging mode. lists all variables and their current values
(princ "\n") (princ "\nUser Defined Variables...")
(princ "\njm_dima = ") (princ jm_dima) (princ "\njm_dimb = ") (princ jm_dimb)
(princ "\njm_dimc = ") (princ jm_dimc) (princ "\njm_dimd = ") (princ jm_dimd)
(princ "\njm_dime = ") (princ jm_dime) (princ "\njm_dimf = ") (princ jm_dimf)
(princ "\njm_dimg = ") (princ jm_dimg) (princ "\njm_polywidth = ") (princ jm_polywidth)
(princ "\n") (princ "\nCalculated Points...")
(princ "\njm_p0 = ") (princ jm_p0) (princ "\njm_p1 = ") (princ jm_p1)
(princ "\njm_p2 = ") (princ jm_p2) (princ "\njm_p3 = ") (princ jm_p3)
(princ "\njm_p4 = ") (princ jm_p4) (princ "\njm_p5 = ") (princ jm_p5)
(princ "\njm_p6 = ") (princ jm_p6) (princ "\njm_p7 = ") (princ jm_p7)
(princ "\njm_p8 = ") (princ jm_p8) (princ "\njm_p9 = ") (princ jm_p9)
(princ "\njm_p10 = ") (princ jm_p10) (princ "\njm_p11 = ") (princ jm_p11)
(princ "\njm_p12 = ") (princ jm_p12) (princ "\njm_p13 = ") (princ jm_p13)
(princ "\njm_p14 = ") (princ jm_p14) (princ "\njm_p15 = ") (princ jm_p15)
(princ "\njm_p16 = ") (princ jm_p16) (princ "\njm_p17 = ") (princ jm_p17)
(princ "\njm_p18 = ") (princ jm_p18) (princ "\njm_p19 = ") (princ jm_p19)
(princ "\n")
)
(prompt "\n...loaded ")
(terpri)
(prin1)
|
|
|
|
|
|
#2 |
|
Super Member
![]() ![]() ![]() ![]() Using: AutoCAD R12 Join Date: Dec 2003
Location: Newport News, Virginia
Posts: 1,126
|
You'll need something like this:
Code:
(initget 7)
(setq jm_dimd (getint "\nEnter Dimension D: "))
(while (or (not jm_dime)
(> jm_dime jm_dimd))
(initget 7)
(setq jm_dime (getint "\nEnter Dimension E: ")))
|
|
R12 (Dos) - A2K
|
|
|
|
|
|
|
#3 |
|
Forum Newbie
|
hehe much appreciated chap. I was trying while loops with little success but putting an "or" in there didn't cross my mind.
Cheers, James |
|
|
|
|
|
#4 |
|
Full Member
![]() ![]() Using: AutoCAD 2009 Join Date: Jul 2009
Posts: 32
|
I think I would use an if or cond phrase within a while statement, i.e.
Code:
(while (dima<dimb)
(setq dimb (getint "Input: "))
(cond (dima<dimb)
(princ "wrong input")
)
)
|
|
|
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick Question | Manic_d | 3ds Max Beginners' Area | 8 | 21st Aug 2009 02:26 am |
| Another quick question | Mason Dixon | AutoCAD Beginners' Area | 1 | 12th Jun 2009 09:39 pm |
| Quick Question Please. | Simsy23 | AutoCAD General | 2 | 12th May 2009 11:36 am |
| Quick Question | wastewater | AutoCAD Drawing Management & Output | 3 | 6th Dec 2006 11:23 am |
| quick question | allanp | AutoLISP, VBA, the CUI & Customisation | 3 | 3rd Oct 2004 09:04 pm |