Welcome to the Southern African Autolisp Website.
You are Visitor Number
|
| Page I. | Page II. | Page III. | Home. |
(defun c:testbeam () ;define the function ;******************************************************** ;Save System Variables (setq oldsnap (getvar "osmode")) ;save snap settings (setq oldblipmode (getvar "blipmode")) ;save blipmode setting ;******************************************************** ;Switch OFF System Variables (setvar "osmode" 0) ;Switch OFF snap (setvar "blipmode" 0) ;Switch OFF Blipmode ;******************************************************** ;Get User Inputs (setq lb (getdist "\nLength of Beam : ")) ;get the length of the beam (setq hb (getdist "\nHeight of Beam : ")) ;get the height of the beam (setq wt (getdist "\nFlange Thickness : ")) ;get the thickness of the flange (setq ep (getdist "\nEnd Plate Thickness : ")) ;get the thickness of the end plate (setq nl (getdist "\nLength of Notch : ")) ;get the length of notch (setq nd (getdist "\nDepth of Notch : ")) ;get the depth of the notch ;End of User Inputs ;********************************************************* ;Get Insertion Point (setvar "osmode" 32) ;switch ON snap (setq ip (getpoint "\nInsertion Point : ")) ;get the insertion point (setvar "osmode" 0) ;switch OFF snap ;******************************************************** ;Start of Polar Calculations (setq p2 (polar ip (dtr 180.0) (- (/ lb 2) nl))) (setq p3 (polar p2 (dtr 270.0) wt)) (setq p4 (polar p2 (dtr 270.0) nd)) (setq p5 (polar p4 (dtr 180.0) nl)) (setq p6 (polar p5 (dtr 180.0) ep)) (setq p7 (polar p6 (dtr 270.0) (- hb nd))) (setq p8 (polar p7 (dtr 0.0) ep)) (setq p9 (polar p8 (dtr 90.0) wt)) (setq p10 (polar p9 (dtr 0.0) lb)) (setq p11 (polar p8 (dtr 0.0) lb)) (setq p12 (polar p11 (dtr 0.0) ep)) (setq p13 (polar p12 (dtr 90.0) (- hb nd))) (setq p14 (polar p13 (dtr 180.0) ep)) (setq p15 (polar p14 (dtr 180.0) nl)) (setq p16 (polar p15 (dtr 90.0) (- nd wt))) (setq p17 (polar p16 (dtr 90.0) wt)) ;End of Polar Calculations ;********************************************************** ;Start of Command Function (command "Line" ip p2 p4 p6 p7 p12 p13 p15 p17 "c" "Line" p3 p16 "" "Line" p9 p10 "" "Line" p5 p8 "" "Line" p11 p14 "" ) ;End Command ;End of Command Function ;********************************************************** ;Reset System Variable (setvar "osmode" oldsnap) ;Reset snap (setvar "blipmode" oldblipmode) ;Reset blipmode ;********************************************************* (princ) ;finish cleanly ) ;end of defun ;********************************************************** ;This function converts Degrees to Radians. (defun dtr (x) ;define degrees to radians function (* pi (/ x 180.0)) ;divide the angle by 180 then ;multiply the result by the constant PI ) ;end of function ;********************************************************** (princ) ;load cleanly ;**********************************************************
Load and run the programme. If you were having problems, they
should now have disapeared. (I hope!!). Did you notice how we
switched on the snap just before asking for the insertion point?
This, of course, is to allow the user to snap to an insertion point.
We still have another problem though. What would happen if the user
entered an illegal value, such as zero, or a negative number.
This could cause very strange results.
To guard against this we will use the (initget) function.
Here's how it works :
(initget (+ 1 2 4)) (setq lb (getdist "\nLength of Beam : "))
This function works on the "sum of the bits" system.
1 = Disallows the user from pressing "Enter". 2 = Disallows the user from entering "Zero". 3 = Disallows the user from entering a "Negative Number".
The same function could have been written like this :
(initget 7) (setq lb (getdist "\nLength of Beam : "))
Let's add this function to our routine :
(defun c:testbeam () ;define the function ;******************************************************** ;Save System Variables (setq oldsnap (getvar "osmode")) ;save snap settings (setq oldblipmode (getvar "blipmode")) ;save blipmode setting ;******************************************************** ;Switch OFF System Variables (setvar "osmode" 0) ;Switch OFF snap (setvar "blipmode" 0) ;Switch OFF Blipmode ;******************************************************** ;Get User Inputs (initget (+ 1 2 4)) ;check user input (setq lb (getdist "\nLength of Beam : ")) ;get the length of the beam (initget (+ 1 2 4)) ;check user input (setq hb (getdist "\nHeight of Beam : ")) ;get the height of the beam (initget (+ 1 2 4)) ;check user input (setq wt (getdist "\nFlange Thickness : ")) ;get the thickness of the flange (initget (+ 1 2 4)) ;check user input (setq ep (getdist "\nEnd Plate Thickness : ")) ;get the thickness of the end plate (initget (+ 1 2 4)) ;check user input (setq nl (getdist "\nLength of Notch : ")) ;get the length of notch (initget (+ 1 2 4)) ;check user input (setq nd (getdist "\nDepth of Notch : ")) ;get the depth of the notch ;End of User Inputs ;********************************************************* ;Get Insertion Point (setvar "osmode" 32) ;switch ON snap (setq ip (getpoint "\nInsertion Point : ")) ;get the insertion point (setvar "osmode" 0) ;switch OFF snap ;******************************************************** ;Start of Polar Calculations (setq p2 (polar ip (dtr 180.0) (- (/ lb 2) nl))) (setq p3 (polar p2 (dtr 270.0) wt)) (setq p4 (polar p2 (dtr 270.0) nd)) (setq p5 (polar p4 (dtr 180.0) nl)) (setq p6 (polar p5 (dtr 180.0) ep)) (setq p7 (polar p6 (dtr 270.0) (- hb nd))) (setq p8 (polar p7 (dtr 0.0) ep)) (setq p9 (polar p8 (dtr 90.0) wt)) (setq p10 (polar p9 (dtr 0.0) lb)) (setq p11 (polar p8 (dtr 0.0) lb)) (setq p12 (polar p11 (dtr 0.0) ep)) (setq p13 (polar p12 (dtr 90.0) (- hb nd))) (setq p14 (polar p13 (dtr 180.0) ep)) (setq p15 (polar p14 (dtr 180.0) nl)) (setq p16 (polar p15 (dtr 90.0) (- nd wt))) (setq p17 (polar p16 (dtr 90.0) wt)) ;End of Polar Calculations ;********************************************************** ;Start of Command Function (command "Line" ip p2 p4 p6 p7 p12 p13 p15 p17 "c" "Line" p3 p16 "" "Line" p9 p10 "" "Line" p5 p8 "" "Line" p11 p14 "" ) ;End Command ;End of Command Function ;********************************************************** ;Reset System Variable (setvar "osmode" oldsnap) ;Reset snap (setvar "blipmode" oldblipmode) ;Reset blipmode ;********************************************************* (princ) ;finish cleanly ) ;end of defun ;********************************************************** ;This function converts Degrees to Radians. (defun dtr (x) ;define degrees to radians function (* pi (/ x 180.0)) ;divide the angle by 180 then ;multiply the result by the constant PI ) ;end of function ;********************************************************** (princ) ;load cleanly ;**********************************************************
(defun c:testbeam () ;define the function ;******************************************************** ;Save System Variables (setq oldsnap (getvar "osmode")) ;save snap settings (setq oldblipmode (getvar "blipmode")) ;save blipmode setting ;******************************************************** ;Switch OFF System Variables (setvar "osmode" 0) ;Switch OFF snap (setvar "blipmode" 0) ;Switch OFF Blipmode ;******************************************************** ;Get User Inputs (initget (+ 1 2 4)) ;check user input (setq lb (getdist "\nLength of Beam : ")) ;get the length of the beam (initget (+ 1 2 4)) ;check user input (setq hb (getdist "\nHeight of Beam : ")) ;get the height of the beam (initget (+ 1 2 4)) ;check user input (setq wt (getdist "\nFlange Thickness : ")) ;get the thickness of the flange (initget (+ 1 2 4)) ;check user input (setq ep (getdist "\nEnd Plate Thickness : ")) ;get the thickness of the end plate (initget (+ 1 2 4)) ;check user input (setq nl (getdist "\nLength of Notch : ")) ;get the length of notch (initget (+ 1 2 4)) ;check user input (setq nd (getdist "\nDepth of Notch : ")) ;get the depth of the notch ;End of User Inputs ;********************************************************* ;Get Insertion Point (setvar "osmode" 32) ;switch ON snap (while ;start of while loop (setq ip (getpoint "\nInsertion Point : ")) ;get the insertion point (setvar "osmode" 0) ;switch OFF snap ;******************************************************** ;Start of Polar Calculations (setq p2 (polar ip (dtr 180.0) (- (/ lb 2) nl))) (setq p3 (polar p2 (dtr 270.0) wt)) (setq p4 (polar p2 (dtr 270.0) nd)) (setq p5 (polar p4 (dtr 180.0) nl)) (setq p6 (polar p5 (dtr 180.0) ep)) (setq p7 (polar p6 (dtr 270.0) (- hb nd))) (setq p8 (polar p7 (dtr 0.0) ep)) (setq p9 (polar p8 (dtr 90.0) wt)) (setq p10 (polar p9 (dtr 0.0) lb)) (setq p11 (polar p8 (dtr 0.0) lb)) (setq p12 (polar p11 (dtr 0.0) ep)) (setq p13 (polar p12 (dtr 90.0) (- hb nd))) (setq p14 (polar p13 (dtr 180.0) ep)) (setq p15 (polar p14 (dtr 180.0) nl)) (setq p16 (polar p15 (dtr 90.0) (- nd wt))) (setq p17 (polar p16 (dtr 90.0) wt)) ;End of Polar Calculations ;********************************************************** ;Start of Command Function (command "Line" ip p2 p4 p6 p7 p12 p13 p15 p17 "c" "Line" p3 p16 "" "Line" p9 p10 "" "Line" p5 p8 "" "Line" p11 p14 "" ) ;End Command ;End of Command Function ;********************************************************** (setvar "osmode" 32) ;Switch ON snap );end of while loop ;********************************************************** ;Reset System Variable (setvar "osmode" oldsnap) ;Reset snap (setvar "blipmode" oldblipmode) ;Reset blipmode ;********************************************************* (princ) ;finish cleanly ) ;end of defun ;********************************************************** ;This function converts Degrees to Radians. (defun dtr (x) ;define degrees to radians function (* pi (/ x 180.0)) ;divide the angle by 180 then ;multiply the result by the constant PI ) ;end of function ;********************************************************** (princ) ;load cleanly ;**********************************************************
The programme will now repeat itself indefinetly, asking for an
insertion point and drawing a beam, until the user presses enter.
This is how it works. The (while) function will continue to evaluate
an expression until the expression evaluates to nil. As long as the user
selects a point, the expression is true. But, when the user selects
"Enter" the expression returns "nil" and the programme moves out of the
loop. (AutoLisp evaluates "Enter" as "nil")
| Page I. | Page II. | Page III. | Home. |