Jump to content

Recommended Posts

Posted

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.

 

(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)
 [b](setq jm_dimd (getint "\nEnter Dimension D: "))[/b]
 (initget 7)
 [b](setq jm_dime (getint "\nEnter Dimension E: "))[/b]
 (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 :P)

 

Whats anoying me is that I can't figure out how to go about making sure Dimension E

 

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.

 

;_______________________________
;
; 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)

Posted

You'll need something like this:

 

[b][color=BLACK]([/color][/b]initget 7[b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]setq jm_dimd [b][color=FUCHSIA]([/color][/b]getint [color=#2f4f4f]"\nEnter Dimension D: "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]or [b][color=NAVY]([/color][/b]not jm_dime[b][color=NAVY])[/color][/b]
          [b][color=NAVY]([/color][/b]> jm_dime jm_dimd[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
      [b][color=FUCHSIA]([/color][/b]initget 7[b][color=FUCHSIA])[/color][/b]
      [b][color=FUCHSIA]([/color][/b]setq jm_dime [b][color=NAVY]([/color][/b]getint [color=#2f4f4f]"\nEnter Dimension E: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

-David

Posted

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

Posted

I think I would use an if or cond phrase within a while statement, i.e.

 

(while (dima<dimb)
  (setq dimb (getint "Input: "))
  (cond (dima<dimb)
    (princ "wrong input")
  )
)

 

I think, maybe wrong, still learning...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...