(defun c:tube ( / @pto @pt2 os cm)
(if (setq @pto (getpoint "\nSpecify base point: "))
(progn
(setq @pt2 (getpoint "\nSpecify second point: "))
(setq cm (getvar "cmdecho")) (setvar "cmdecho" 0)
(command "_undo" "_a" "_on" "_undo" "_group")
(if (null #ra1) (setq #ra1 5.0) )
(if (null #ra2) (setq #ra2 8.0) )
(if (null #len) (setq #len 20.0) )
(setq #cr (getdist @pto (strcat "\nEnter inner diameter: <" (rtos #ra1) "> ")))
(if #cr (setq #ra1 #cr) ) (initget "T")
(setq #cr (getdist @pto (strcat "\nEnter Outer diameter OR [Thickness (T)]: <" (rtos #ra2) "> ")))
(if (member #cr (list "t" "T"))
(if (setq #cr (getreal (strcat "\nEnter Thickness: <" (rtos (- #ra2 #ra1)) "> ")))
(setq #ra2 (+ #ra1 #cr))
)
(if #cr (setq #ra2 #cr) )
)
(setq #cr (getdist @pto (strcat "\nEnter length: <" (rtos #len) "> ")))
(if #cr (setq #len #cr) )
(setq os (getvar "osmode")) (setvar "osmode" 0)
(setq @p1 (polar @pto 0 (/ #ra1 2.0)))
(setq @p2 (polar (polar @pto 0 (/ #ra2 2.0)) (* pi 1.5) #len))
(command "_.Rectang" @p1 @p2 "_.Revolve" "_l" "" @pto (polar @pto (/ pi 2) 1) 360)
(command "_.Rotate3d" "_l" "" "_Z" @pto "_r" @pto (polar @pto (/ pi 2) -1) @pto @pt2 )
(command "_undo" "_e")
(setvar "osmode" os)
(setvar "cmdecho" cm)
(princ)
)
)
)
Just rotate tube to pt2 on Z axis instead of rotation by 90 degrees in X axis. Try this:Code: [Select](defun c:tube ( / @pto @pt2 os cm)
(if (setq @pto (getpoint "\nSpecify base point: "))
(progn
(setq @pt2 (getpoint "\nSpecify second point: "))
(setq cm (getvar "cmdecho")) (setvar "cmdecho" 0)
(command "_undo" "_a" "_on" "_undo" "_group")
(if (null #ra1) (setq #ra1 5.0) )
(if (null #ra2) (setq #ra2 8.0) )
(if (null #len) (setq #len 20.0) )
(setq #cr (getdist @pto (strcat "\nEnter inner diameter: <" (rtos #ra1) "> ")))
(if #cr (setq #ra1 #cr) ) (initget "T")
(setq #cr (getdist @pto (strcat "\nEnter Outer diameter OR [Thickness (T)]: <" (rtos #ra2) "> ")))
(if (member #cr (list "t" "T"))
(if (setq #cr (getreal (strcat "\nEnter Thickness: <" (rtos (- #ra2 #ra1)) "> ")))
(setq #ra2 (+ #ra1 #cr))
)
(if #cr (setq #ra2 #cr) )
)
(setq #cr (getdist @pto (strcat "\nEnter length: <" (rtos #len) "> ")))
(if #cr (setq #len #cr) )
(setq os (getvar "osmode")) (setvar "osmode" 0)
(setq @p1 (polar @pto 0 (/ #ra1 2.0)))
(setq @p2 (polar (polar @pto 0 (/ #ra2 2.0)) (* pi 1.5) #len))
(command "_.Rectang" @p1 @p2 "_.Revolve" "_l" "" @pto (polar @pto (/ pi 2) 1) 360)
(command "_.Rotate3d" "_l" "" "_Z" @pto "_r" @pto (polar @pto (/ pi 2) -1) @pto @pt2 )
(command "_undo" "_e")
(setvar "osmode" os)
(setvar "cmdecho" cm)
(princ)
)
)
)
TryCode - Auto/Visual Lisp: [Select]
Maybe something like thisCode - Lisp: [Select]
(setq pt (getpoint "\n Select first point along path: ")) (setq pt2 (getpoint "\n Select second point along path: ")) (setq rad (getdist "\n Enter outer radius: ")) (setq thk (getdist "\n Enter thickness: ")) (setq vec (mapcar (function -) pt2 pt)) (entmake (list '(0 . "CIRCLE") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 10 (trans pt 1 vec)) (cons 40 rad) (cons 210 vec) ) ) (setq ent (entlast)) (entmake (list '(0 . "CIRCLE") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 10 (trans pt 1 vec)) (cons 40 (- rad thk)) (cons 210 vec) ) ) (command "._extrude" (entlast) ent "" (sqrt (apply (function +) (mapcar (function (lambda ( a ) (* a a))) vec))))
Maybe something like thisCode - Lisp: [Select]
(setq pt (getpoint "\n Select first point along path: ")) (setq pt2 (getpoint "\n Select second point along path: ")) (setq rad (getdist "\n Enter outer radius: ")) (setq thk (getdist "\n Enter thickness: ")) (setq vec (mapcar (function -) pt2 pt)) (entmake (list '(0 . "CIRCLE") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 10 (trans pt 1 vec)) (cons 40 rad) (cons 210 vec) ) ) (setq ent (entlast)) (entmake (list '(0 . "CIRCLE") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 10 (trans pt 1 vec)) (cons 40 (- rad thk)) (cons 210 vec) ) ) (command "._extrude" (entlast) ent "" (sqrt (apply (function +) (mapcar (function (lambda ( a ) (* a a))) vec))))
.. ok, this is I want , But I found , Can't draw a tube along the Z axis .
I specify second point at Z axis ,But still draw on X axis . :cry:
.. ok, this is I want , But I found , Can't draw a tube along the Z axis .
I specify second point at Z axis ,But still draw on X axis . :cry:
Let's do a little modifcation to bring an option to use your old code:
(command "_.Rotate3d" "_l" "" "_X" @pto 90)
with
(command "_.Rotate3d" "_l" "" "_X" @pto 270)
for draw tube like "positive=up", "negative=down".
<snip>
Tim, I test your code , Z axis have flaw. see demo
I would use path option of extrude like Tim suggested...
AIberto,
Welcome to the Swamp.
Would this task be a homework assignment?
Thanks
Alan
<snip>
Tim, I test your code , Z axis have flaw. see demo
I think the issue is that the distance calculated is always positive, and based on the pick point order it should be negative. I guess one could see which way the vector variable 'vec' is pointing, and tell the distance to be positive or negative.
Or you can just use the path option, and it will extrude it along the whole path.
Or you can just leave out the last part of the command, and let it be open ended so the user can select the end point of the extrusion.
Or... (I am sure there are more options)
Hi, if you still want to use your old code you can simply specify positive/negative length to change Z direction up/down and replaceCode: [Select](command "_.Rotate3d" "_l" "" "_X" @pto 90)
withCode: [Select]for draw tube like "positive=up", "negative=down".
(command "_.Rotate3d" "_l" "" "_X" @pto 270)
Alberto, I've modified my code :
this :Code - Auto/Visual Lisp: [Select]
should be :Code - Auto/Visual Lisp: [Select]