DuanJinHui Posted November 22, 2014 Share Posted November 22, 2014 (edited) Hello guys I want use a routine to drawing the springs, need help. The kinds of the spring Parameter 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 November 26, 2014 by DuanJinHui Quote Link to comment Share on other sites More sharing options...
AIberto Posted November 22, 2014 Share Posted November 22, 2014 Good thread, hope someone can help ! Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 24, 2014 Author Share Posted November 24, 2014 Good thread, hope someone can help ! Thank you Alberto, But nobody seems concerned. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted November 24, 2014 Share Posted November 24, 2014 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 if you can manually draw it , is it possible in lisp? good luck Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 24, 2014 Share Posted November 24, 2014 (edited) 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 November 26, 2014 by marko_ribar code modified again... Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 25, 2014 Author Share Posted November 25, 2014 try command: helixor 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 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? Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 25, 2014 Author Share Posted November 25, 2014 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 ? Have you seen him play? Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 25, 2014 Author Share Posted November 25, 2014 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 Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 25, 2014 Share Posted November 25, 2014 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. Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 25, 2014 Author Share Posted November 25, 2014 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. I think can make it shorter if not work at wcs, will be like this: Extension Springs ,The ends of the transition is not smooth. can do it like this ? If difficult , can like this Thanks again ,marko:thumbsup: Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 25, 2014 Share Posted November 25, 2014 (edited) 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 November 26, 2014 by marko_ribar Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 26, 2014 Author Share Posted November 26, 2014 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. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 26, 2014 Share Posted November 26, 2014 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. Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted November 26, 2014 Author Share Posted November 26, 2014 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 ! Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 26, 2014 Share Posted November 26, 2014 Hi marko, It's cool !You help me so much, No words can express my thanks to you ! 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. Quote Link to comment Share on other sites More sharing options...
AIberto Posted November 26, 2014 Share Posted November 26, 2014 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 ? Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 26, 2014 Share Posted November 26, 2014 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... Quote Link to comment Share on other sites More sharing options...
AIberto Posted November 26, 2014 Share Posted November 26, 2014 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 . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.