Author Topic: extrusion code  (Read 6898 times)

0 Members and 1 Guest are viewing this topic.

Zahex

  • Guest
extrusion code
« 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...

Code: [Select]


(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)
  )




Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extrusion code
« Reply #1 on: May 11, 2005, 08:10:09 AM »
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.
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
extrusion code
« Reply #2 on: May 11, 2005, 08:49:33 AM »
I saw that. Was wondering why you'd erase everything in your drawing whenever you load that file? Could be very dangerous.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
extrusion code
« Reply #3 on: May 11, 2005, 09:07:15 AM »
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

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Zahex

  • Guest
forget numbers 3 and 5
« Reply #4 on: May 11, 2005, 09:50:38 AM »
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

daron

  • Guest
extrusion code
« Reply #5 on: May 11, 2005, 10:32:57 AM »
What's the purpose of erasing all objects in db?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
extrusion code
« Reply #6 on: May 11, 2005, 10:46:39 AM »
Checking batteries in crystal ball ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Zahex

  • Guest
extrusion code
« Reply #7 on: May 11, 2005, 12:25:45 PM »
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?

Code: [Select]

(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 (

CADaver

  • Guest
extrusion code
« Reply #8 on: May 11, 2005, 01:06:27 PM »
dunno, try these

Code: [Select]
(defun dtr (a)(* pi (/ a 180.0)))
(defun rtd (a)(* 180.0 (/ a pi)))


Code: [Select]
(command "polygon" sides centerpt "C" radius)no need for polar


Code: [Select]
(setq angdeg (- 90.0 (rtd (atan height (- radius baseradius)))))no need to set and save angrad

Zahex

  • Guest
where do i put them
« Reply #9 on: May 11, 2005, 01:20:47 PM »
exactly where do i pu them in my code?

Thanks

CADaver

  • Guest
extrusion code
« Reply #10 on: May 11, 2005, 01:45:22 PM »
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.

Zahex

  • Guest
Like this?
« Reply #11 on: May 11, 2005, 04:26:06 PM »
Like this?

Code: [Select]

(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)))

CADaver

  • Guest
Re: Like this?
« Reply #12 on: May 11, 2005, 04:37:28 PM »
sorta Like this? completely unchecked.

Code: [Select]
(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")
)

daron

  • Guest
extrusion code
« Reply #13 on: May 12, 2005, 07:27:41 AM »
Always keep a backup of your work before making suggested changes.

CADaver

  • Guest
extrusion code
« Reply #14 on: May 12, 2005, 08:49:37 AM »
Quote from: Daron
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.

Zahex

  • Guest
who's CAB?
« Reply #15 on: May 12, 2005, 08:52:30 AM »
who's CAB?

daron

  • Guest
extrusion code
« Reply #16 on: May 12, 2005, 09:27:23 AM »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
extrusion code
« Reply #17 on: May 12, 2005, 09:42:31 AM »
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
Code: [Select]

(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)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Zahex

  • Guest
extrusion code
« Reply #18 on: May 12, 2005, 09:48:55 AM »
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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
extrusion code
« Reply #19 on: May 12, 2005, 09:57:44 AM »
Welcome to the Swamp :)
Quote
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:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
extrusion code
« Reply #20 on: May 12, 2005, 09:58:13 AM »
1 - CoMmanDECHO. It echo's (prints) the return values of commands to the command line.

Zahex

  • Guest
extrusion code
« Reply #21 on: May 12, 2005, 10:40:10 AM »
now...who's a 3d kind of guy that can give me some help in the merge of  2 routines ...?

Thanks

CADaver

  • Guest
extrusion code
« Reply #22 on: May 12, 2005, 10:51:24 AM »
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.

Zahex

  • Guest
extrusion code
« Reply #23 on: May 12, 2005, 10:52:51 AM »
Thanks CADaver!