AutoCAD/AutoLISP
Expert: Bill DeShawn - 11/5/2011
QuestionQUESTION: I need some help in parametric programming. eg. drawing hexagonal nut whose size is defined by user.
I also need some help in animating programs in AutoLISP. For eg. demonstration of Otto Cycle (schematic.) or pendulum or crank shaft mechanisim etc.
ANSWER: Madhura:
Let's start with the hex nut. Are you drawing these nuts in 3-D? Are they metric? Are they SAE?
Next: The demonstration of the Autocycle can be done with slides (.SLD files - one for each step in the cycle) and a script file and would probably look very similar to this:
http://techni.tachemie.uni-leipzig.de/otto/index_e.html%20
The pendulum or crankshaft mechanisms can be demonstrated in a similar fashion. Are you familiar with writing scripts for slides to run in AutoCAD?
Bill DeShawn
http://my.sterling.net/~bdeshawn
---------- FOLLOW-UP ----------
QUESTION: I'm drawing a metric hex nut in 2D. I know only basic autolisp programming. i hv written some programs for basic shapes like concentric circles etc only .lsp files.
AnswerOK, then, let's get started by making a list of hex nut sizes that you want a user to have access to. We can probably get started here:
http://www.fairburyfastener.com/xdims_metric_nuts.htm
To be on the safe side, for the sake of designability, it might be best to draw these nuts with the maximum hex nut size.
(defun c:hexnut (/ goodval)
(textscr)
(princ "\nEnter letter for size: ")
(princ "\nA: M1.6 \nB: M2 \nC: M2.5 \nD: M3 \nE: M4 \nF: M5 \nG: M6 ")
(princ "\nH: M8 \nI: M10 \nJ: M12 \nK: M14 \nL: M16 \nM: M20 \nN: M24 ")
(terpri)(terpri)
(setq nomsz (strcase (getstring)));sets nominal size to an upper case letter that the user types in.
(if (= nomsz "A") (progn (setq nomsz 1.6)(setq nutwid 3.2)(setq goodval T)))
(if (= nomsz "B") (progn (setq nomsz 2.0)(setq nutwid 0.4)(setq goodval T)))
(if (= nomsz "C") (progn (setq nomsz 2.5)(setq nutwid 0.45)(setq goodval T)))
(if (= nomsz "D") (progn (setq nomsz 3.0)(setq nutwid 0.5)(setq goodval T)))
(if (= nomsz "E") (progn (setq nomsz 4.0)(setq nutwid 0.7)(setq goodval T)))
(if (= nomsz "F") (progn (setq nomsz 5.0)(setq nutwid 0.8)(setq goodval T)))
(if (= nomsz "G") (progn (setq nomsz 6.0)(setq nutwid 1.0)(setq goodval T)))
(if (= nomsz "H") (progn (setq nomsz 8.0)(setq nutwid 1.25)(setq goodval T)))
(if (= nomsz "I") (progn (setq nomsz 10.0)(setq nutwid 1.5)(setq goodval T)))
(if (= nomsz "J") (progn (setq nomsz 12.0)(setq nutwid 1.75)(setq goodval T)))
(if (= nomsz "K") (progn (setq nomsz 14.0)(setq nutwid 2.0)(setq goodval T)))
(if (= nomsz "L") (progn (setq nomsz 16.0)(setq nutwid 2.0)(setq goodval T)))
(if (= nomsz "M") (progn (setq nomsz 20.0)(setq nutwid 2.5)(setq goodval T)))
(if (= nomsz "N") (progn (setq nomsz 24.0)(setq nutwid 3.0)(setq goodval T)))
(if (null goodval)
(alert "\nPlease run routine again and select a displayed response.")
(progn
(princ (strcat "\n Nominal size: " (rtos nomsz 2 2) " Nut Width: " (rtos nutwid 2 2)))
)
)
(graphscr)
(princ)
)
Darn! AllExperts is reformatting my code. It'll still work, though.
I used getstring here, but another popular way is to use initget and getkword.
So, get that started see if you like it, and then we'll go from here.
Bill DeShawn
http://my.sterling.net/~bdeshawn