PDA

View Full Version : spiral extrusion



fuccaro
17th May 2003, 10:17 am
Some time ago I begun to write a Lisp for extruding a closed polyline on a helix path. As you probably noticed the AutoCAD EXTRUDE command will rotate the shape during the extrusion. My simple routine is ready from about 1 month but it has limited functionality. Trying to improve it I got a huge source file. Also the number of bugs is increasing and sometime the programs behavior is unexpected. I decided to make public the limited form of the program and I will walk in a direction or other depending of your feed-backs. Please consider the following sentences as the "user manual" for the routine.
-Restrictions regarding the SHAPE to extrude
The shape to extrude must be a closed polyline formed by line segments only (no arcs).
The program can extrude only convex shapes. For other shapes please use your modeling skills and add, substract etc. the solids based on convex shapes.
All corners must be distinct. If you draw for example a rectangle you may use it. Also you may use a triangle. But if you will edit the grips of the rectangle and move on of the corners over an other one, even if your rectangle looks like the triangle - you can not use it.
You can not use polylines with three or more collinear consecutive points. This case may appear if you draw a half of the profile and the other half is obtained by mirroring. If an extreme edge is perpendicular to the mirror line you will obtain a polyline with three collinear points.
If the polyline contains a lot of points you will slow-down the program.
-Restrictions regarding the NUMBER OF SEGMENTS.
The curved faces of the solid are approximated by plain segments. Using too few segments will result a discontinued solid. More segments means smoothed aspect. But also means dramatically increase of the model complexity. If the polyline to extrude is complex you should use no more than about 50 segments. Experiment with the best complexity of the model - it depends on your machine.
-Other things to keep in mind
I wrote no error handling routine.
Call the routine when you are in the same UCS as the shape was create.
The shape you draw is the frontal section of the final solid. The mechanical engineers know the difference between the normal and the frontal section of a gear profile.
If the axe is inside the polyline to extrude you will got a twisted solid.
Set the shading mode to wire frame to speed up the process - you will need that.
High speed machines and large memories are welcome.
Do not write to me if this routine will drive you crazy.

; SPIRAL EXTRUSION ;
; mfuccaro@hotmail.com ;
;;;;;;;;- 17.05.2003 -;;;;;
(defun c:spirex( / m3 m4 plist pts nwpt nwpts rad ang dist
i mm pln ax ang1 s ss h1 pt)
(defun m3(a b c / p1 p2 p3 m1 m2 m3)
(setq p1 (* (car a) (cadr b) (caddr c))
p2 (* (car b) (cadr c) (caddr a))
p3 (* (car c) (cadr a) (caddr b))
m1 (* (car c) (cadr b) (caddr a))
m2 (* (car a) (cadr c) (caddr b))
m3 (* (car b) (cadr a) (caddr c)))
(- (+ p1 p2 p3) (+ m1 m2 m3)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun m4(x a b c / arg1 arg2 arg3)
(setq arg1 (list (cadr a) (caddr a) 1)
arg2 (list (cadr b) (caddr b) 1)
arg3 (list (cadr c) (caddr c) 1)
p (* (car x) (m3 arg1 arg2 arg3))
arg1 (list (car a) (caddr a) 1)
arg2 (list (car b) (caddr b) 1)
arg3 (list (car c) (caddr c) 1)
p (- p (* (cadr x) (m3 arg1 arg2 arg3)))
arg1 (list (car a) (cadr a) 1)
arg2 (list (car b) (cadr b) 1)
arg3 (list (car c) (cadr c) 1)
p (+ p (* (caddr x) (m3 arg1 arg2 arg3)))
p (- p (m3 a b c))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq pln (car (entsel "\n Select shape to extrude"))
ax (getpoint " Point on the axis?")
ang1 (/ (* pi (getreal "\nRotation angle (degrees) ")) 180.0)
h1 (getdist " Height ")
s (max 5 (getint " Segments "))
ang1 (/ ang1 s)
h1 (/ h1 s)
ss (ssadd))
(setq plist (entget pln)
pts nil nwpts nil i 0 rad 0)
(repeat (length plist)
(if (= (car (nth i plist)) 10)
(setq pt (cdr (nth i plist))
pts (cons (list (car pt) (cadr pt) 0) pts)
dist (distance pt ax)
rad (max rad dist)
ang (+ ang1 (atan (- (cadr pt) (cadr ax)) (- (car pt) (car ax))))
nwpt (polar ax ang dist)
rad (max rad (distance ax nwpt))
nwpts (cons (list (car nwpt) (cadr nwpt) h1) nwpts)))
(setq i (1+ i)))
(setq rad (* 1.5 rad) old (getvar "osmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(command "._undo" "begin")
(command "._sphere" (list (car ax) (cadr ax) 0) rad)
(command "._zoom" "w" (list (+ (car ax) rad) (+ (cadr ax) rad))
(list (- (car ax) rad) (- (cadr ax) rad)))
(command "._plan" "")
(command "._slice" "l" "" (car pts) (cadr pts) (caddr pts) (car nwpts))
(command "._slice" "l" "" (car nwpts) (cadr nwpts) (caddr nwpts) (car pts))
(setq mm (1- (length pts)) i 0)
(repeat (1+ mm)
(setq j (1+ i))
(if (> j mm) (setq j 0))
(setq k (1- i))
(if (< k 0) (setq k mm))
(if (minusp (* (m4 (nth j nwpts) (nth i pts) (nth j pts) (nth i nwpts))
(m4 (nth k pts) (nth i pts) (nth j pts) (nth i nwpts))))
(progn
(command "._slice" "l" "" (nth i pts) (nth j pts) (nth j nwpts) (nth k pts))
(command "._slice" "l" "" (nth i nwpts) (nth j nwpts) (nth i pts) (nth k pts)))
(progn
(command "._slice" "l" "" (nth i pts) (nth j pts) (nth i nwpts) (nth k pts))
(command "._slice" "l" "" (nth i nwpts) (nth j nwpts) (nth j pts) (nth k pts))))
(setq i (1+ i)))
(setq ss (ssadd (entlast) ss))
(repeat (1- s)
(command "._copy" "l" "" (list 0 0 0) (list 0 0 h1))
(command "._rotate" "l" "" ax (/ (* ang1 180.0) PI))
(setq ss (ssadd (entlast) ss)))
(command "._union" ss "")
(setvar "osmode" old)
(command "._undo" "end")
(setvar "cmdecho" 1)
(princ)
)
(princ "\nSPIRAL EXTRUSION program loaded")
(princ "\ttype SPIREX at the command prompt")
(princ)

superjari
22nd May 2003, 05:37 pm
I just tried it with a square but it gives a sphere as result, I'm still looking for a helix-lisp-file, I can't seem to get LISP-files for helixes from this forum to work...

fuccaro
23rd May 2003, 06:59 am
Superjari
I tested the routine with AutoCAD 2000 and it works for me. Please run the routine again in a new drawing with the OSNAP and OTRACK turned off and write me your experience.
I am surprised to read that none of the helix routines is working because I received positive feed-backs from other members and even from non members. Do you wish we try step by step to draw a helix?

superjari
23rd May 2003, 01:41 pm
Yes, if you could give me a step-by-step help on how to use the helix routine it might help, because I got a sphere as result again...

CADTutor
23rd May 2003, 03:49 pm
Well it works fine for me...

http://www.cadimage.net/watson/spirex1.gif

I coloured the extruded face so that you can see it more clearly. I haven't tried anything tricky but the pentagon worked without a hitch. The only thing I notice is that the spiral is rather flattened. Is it possible to extrude the profile so that it is perpendicular to the helical path?

robfowler
24th May 2003, 09:29 am
Sorry to have not tried your routine earlier Fuccaro but things have been a bit frought at work with our school changing its timetable 2 weeks earlier this year!

This lisp works well for when you may want a solid like a twisted wrought iron bar and where the bar is twisted on its own axis. Other possibilites are there also but, like David, I would like to see the profile extrude perpendicular to the path - it would look more realistic for many applications.

I really liked your drill bit and banister in your other post and I thought that your lisp here would eventually lead on to us being able to create solids like that.

Keep up the good work.

Rob.

fuccaro
24th May 2003, 10:13 am
CADTutor and Rob
As I mentioned earlier the shape you draw is the frontal section of the solid. It is possible to modify the routine but each changes means more code lines. I wait for more user inputs to operate the most wanted changes. Until that you may stretch the shape before the helical extrusion. I used this routine to draw the drill and the banister.
Superjari lets try to find out the problem.
Please find in the source code the line number 52 (if I counted correctly)
(setvar "cmdecho" 0)
and put a semicolon as first character in the line. This will transform the line in a comment. Reload the program and run it again. Wait until the command prompt returns. Switch to the textscreen (F2) and copy in a text document the sequence from the command SPIREX you typed in. Send me that text so I can see the executed commands and the error message.

superjari
24th May 2003, 02:00 pm
Command&#58; spirex

Select shape to extrude Point on the axis?20,20

Rotation angle &#40;degrees&#41; 600
Height 100
Segments 30
._undo Enter the number of operations to undo or
&#91;Auto/Control/BEgin/End/Mark/Back&#93; <1>&#58; begin
Command&#58; ._sphere
Current wire frame density&#58; ISOLINES=4
Specify center of sphere <0,0,0>&#58;
Specify radius of sphere or &#91;Diameter&#93;&#58; 0.000000000000000
Value must be nonzero.
Specify radius of sphere or &#91;Diameter&#93;&#58; ._zoom
Requires numeric distance, second point, or option keyword.
; error&#58; Function cancelled

Specify radius of sphere or &#91;Diameter&#93;&#58; 20


This is what I get, I used a rectangle for this, made out of 4 lines and regioned them...

I tried using 'rectangle' afterwards and that worked! :lol:

fuccaro
26th May 2003, 05:38 am
Superjari
The sahpe must be a cloed polyline. Also Rectangle, Polygon can be used. If you draw the shape from lines use PLJOIN (if do you have the express tools). I am glad that your problem is fixed. Do not forget to remove the semicolon you put in the Lisp file.
Still waiting for sugestions and observations. Thanks!

superjari
26th May 2003, 10:53 am
Here's my try...

http://picserver.student.utwente.nl/getpicture.php?id=130249

THNX Fuccaro for another great LISP-routine...

I agree with CADtutor and Rob about the flatness of the extruded shape, but further great! 8)

fuccaro
26th May 2003, 01:28 pm
Ok, probable the first modification will be the rotation of the shape perpendicular to the path to avoid the flatness.
Superjari you are so happy having the lisp working... you did not realized that your solid is discontinued. Increase the number of segments. If the model is to complex, decrease the rotation angle.
Probable the entire planet noticed until now that I never learned English in the school. However I realized that your THNX means “thanks”. Do you know a short form for “You are welcome” ?

superjari
26th May 2003, 03:08 pm
Well the best I can think of is "U R welcome"... 8)

Flores
27th May 2003, 05:30 am
Fuccaro, Spirex is an awesome routine, but as others have mentioned already, it would be great if the profile that is extruded would be normal to the extrusion path. I have made helixes in Mechanical Desktop 5 for a few projects, but this is the first time I have been somewhat succesful in Acad.
I am on a few CADD related forums, and there are only a small handful of programmers that make me say "Wow, how the heck did he do that!", and I will say that you are one of them.

Keep up the great work.

Flores

fuccaro
27th May 2003, 01:41 pm
Everybody is complaining about the flatness. Ok, I will change this but just as an option. Try to draw a drill or a twisted anything with the shape not in frontal position!
Other options? Observations? Comments?

superjari
27th May 2003, 04:27 pm
Something like this?
http://members1.chello.nl/~cohn/drill.jpg

After that I tried looking from a side view while running spirex and it gave a long stretched horizontal spiral of triangular shapes...

fuccaro
28th May 2003, 05:40 am
Thank you (THNX :) ) Superjari for the bugriport. The problem is the number of segments. This is the second issue on my "debug list".
Superjari please tell me (write me): in both of your images the shape is not in its place. Did you moved the shape or the resulted solid? Or it is an other bug? If you did not moved them, did you changed the UCS before the call of the lisp routine?
In the first image the shape is not a convex poligon so the routine can not generate a correct solid.

superjari
28th May 2003, 01:09 pm
I moved the solid afterwards so the UCS-icon wouldn't be in front of the solid...

Could you explain what a convex-polygon is?

fuccaro
28th May 2003, 01:23 pm
Thank you for your answer Superjari!
Pick two points inside of a polygon. The line segment between the two points may not intersect the boundary. If you can not find two internal points so that the line segment between them intersects the polygon, this means that the polygon is a convex one.
Draw a square. This is a convex polygon. Move a corner in the direction of the opposite corner. When the corner it is close to the opposite corner, the polygon is no more convex; drawing a segment between two internal points placed near the other two corners, the segment will intersect the polygon.
If I was clear enough please propose a new word for “convex”

superjari
28th May 2003, 03:11 pm
It's just my technical-English... :lol: My basic English is OK, but when talking about technical things I do not know enough...

Orbit
29th May 2003, 10:03 am
:roll:

convexed polygon

polygon= a geometrical plane figure with three or more straight sides
convex= with a surface that curves outward /used to describe a polygon with no interior angle greater than 180°

Orbit
29th May 2003, 08:54 pm
[/quote]If I was clear enough please propose a new word for “convex”

:P Fuccaro, I suggest a new name: curved polygon. Hey, it sounds good.
How about rounded polygon, neh.
convex= curved, what do you say about it? :wink:

I glued my eyes on Bryce today and got that inspiration, lucky me :P .

Flores
30th May 2003, 03:42 am
I moved the solid afterwards so the UCS-icon wouldn't be in front of the solid...

Could you explain what a convex-polygon is?

Fuccaro is right about the "covex polygon".
http://mathworld.wolfram.com/ConvexPolygon.html

Flores

helio_teixeira
2nd Jun 2004, 03:27 pm
:shock: when i try to use this lisp on a polygon,the radius of the spiral isn't the right one. It gets to big. I've turned off the osnap and ortho....

fuccaro
4th Jun 2004, 12:58 pm
Helio_teixeira

I was unable to reproduce the bug on my computer. Can you please post more explanations? Or an image?
Thank you.

Bulldog
3rd Mar 2006, 01:36 am
I'm trying to use teh SPIREX.LSP but cannot get any good results.

If someone could help me out with it I would appreciate a lot.

A have my made my path using the SPR.LSP and it is ok.
Then I made a triangle to follow this path. But no good results with SPIREX... I know I'm doing something wrong but I dont know what :(

Would be nice to have step by step explanation or even added with visual explanation would be the best.

You can mail me at mistral150@hotmail.com

Thx to all of you for the help.

Take note: I'm tying to do a wood screw :cry:

Sry for my english :oops:

CarlB
3rd Mar 2006, 02:09 am
You may not be doing anything wrong...it's probably how shapes are rotated as they are extruded.

See http://www.caddigest.com/subjects/autocad/tutorials/select/SCREWS/SCREWS3.HTM