Author Topic: extrusion code  (Read 6740 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: 28753
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.