TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Zahex on May 11, 2005, 07:40:58 AM
-
Hi can anyone give me a help with this code?i marked the line that doesn't work and what i want it to do.
i want to extrude using the taper angle option one polygon defined by a user to another also defined by the user.
give it a look the only problem is that it only works because i fixed the values.
please help...
(alert "to run type 2")
;;; (command "erase" "all" "") comment added by CAB
(defun c:2 ()
(setq angl (atan (/ 5 3))) ; here is the problem the idea was to replace 5 by height and 3 by larger radius-smaller radius this is the only way to return the angle for the taper angle extrusion
(setq baseradius (getreal "\n smaller radius: "))
(setq height (getreal "\n height: "))
(setq sides (getint "\n number of polygon sides: ")
centerpt (getpoint "\n insertion point: ")
radius (getreal "\n larger radius: ")
osnaps (getvar "osmode")
); setq
(setvar "osmode" 0)
(command "polygon" sides centerpt "C" (polar centerpt 0 radius))
(command "extrude" (entlast) "" height angl)
)
-
This [ (command "erase" "all" "") ] may not bother anyone else but it may be a good idea not to include that in your code when posting it. Might give someone a shock if they didn't catch that in your code.
-
I saw that. Was wondering why you'd erase everything in your drawing whenever you load that file? Could be very dangerous.
-
I concur with previous comments.
Also, was it your intention to perform integer math?
(/ 5 3) => 1
(/ 5 3.0) => 1.66667
Thus ...
(atan (/ 5 3)) => 0.785398
(atan (/ 5 3.0)) => 1.03038
:)
-
Yes you're right about the erase all thing how do i change it so people don't be shocked?
Forget the 5 and 3 values that's not what this is about,5 and 3 are just examples.
5 should be replaced by a variable height previously defined by the user.
3 should be replaced by a subtraction of two variables,between the bigger radius and the smaller radius(top and base can take both types of radius).
please help
-
What's the purpose of erasing all objects in db?
-
Checking batteries in crystal ball ...
-
this is what i want to do,only this code asks me for 2 radius but still it draws me a pyramid and not a prismatic figure.
Any ideas?
(defun c:2 ()
(setq radius (getreal "\n larger radius: "))
(setq baseradius (getreal "\n smaller radius: "))
(setq height (getreal "\n height: "))
(setq angRad (atan height (- radius baseradius)))
(setq angDeg (Radians->Degrees angRad))
(setq sides (getint "\n number of polygon sides: "))
(setq centerpt (getpoint "\n insertion point: "))
(setq osnaps (getvar "osmode"))
(setvar "osmode" 0)
(command "polygon" sides centerpt "C" (polar centerpt 0 radius))
(command "extrude" (entlast) "" height angDeg)
)
(defun Radians->Degrees (rads)
(* rads (
-
dunno, try these
(defun dtr (a)(* pi (/ a 180.0)))
(defun rtd (a)(* 180.0 (/ a pi)))
(command "polygon" sides centerpt "C" radius)
no need for polar
(setq angdeg (- 90.0 (rtd (atan height (- radius baseradius)))))
no need to set and save angrad
-
exactly where do i pu them in my code?
Thanks
-
the two function rtd and dtr go first, above everything.
for the other two lines, just replace your lines in the code with those. where you're calling the polygon command, replace it with that line, and where you're defining angdeg replace that line with mine, then delete the (setq andrad line completely.
then give it a shot.
-
Like this?
(defun c:2 ()
(defun dtr (a)(* pi (/ a 180.0)))
(defun rtd (a)(* 180.0 (/ a pi)))
(setq radius (getreal "\n larger radius: "))
(setq baseradius (getreal "\n smaller radius: "))
(setq height (getreal "\n height: "))
(setq angDeg (- 90.0 (rtd (atan height (- radius baseradius)))))
(setq sides (getint "\n number of polygon sides: "))
(setq centerpt (getpoint "\n insertion point: "))
(setq osnaps (getvar "osmode"))
(setvar "osmode" 0)
(command "polygon" sides centerpt "C" radius)
(command "extrude" (entlast) "" height angDeg)
)
(defun Radians->Degrees (rads)
(* rads (/ 180.0 pi)))
-
sorta Like this? completely unchecked.
(defun dtr (a)(* pi (/ a 180.0)))
(defun rtd (a)(* 180.0 (/ a pi)))
(defun c:2 ()
(command ".undo" "begin")
(setq radius (getreal "\n larger radius: "))
(setq baseradius (getreal "\n smaller radius: "))
(setq height (getreal "\n height: "))
(setq angDeg (- 90.0 (rtd (atan height (- radius baseradius)))))
(setq sides (getint "\n number of polygon sides: "))
(setq centerpt (getpoint "\n insertion point: "))
(setq osnaps (getvar "osmode"))
(setvar "osmode" 0)
(command "polygon" sides centerpt "C" radius)
(command "extrude" (entlast) "" height angDeg)
(setvar "osmode" osnaps)
(command ".undo" "end")
)
-
Always keep a backup of your work before making suggested changes.
-
Always keep a backup of your work before making suggested changes.
excellent advice... i'm quite surprised CAB hasn't jumped in yet with some simply marvelous code for this. i've grown to depend on his participation to keep me out of trouble... well, him and nearly everyone else here.
-
who's CAB?
-
Charles Alan Butler? A very good guy who learned a lot about lisp through forums like this and does a lot to return the favor by helping others.
-
Thanks guys.
I did not see problem with the code & it worked for me in ACAD2000.
Here are some changes I would make though. Mostly the use of getdist to
replace getreal. Also localized the functions
(defun c:2 (/ usercmd useros radius height angDeg sides centerpt baseradius
dtr rtd)
(defun dtr (a) (* pi (/ a 180.0)))
(defun rtd (a) (* 180.0 (/ a pi)))
(command "._undo" "_begin")
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq useros (getvar "osmode"))
(if (and
(setq radius (getdist "\n larger radius: "))
(setq baseradius (getdist "\n smaller radius: "))
(setq height (getdist "\n height: "))
(setq angDeg (- 90.0 (rtd (atan height (- radius baseradius)))))
(setq sides (getint "\n number of polygon sides: "))
(setq centerpt (getpoint "\n insertion point: "))
)
(progn
(setvar "osmode" 0)
(command "._polygon" sides centerpt "_C" radius)
(command "._extrude" (entlast) "" height angDeg)
)
)
(setvar "osmode" useros)
(setvar "CMDECHO" usercmd)
(command "._undo" "_end")
(princ)
)
(prompt "\nRoutine 2 Loaded, Enter 2 to run.")
(princ)
-
nice to meet you CAB.You have lots of people who trust your work,that's very nice.
2 questions:
1-what does "CMDECHO" means?
2-can you take a look at my other post called 2 codes fusion ant tell me what you think about it?
thanks all of you
-
Welcome to the Swamp :)
CMDECHO - system variable
Type: Integer
Not saved
Initial value: 1
Controls whether AutoCAD echoes prompts and input during the AutoLISP command function.
0 Turns off echoing
1 Turns on echoing
I'll look but I'm a 2d kinda guy, that 3d hurts my head. :shock:
-
1 - CoMmanDECHO. It echo's (prints) the return values of commands to the command line.
-
now...who's a 3d kind of guy that can give me some help in the merge of 2 routines ...?
Thanks
-
well i'm a 3d kinda guy, but my lisp capabilities stink. i'll take a look at that other thread, but i ain't making any promises.
-
Thanks CADaver!