CADTutor: The best free help for AutoCAD on the web

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Go Back   AutoCAD Forums > AutoCAD > AutoLISP, VBA, the CUI & Customisation

Reply
 
Thread Tools
Old 19th Oct 2009, 01:23 pm   #1
morris
Forum Newbie
 
Using: AutoCAD 2010
 
Computer Details
 
Join Date: Oct 2009
Location: Warrington, UK
Posts: 2
Default Quick question about input validation

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: "))
 
)
The above is the function that gets all of the required info from the user. (no sh*t )

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)
morris is offline   Reply With Quote
Old 19th Oct 2009, 01:45 pm   #2
David Bethel
Super Member
 
David Bethel's Avatar
 
Using: AutoCAD R12
 
Join Date: Dec 2003
Location: Newport News, Virginia
Posts: 1,126
Default

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: ")))
-David

R12 (Dos) - A2K
David Bethel is online now   Reply With Quote
Old 19th Oct 2009, 01:52 pm   #3
morris
Forum Newbie
 
Using: AutoCAD 2010
 
Computer Details
 
Join Date: Oct 2009
Location: Warrington, UK
Posts: 2
Default

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
morris is offline   Reply With Quote
Old 19th Oct 2009, 02:29 pm   #4
dhl
Full Member
 
Using: AutoCAD 2009
 
Join Date: Jul 2009
Posts: 32
Default

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")
   )
)
I think, maybe wrong, still learning...
dhl is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

Why Donate?


All times are GMT +1. The time now is 01:42 pm.

RSS Feed for AutoCAD ForumsValid XHTML 1.0!Valid CSS!Creative Commons Licence