Jump to content

help ! Extension Springs and CompressionSprings


DuanJinHui

Recommended Posts

Hello guys

 

I want use a routine to drawing the springs, need help.

 

The kinds of the spring

 

1.png

 

Parameter

20141122082253.jpg

 

The lengh(H), Outer diameter (D), Pitch(t), diameter(d), Spiral Angle (α=5°~9°), Number of turns(n), need enter by user .

 

if enter the lengh(H) ,so not enter the Pitch(t)

if enter the Pitch(t) ,so not enter the Lengh(H)

 

Enter parameter , pick a basic point ,

The key is drawing the end of springs ,maybe is difficult .

Edited by DuanJinHui
Link to comment
Share on other sites

try command: helix

or this the old similar thread

http://www.cadtutor.net/forum/showthread.php?78-Get-your-Helix-here!

http://www.cadtutor.net/forum/showthread.php?57899-Problem-With-Helix-Command

http://www.cadtutor.net/forum/showthread.php?89044-Helix-Along-a-Path&

see any idea helps?

 

at least you try something in command, it could help other programmers to understand.

you can draft simple code with command & comments, which the code not actually can work no worries but at least we know the steps.

example:

(defun c:test (/ )

(setq radius [color="red"]??[/color] );  say you put this [color="red"]??[/color] but we can help to do the rest
(setq point [color="red"]??[/color]); tell us what point in comment

(command "helix" ..... )  ; comment what to do this
(command "circle" ...)  ; what to do next
(command "sweep" ....) ; etc..
(command "union" ....)
...
...
) 

 

But nobody seems concerned.:(

 

this chinese foooood :facepalm:

 

if you can manually draw it , is it possible in lisp?

good luck :)

Link to comment
Share on other sites

My attempt...

 

(defun c:springs ( / el p rmax rmin n ch1 ch2 hmax hmin h pitch helix do ci pl sols ss )
 (command "_.UCS" "_W")
 (command "_.VIEW" "_SWISO")
 (command "_.ZOOM" "_C" "_non" '(0.0 0.0 0.0) "")
 (setq p '(0.0 0.0 0.0))
 (setq el (entlast))
 (initget 7)
 (setq rmax (getdist p "\nPick or specify radius of helix : "))
 (initget 7)
 (setq rmin (getdist "\nPick or specify radius of sweep circle along helix : "))
 (while (<= rmax rmin)
   (prompt "\nInvalid radius of sweep circle specification (must be < ") (princ (rtos rmax 2 50)) (prompt " ), please try specifying again...")
   (initget 7)
   (setq rmin (getdist "\nPick or specify radius of sweep circle along helix : "))
 )
 (initget 7)
 (setq n (getreal "\nSpecify number of turns of helix : "))
 (while (not (or (= 0.5 (- n (float (fix n)))) (= 0.0 (- n (float (fix n))))))
   (prompt "\nInvalid number of turns of helix (must be whole number, or whole+half number), please try specifying again...")
   (initget 7)
   (setq n (getreal "\nSpecify number of turns of helix : "))
 )
 (initget "Height Pitch")
 (setq ch1 (getkword "\nChoose specification [Height/Pitch] <Height> : "))
 (if (null ch1) (setq ch1 "Height"))
 (initget "Extension Compression")
 (setq ch2 (getkword "\nChoose type [Extension/Compression] <Extension> : "))
 (if (null ch2) (setq ch2 "Extension"))
 (if (eq ch2 "Extension")
   (if (eq ch1 "Height")
     (progn
       (initget 7)
       (setq hmax (getdist "\nPick or specify height : "))
       (setq h (- hmax (* 4 rmax) (* 4 rmin)))
       (setq hmin (/ h n))
       (while (or (< hmax (* 4 rmax)) (< hmin (* 2 rmin)))
         (prompt "\nInvalid height specification (must be >= ") (princ (rtos (+ (* 4 rmax) (* 2 (+ n 2) rmin)) 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq hmax (getdist "\nPick or specify height : "))
         (setq h (- hmax (* 4 rmax) (* 4 rmin)))
         (setq hmin (/ h n))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
     (progn
       (initget 7)
       (setq pitch (getreal "\nSpecify pitch angle in decimal degrees : "))
       (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       (while (not (<= (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") pitch))
         (prompt "\nInvalid pitch specification (must be >= ") (princ (rtos (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
         (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
   )
   (if (eq ch1 "Height")
     (progn
       (initget 7)
       (setq hmax (getdist "\nPick or specify height : "))
       (setq hmin (/ hmax n))
       (while (< hmin (* 2 rmin))
         (prompt "\nInvalid height specification (must be >= ") (princ (rtos (* 2 n rmin) 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq hmax (getdist "\nPick or specify height : "))
         (setq hmin (/ hmax n))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
     (progn
       (initget 7)
       (setq pitch (getreal "\nSpecify pitch angle in decimal degrees : "))
       (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       (while (not (<= (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") pitch))
         (prompt "\nInvalid pitch specification (must be >= ") (princ (rtos (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
         (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
   )
 )
 (setq do (getvar 'delobj))
 (setvar 'delobj 1)
 (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
 (command "_.SWEEP" ci "" helix)
 (while (> (getvar 'cmdactive) 0) (command ""))
 (entdel helix)
 (if (eq ch2 "Extension")
   (if (= 0.5 (- n (float (fix n))))
     (progn
       (setq h (* n hmin))
       (command "_.UCS" "_FRONT")
       (command "_.PLINE" "_non" (list rmax 0.0) "_non" '(0.0 0.0) "_non" (list 0.0 (- (* 2 rmin))) "_A" "_S" "_non" (list rmax (- (+ (* 2 rmin) rmax))) "_non" (list (- rmax) (- (+ (* 2 rmin) rmax))) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list rmax 0.0) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.PLINE" "_non" (list (- rmax) h) "_non" (list 0.0 h) "_non" (list 0.0 (+ (* 2 rmin) h)) "_A" "_S" "_non" (list (- rmax) (+ (* 2 rmin) rmax h)) "_non" (list rmax (+ (* 2 rmin) rmax h)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list (- rmax) h) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.UCS" "_P")
     )
     (progn
       (setq h (* n hmin))
       (command "_.UCS" "_FRONT")
       (command "_.PLINE" "_non" (list rmax 0.0) "_non" '(0.0 0.0) "_non" (list 0.0 (- (* 2 rmin))) "_A" "_S" "_non" (list rmax (- (+ (* 2 rmin) rmax))) "_non" (list (- rmax) (- (+ (* 2 rmin) rmax))) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list rmax 0.0) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.PLINE" "_non" (list rmax h) "_non" (list 0.0 h) "_non" (list 0.0 (+ (* 2 rmin) h)) "_A" "_S" "_non" (list rmax (+ (* 2 rmin) rmax h)) "_non" (list (- rmax) (+ (* 2 rmin) rmax h)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list rmax h) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.UCS" "_P")
     )
   )
   (if (= 0.5 (- n (float (fix n))))
     (progn
       (setq h (* n hmin))
       (command "_.PLINE" "_non" (list rmax 0.0) "_A" "_S" "_non" (list 0.0 (- rmax)) "_non" (list 0.0 rmax) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list (- rmax) 0.0 h) "_A" "_S" "_non" (list 0.0 (- rmax) h) "_non" (list 0.0 rmax h) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
     )
     (progn
       (setq h (* n hmin))
       (command "_.PLINE" "_non" (list rmax 0.0) "_A" "_S" "_non" (list 0.0 (- rmax)) "_non" (list 0.0 rmax) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list rmax 0.0 h) "_A" "_S" "_non" (list 0.0 rmax h) "_non" (list 0.0 (- rmax) h) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
     )
   )
 )
 (command "_.UCS" "_P")
 (while (setq el (if el (entnext el) (entnext)))
   (setq sols (cons el sols))
 )
 (setq ss (ssadd))
 (foreach sol sols
   (ssadd sol ss)
 )
 (command "_.UNION" ss "")
 (if (eq ch2 "Compression")
   (progn
     (setq el (entlast))
     (command "_.BOX" "_non" (list (- (+ rmax rmin)) (- (+ rmax rmin)) 0.0) "_non" (list (+ rmax rmin) (+ rmax rmin) h))
     (while (> (getvar 'cmdactive) 0) (command ""))
     (command "_.INTERSECT" el (entlast) "")
     (while (> (getvar 'cmdactive) 0) (command ""))
   )
 )
 (command "_.VSCURRENT" "_C")
 (setvar 'delobj do)
 (princ)
)

HTH, M.R.

BTW. Is maybe your brother famous snooker player Ding?...

Edited by marko_ribar
code modified again...
Link to comment
Share on other sites

try command: helix

or this the old similar thread

http://www.cadtutor.net/forum/showthread.php?78-Get-your-Helix-here!

http://www.cadtutor.net/forum/showthread.php?57899-Problem-With-Helix-Command

http://www.cadtutor.net/forum/showthread.php?89044-Helix-Along-a-Path&

see any idea helps?

 

at least you try something in command, it could help other programmers to understand.

you can draft simple code with command & comments, which the code not actually can work no worries but at least we know the steps.

example:

(defun c:test (/ )

(setq radius [color="red"]??[/color] );  say you put this [color="red"]??[/color] but we can help to do the rest
(setq point [color="red"]??[/color]); tell us what point in comment

(command "helix" ..... )  ; comment what to do this
(command "circle" ...)  ; what to do next
(command "sweep" ....) ; etc..
(command "union" ....)
...
...
) 

 

 

 

this chinese foooood :facepalm:

 

if you can manually draw it , is it possible in lisp?

good luck :)

 

 

Hi hanhphuc

 

Thank a lot ! I will carefully taste .

 

foooood ?? What does this mean?

Link to comment
Share on other sites

My attempt...

 

(defun c:springs ( / p rmax rmin n ch1 ch2 hmax hmin h pitch helix do ci pl )
 (command "_.UCS" "_W")
 (command "_.VIEW" "_SWISO")
 (command "_.ZOOM" "_C" "_non" '(0.0 0.0 0.0) "")
 (setq p '(0.0 0.0 0.0))
 (initget 7)
 (setq rmax (getdist p "\nPick or specify radius of helix : "))
 (initget 7)
 (setq rmin (getdist "\nPick or specify radius of sweep circle along helix : "))
 (while (<= rmax rmin)
   (prompt "\nInvalid radius of sweep circle specification (must be < ") (princ (rtos rmax 2 50)) (prompt " ), please try specifying again...")
   (initget 7)
   (setq rmin (getdist "\nPick or specify radius of sweep circle along helix : "))
 )
 (initget 7)
 (setq n (getreal "\nSpecify number of turns of helix : "))
 (while (not (or (= 0.5 (- n (float (fix n)))) (= 0.0 (- n (float (fix n))))))
   (prompt "\nInvalid number of turns of helix (must be whole number, or whole+half number), please try specifying again...")
   (initget 7)
   (setq n (getreal "\nSpecify number of turns of helix : "))
 )
 (initget "Height Pich")
 (setq ch1 (getkword "\nChoose specification [Height/Pich] <Height> : "))
 (if (null ch1) (setq ch1 "Height"))
 (initget "Extension Compression")
 (setq ch2 (getkword "\nChoose type [Extension/Compression] <Extension> : "))
 (if (null ch2) (setq ch2 "Extension"))
 (if (eq ch2 "Extension")
   (if (eq ch1 "Height")
     (progn
       (initget 7)
       (setq hmax (getdist "\nPick or specify height : "))
       (setq h (- hmax (* 4 rmax) (* 4 rmin)))
       (setq hmin (/ h n))
       (while (or (<= hmax (* 4 rmax)) (<= hmin (* 2 rmin)))
         (prompt "\nInvalid height specification (must be > ") (princ (rtos (+ (* 4 rmax) (* 2 (+ n 2) rmin)) 2 50)) (prompt " ), please try specifying again...")
         (initget 7)
         (setq hmax (getdist "\nPick or specify height : "))
         (setq h (- hmax (* 4 rmax) (* 4 rmin)))
         (setq hmin (/ h n))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
     (progn
       (initget 7)
       (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
       (while (not (<= (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") pitch))
         (prompt "\nInvalid pitch specification (must be >= ") (princ (rtos (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") 2 50)) (prompt " ), please try specifying again...")
         (initget 7)
         (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
         (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
   )
   (if (eq ch1 "Height")
     (progn
       (initget 7)
       (setq hmax (getdist "\nPick or specify height : "))
       (while (<= hmax (* 2 rmin))
         (prompt "\nInvalid height specification (must be > ") (princ (rtos (* 2 n rmin) 2 50)) (prompt " ), please try specifying again...")
         (initget 7)
         (setq hmax (getdist "\nPick or specify height : "))
         (setq hmin (/ hmax n))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
     (progn
       (initget 7)
       (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
       (while (not (<= (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") pitch))
         (prompt "\nInvalid pitch specification (must be >= ") (princ (rtos (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") 2 50)) (prompt " ), please try specifying again...")
         (initget 7)
         (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
         (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
   )
 )
 (setq do (getvar 'delobj))
 (setvar 'delobj 1)
 (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
 (command "_.SWEEP" ci "" helix)
 (while (> (getvar 'cmdactive) 0) (command ""))
 (entdel helix)
 (if (eq ch2 "Extension")
   (if (= 0.5 (- n (float (fix n))))
     (progn
       (setq h (* n hmin))
       (command "_.UCS" "_FRONT")
       (command "_.PLINE" "_non" (list rmax 0.0) "_non" '(0.0 0.0) "_non" (list 0.0 (- (* 2 rmin))) "_A" "_S" "_non" (list rmax (- (+ (* 2 rmin) rmax))) "_non" (list (- rmax) (- (+ (* 2 rmin) rmax))) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list (- rmax) h) "_non" (list 0.0 h) "_non" (list 0.0 (+ (* 2 rmin) h)) "_A" "_S" "_non" (list (- rmax) (+ (* 2 rmin) rmax h)) "_non" (list rmax (+ (* 2 rmin) rmax h)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.UCS" "_P")
     )
     (progn
       (setq h (* n hmin))
       (command "_.UCS" "_FRONT")
       (command "_.PLINE" "_non" (list rmax 0.0) "_non" '(0.0 0.0) "_non" (list 0.0 (- (* 2 rmin))) "_A" "_S" "_non" (list rmax (- (+ (* 2 rmin) rmax))) "_non" (list (- rmax) (- (+ (* 2 rmin) rmax))) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list rmax h) "_non" (list 0.0 h) "_non" (list 0.0 (+ (* 2 rmin) h)) "_A" "_S" "_non" (list rmax (+ (* 2 rmin) rmax h)) "_non" (list (- rmax) (+ (* 2 rmin) rmax h)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.UCS" "_P")
     )
   )
   (if (= 0.5 (- n (float (fix n))))
     (progn
       (setq h (* n hmin))
       (command "_.PLINE" "_non" (list rmax 0.0) "_A" "_S" "_non" (list 0.0 (- rmax)) "_non" (list 0.0 rmax) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list (- rmax) 0.0 h) "_A" "_S" "_non" (list 0.0 (- rmax) h) "_non" (list 0.0 rmax h) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
     )
     (progn
       (setq h (* n hmin))
       (command "_.PLINE" "_non" (list rmax 0.0) "_A" "_S" "_non" (list 0.0 (- rmax)) "_non" (list 0.0 rmax) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list rmax 0.0 h) "_A" "_S" "_non" (list 0.0 rmax h) "_non" (list 0.0 (- rmax) h) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
     )
   )
 )
 (command "_.UCS" "_P")
 (command "_.VSCURRENT" "_C")
 (setvar 'delobj do)
 (princ)
)

HTH, M.R.

 

Hi marko.

Ill give it a run and will get back to you :-)

BTW. Is maybe your brother famous snooker player Ding?...

 

WOW! You know this ? Ding Jun hui ? :thumbsup: Have you seen him play?

Link to comment
Share on other sites

My attempt...

 

 

Hi marko

I test use autocad 2010.

 

Pick or specify radius of helix : 10

Pick or specify radius of sweep circle along helix : 1

Specify number of turns of helix : 20

Choose specification [Height/Pich] : P

Choose type [Extension/Compression] : E

Specify pich angle in decimal degrees : 9

_.HELIX

Number of turns = 20.0000 Twist=CCW

Specify center point of base:

Specify base radius or [Diameter] : 10.00000000000000

Specify top radius or [Diameter] : 10.00000000000000

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] : _T

Enter number of turns : 20.00000000000000

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] : _H

Specify distance between turns :

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] :

Command: _.SWEEP

Current wire frame density: ISOLINES=4

Select objects to sweep: 1 found

Select objects to sweep:

Select sweep path or [Alignment/Base point/Scale/Twist]:

Unable to sweep the selected object.

Command: ; error: bad argument type: numberp: nil

---------------------------------------------------------------------------------------------------

Pick or specify radius of helix : 10

Pick or specify radius of sweep circle along helix : 1

Specify number of turns of helix : 20

Choose specification [Height/Pich] : P

Choose type [Extension/Compression] : C

Specify pich angle in decimal degrees : 9

_.HELIX

Number of turns = 1.0000 Twist=CCW

Specify center point of base:

Specify base radius or [Diameter] : 10.00000000000000

Specify top radius or [Diameter] : 10.00000000000000

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] : _T

Enter number of turns : 20.00000000000000

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] : _H

Specify distance between turns :

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] :

Command: _.SWEEP

Current wire frame density: ISOLINES=4

Select objects to sweep: 1 found

Select objects to sweep:

Select sweep path or [Alignment/Base point/Scale/Twist]:

Unable to sweep the selected object.

Command: ; error: bad argument type: numberp: nil

---------------------------------------------------------------------------------------------------

 

Pick or specify radius of helix : 10

Pick or specify radius of sweep circle along helix : 1

Specify number of turns of helix : 20

Choose specification [Height/Pich] : H

Choose type [Extension/Compression] : C

Pick or specify height : 100

_.HELIX

Number of turns = 20.0000 Twist=CCW

Specify center point of base:

Specify base radius or [Diameter] : 10.00000000000000

Specify top radius or [Diameter] : 10.00000000000000

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] : _T

Enter number of turns : 20.00000000000000

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] : _H

Specify distance between turns :

Specify helix height or [Axis endpoint/Turns/turn Height/tWist] :

Command: _.SWEEP

Current wire frame density: ISOLINES=4

Select objects to sweep: 1 found

Select objects to sweep:

Select sweep path or [Alignment/Base point/Scale/Twist]:

Unable to sweep the selected object.

Command: ; error: bad argument type: numberp: nil

Link to comment
Share on other sites

DJinHui, I've modified my code again... Please copy+paste it into notepad and save again as *.lsp... Then try again and follow important info ab Height and Pitch values you must enter in order for correct helix to be made... At first enter some small distance or angle, and then input larger one than that was prompted to text screen of ACAD...

 

Inform me again if you have some problems...

M.R.

Link to comment
Share on other sites

DJinHui, I've modified my code again... Please copy+paste it into notepad and save again as *.lsp... Then try again and follow important info ab Height and Pitch values you must enter in order for correct helix to be made... At first enter some small distance or angle, and then input larger one than that was prompted to text screen of ACAD...

 

Inform me again if you have some problems...

M.R.

Hi marko.

many thinks!

I tested, Find a little defective.

Compression Springs, have overlap at ends.

6.png

 

I think can make it shorter

7.png

 

if not work at wcs, will be like this:

5.png

 

Extension Springs ,The ends of the transition is not smooth.

8.png

9.png

 

can do it like this ?

10.png

 

If difficult , can like this

20141126013255.jpg

 

 

 

Thanks again ,marko:thumbsup:

Link to comment
Share on other sites

Here, try this new version...

 

(defun c:springs ( / el p rmax rmin n ch1 ch2 hmax hmin h pitch helix do ci pl sols ss )
 (command "_.UCS" "_W")
 (command "_.VIEW" "_SWISO")
 (command "_.ZOOM" "_C" "_non" '(0.0 0.0 0.0) "")
 (setq p '(0.0 0.0 0.0))
 (setq el (entlast))
 (initget 7)
 (setq rmax (getdist p "\nPick or specify radius of helix : "))
 (initget 7)
 (setq rmin (getdist "\nPick or specify radius of sweep circle along helix : "))
 (while (<= rmax rmin)
   (prompt "\nInvalid radius of sweep circle specification (must be < ") (princ (rtos rmax 2 50)) (prompt " ), please try specifying again...")
   (initget 7)
   (setq rmin (getdist "\nPick or specify radius of sweep circle along helix : "))
 )
 (initget 7)
 (setq n (getreal "\nSpecify number of turns of helix : "))
 (while (not (or (= 0.5 (- n (float (fix n)))) (= 0.0 (- n (float (fix n))))))
   (prompt "\nInvalid number of turns of helix (must be whole number, or whole+half number), please try specifying again...")
   (initget 7)
   (setq n (getreal "\nSpecify number of turns of helix : "))
 )
 (initget "Height Pitch")
 (setq ch1 (getkword "\nChoose specification [Height/Pitch] <Height> : "))
 (if (null ch1) (setq ch1 "Height"))
 (initget "Extension Compression")
 (setq ch2 (getkword "\nChoose type [Extension/Compression] <Extension> : "))
 (if (null ch2) (setq ch2 "Extension"))
 (if (eq ch2 "Extension")
   (if (eq ch1 "Height")
     (progn
       (initget 7)
       (setq hmax (getdist "\nPick or specify height : "))
       (setq h (- hmax (* 4 rmax)))
       (setq hmin (/ h n))
       (while (or (< hmax (* 4 rmax)) (< hmin (* 2 rmin)))
         (prompt "\nInvalid height specification (must be >= ") (princ (rtos (+ (* 4 rmax) (* 2 n rmin)) 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq hmax (getdist "\nPick or specify height : "))
         (setq h (- hmax (* 4 rmax)))
         (setq hmin (/ h n))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
     (progn
       (initget 7)
       (setq pitch (getreal "\nSpecify pitch angle in decimal degrees : "))
       (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       (while (not (<= (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") pitch))
         (prompt "\nInvalid pitch specification (must be >= ") (princ (rtos (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
         (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
   )
   (if (eq ch1 "Height")
     (progn
       (initget 7)
       (setq hmax (getdist "\nPick or specify height : "))
       (setq hmin (/ hmax n))
       (while (< hmin (* 2 rmin))
         (prompt "\nInvalid height specification (must be >= ") (princ (rtos (* 2 n rmin) 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq hmax (getdist "\nPick or specify height : "))
         (setq hmin (/ hmax n))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
     (progn
       (initget 7)
       (setq pitch (getreal "\nSpecify pitch angle in decimal degrees : "))
       (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       (while (not (<= (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") pitch))
         (prompt "\nInvalid pitch specification (must be >= ") (princ (rtos (cvunit (atan (/ rmin (* pi rmax))) "radian" "degree") 2 50)) (prompt "), please try specifying again...")
         (initget 7)
         (setq pitch (getreal "\nSpecify pich angle in decimal degrees : "))
         (setq hmin (* 2 pi rmax (/ (sin (cvunit pitch "degree" "radian")) (cos (cvunit pitch "degree" "radian")))))
       )
       (command "_.HELIX" p rmax rmax "_T" n "_H" hmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (setq helix (entlast))
     )
   )
 )
 (setq do (getvar 'delobj))
 (setvar 'delobj 1)
 (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
 (command "_.SWEEP" ci "" helix)
 (while (> (getvar 'cmdactive) 0) (command ""))
 (entdel helix)
 (if (eq ch2 "Extension")
   (if (= 0.5 (- n (float (fix n))))
     (progn
       (setq h (* n hmin))
       (command "_.UCS" "_FRONT")
       (command "_.PLINE" "_non" (list rmax 0.0) "_non" (list rmax (- rmax)) "_A" "_S" "_non" (list 0.0 (- (* 2 rmax))) "_non" (list (- rmax) (- rmax)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list rmax 0.0) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.PLINE" "_non" (list (- rmax) h) "_non" (list (- rmax) (+ h rmax)) "_A" "_S" "_non" (list 0.0 (+ (* 2 rmax) h)) "_non" (list rmax (+ rmax h)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list (- rmax) h) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.UCS" "_P")
     )
     (progn
       (setq h (* n hmin))
       (command "_.UCS" "_FRONT")
       (command "_.PLINE" "_non" (list rmax 0.0) "_non" (list rmax (- rmax)) "_A" "_S" "_non" (list 0.0 (- (* 2 rmax))) "_non" (list (- rmax) (- rmax)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list rmax 0.0) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.PLINE" "_non" (list rmax h) "_non" (list rmax (+ h rmax)) "_A" "_S" "_non" (list 0.0 (+ (* 2 rmax) h)) "_non" (list (- rmax) (+ rmax h)) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.SPHERE" "_non" (list rmax h) rmin)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (command "_.UCS" "_P")
     )
   )
   (if (= 0.5 (- n (float (fix n))))
     (progn
       (setq h (* n hmin))
       (command "_.PLINE" "_non" (list rmax 0.0) "_A" "_S" "_non" (list 0.0 (- rmax)) "_non" (list (- rmax) 0.0) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list (- rmax) 0.0 h) "_A" "_S" "_non" (list 0.0 (- rmax) h) "_non" (list rmax 0.0 h) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
     )
     (progn
       (setq h (* n hmin))
       (command "_.PLINE" "_non" (list rmax 0.0) "_A" "_S" "_non" (list 0.0 (- rmax)) "_non" (list (- rmax) 0.0) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
       (command "_.PLINE" "_non" (list rmax 0.0 h) "_A" "_S" "_non" (list 0.0 rmax h) "_non" (list (- rmax) 0.0 h) "")
       (setq pl (entlast))
       (setq ci (entmakex (list '(0 . "CIRCLE") '(10 0.0 0.0 0.0) (cons 40 rmin))))
       (command "_.SWEEP" ci "" pl)
       (while (> (getvar 'cmdactive) 0) (command ""))
       (entdel pl)
     )
   )
 )
 (command "_.UCS" "_P")
 (while (setq el (if el (entnext el) (entnext)))
   (setq sols (cons el sols))
 )
 (setq ss (ssadd))
 (foreach sol sols
   (ssadd sol ss)
 )
 (command "_.UNION" ss "")
 (if (eq ch2 "Compression")
   (progn
     (setq el (entlast))
     (command "_.BOX" "_non" (list (- (+ rmax rmin)) (- (+ rmax rmin)) 0.0) "_non" (list (+ rmax rmin) (+ rmax rmin) h))
     (while (> (getvar 'cmdactive) 0) (command ""))
     (command "_.INTERSECT" el (entlast) "")
     (while (> (getvar 'cmdactive) 0) (command ""))
   )
 )
 (command "_.VSCURRENT" "_C")
 (setvar 'delobj do)
 (princ)
)

HTH, M.R. (Thought you could do fix on your own...)

Edited by marko_ribar
Link to comment
Share on other sites

Here, try this new version...

 

HTH, M.R. (Thought you could do fix on your own...)

 

Hi marko.

Thank you so much!

Drawing Compression Springs have a little problem.

 

11.png

Link to comment
Share on other sites

Hi marko.

Thank you so much!

 

You're welcome...

 

Drawing Compression Springs have a little problem.

[ATTACH=CONFIG]51769[/ATTACH]

 

Oh, I see, I've modified it again... Thanks for checking...

Kr. M.R.

Link to comment
Share on other sites

You're welcome...

 

 

 

Oh, I see, I've modified it again... Thanks for checking...

Kr. M.R.

 

Hi marko, It's cool !

You help me so much, No words can express my thanks to you ! :beer:

Link to comment
Share on other sites

Hi marko, It's cool !

You help me so much, No words can express my thanks to you ! :beer:

 

You're welcome DuanJinHui...

 

Still I've modified both my functions again to include accepting of minimal Height/Pitch input, but however when that is the case somehow CAD is unable to do UNION of 3D SOLIDS, so this is possible but with some lacks in Modelling operations of ACAD itself, both codes are though correct...

 

All the best, M.R.

Link to comment
Share on other sites

Here, try this new version...

 

 

marko , great job!

It's works perfect in Acad2012 , but can't work normal in Acad2007 !

can you add error function into ?

Link to comment
Share on other sites

marko , great job!

It's works perfect in Acad2012 , but can't work normal in Acad2007 !

can you add error function into ?

 

I think HELIX command was introduced since A2008 onwards... So I can't help I am afraid with this one...

Link to comment
Share on other sites

I think HELIX command was introduced since A2008 onwards... So I can't help I am afraid with this one...

 

a2007 can run "helix" command , I think parameter is not the same .:roll:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...