TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: AIberto on June 29, 2015, 05:02:19 AM

Title: Draw a tube ,need help.
Post by: AIberto on June 29, 2015, 05:02:19 AM
Dear all.

I use this code draw a tube
Steps
1.Specify base point
2.Enter inner diameter
3.Enter Outer diameter
4.Enter length
It will draw a tube along the Z axis .

I need a little change.  not along Z axis
1.Specify base point (pt1)
2.Specify another point , (pt2) ,So pt1 & pt2 is the axis of rotation.
3.Enter inner diameter
4.Enter Outer diameter
5.Enter length

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tube ( )
  2.   (if (setq @pto (getpoint "\nSpecify base point: "))
  3.    (progn
  4.     (setq cm (getvar "cmdecho")) (setvar "cmdecho" 0)
  5.     (command "undo" "a" "on" "undo" "group")
  6.     (if (null #ra1) (setq #ra1 5.0) )
  7.     (if (null #ra2) (setq #ra2 8.0) )
  8.     (if (null #len) (setq #len 20.0) )
  9.     (setq #cr (getdist @pto (strcat "\nEnter inner diameter: <" (rtos #ra1) "> ")))
  10.     (if #cr (setq #ra1 #cr) ) (initget "T")
  11.     (setq #cr (getdist @pto (strcat "\nEnter Outer diameter OR [Thickness (T)]: <" (rtos #ra2) "> ")))
  12.     (if (member #cr (list "t" "T"))
  13.      (if (setq #cr (getreal (strcat "\nEnter Thickness: <" (rtos (- #ra2 #ra1)) "> ")))
  14.       (setq #ra2 (+ #ra1 #cr))
  15.      )
  16.      (if #cr (setq #ra2 #cr) )
  17.     )
  18.     (setq #cr (getdist @pto (strcat "\nEnter length: <" (rtos #len) "> ")))
  19.     (if #cr (setq #len #cr) )
  20.     (setq os (getvar "osmode")) (setvar "osmode" 0)
  21.     (setq @p1 (polar @pto 0 (/ #ra1 2.0)))
  22.     (setq @p2 (polar (polar @pto 0 (/ #ra2 2.0)) (* pi 1.5) #len))
  23.     (command "_.Rectang" @p1 @p2 "_.Revolve" "l" "" @pto (polar @pto (/ pi 2) 1) 360)
  24.     (command "_.Rotate3d" "l" "" "X" @pto 90) (command "undo" "e")
  25.     (setvar "osmode" os)
  26.     (setvar "cmdecho" cm)
  27.     (princ)
  28.    )
  29.   )
  30. )
  31.  
Title: Re: Draw a tube ,need help.
Post by: ChrisCarlson on June 29, 2015, 08:54:21 AM
You can either,

a) Save current UCS state, re-orientate UCS to pt1/pt2, revert back to previous UCS
b) Rotate drawn tube from base point to pt2
Title: Re: Draw a tube ,need help.
Post by: NICK_VNV on June 29, 2015, 09:01:03 AM
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)
   )
  )
)
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 29, 2015, 10:00:30 AM
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)
   )
  )
)

Dear Sir
Thanks for your help , But still not perfect.
When specify second point , May be I will forget where is the first point .
SO, when specify second point , can like this ?



Title: Re: Draw a tube ,need help.
Post by: ChrisCarlson on June 29, 2015, 10:07:28 AM
Try

Code - Auto/Visual Lisp: [Select]
  1.   (if (setq @pto (getpoint "\nSpecify base point: "))
  2.    (progn
  3.     (setq @pt2 (getpoint @pto "\nSpecify second point: "))
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 29, 2015, 10:30:46 AM
Try

Code - Auto/Visual Lisp: [Select]
  1.   (if (setq @pto (getpoint "\nSpecify base point: "))
  2.    (progn
  3.     (setq @pt2 (getpoint @pto "\nSpecify second point: "))

Thank you , Sir
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:
Title: Re: Draw a tube ,need help.
Post by: T.Willey on June 29, 2015, 10:57:58 AM
Maybe something like this

Code - Lisp: [Select]
  1. (setq pt (getpoint "\n Select first point along path: "))
  2. (setq pt2 (getpoint "\n Select second point along path: "))
  3. (setq rad (getdist "\n Enter outer radius: "))
  4. (setq thk (getdist "\n Enter thickness: "))
  5. (setq vec (mapcar (function -) pt2 pt))
  6. (entmake
  7.     (list
  8.         '(0 . "CIRCLE")
  9.         '(100 . "AcDbEntity")
  10.         '(100 . "AcDbCircle")
  11.         (cons 10 (trans pt 1 vec))
  12.         (cons 40 rad)
  13.         (cons 210 vec)
  14.     )
  15. )
  16. (setq ent (entlast))
  17. (entmake
  18.     (list
  19.         '(0 . "CIRCLE")
  20.         '(100 . "AcDbEntity")
  21.         '(100 . "AcDbCircle")
  22.         (cons 10 (trans pt 1 vec))
  23.         (cons 40 (- rad thk))
  24.         (cons 210 vec)
  25.     )
  26. )
  27. (command "._extrude" (entlast) ent "" (sqrt (apply (function +) (mapcar (function (lambda ( a ) (* a a))) vec))))
  28.  
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 29, 2015, 08:34:22 PM
Maybe something like this

Code - Lisp: [Select]
  1. (setq pt (getpoint "\n Select first point along path: "))
  2. (setq pt2 (getpoint "\n Select second point along path: "))
  3. (setq rad (getdist "\n Enter outer radius: "))
  4. (setq thk (getdist "\n Enter thickness: "))
  5. (setq vec (mapcar (function -) pt2 pt))
  6. (entmake
  7.     (list
  8.         '(0 . "CIRCLE")
  9.         '(100 . "AcDbEntity")
  10.         '(100 . "AcDbCircle")
  11.         (cons 10 (trans pt 1 vec))
  12.         (cons 40 rad)
  13.         (cons 210 vec)
  14.     )
  15. )
  16. (setq ent (entlast))
  17. (entmake
  18.     (list
  19.         '(0 . "CIRCLE")
  20.         '(100 . "AcDbEntity")
  21.         '(100 . "AcDbCircle")
  22.         (cons 10 (trans pt 1 vec))
  23.         (cons 40 (- rad thk))
  24.         (cons 210 vec)
  25.     )
  26. )
  27. (command "._extrude" (entlast) ent "" (sqrt (apply (function +) (mapcar (function (lambda ( a ) (* a a))) vec))))
  28.  


Thank you ,Tim ,
Your code only draw two cylinder ?  and I need enter the length , not pt->pt2 , pt2 is only confirm the direction.
Title: Re: Draw a tube ,need help.
Post by: T.Willey on June 29, 2015, 10:04:36 PM
If that is the case, then I would just have the user select the entity desired to act as the path of the extrusion, and just pass that to the extrude command instead of a distance.

You could use one of the points with either 'ssget' or 'nentselp' to select an entity based on a point, and pass that to the extrude command.  You will have to change the command call a little, telling it you want to use the 'path' option.

You're welcome.
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 03:06:54 AM
Maybe something like this

Code - Lisp: [Select]
  1. (setq pt (getpoint "\n Select first point along path: "))
  2. (setq pt2 (getpoint "\n Select second point along path: "))
  3. (setq rad (getdist "\n Enter outer radius: "))
  4. (setq thk (getdist "\n Enter thickness: "))
  5. (setq vec (mapcar (function -) pt2 pt))
  6. (entmake
  7.     (list
  8.         '(0 . "CIRCLE")
  9.         '(100 . "AcDbEntity")
  10.         '(100 . "AcDbCircle")
  11.         (cons 10 (trans pt 1 vec))
  12.         (cons 40 rad)
  13.         (cons 210 vec)
  14.     )
  15. )
  16. (setq ent (entlast))
  17. (entmake
  18.     (list
  19.         '(0 . "CIRCLE")
  20.         '(100 . "AcDbEntity")
  21.         '(100 . "AcDbCircle")
  22.         (cons 10 (trans pt 1 vec))
  23.         (cons 40 (- rad thk))
  24.         (cons 210 vec)
  25.     )
  26. )
  27. (command "._extrude" (entlast) ent "" (sqrt (apply (function +) (mapcar (function (lambda ( a ) (* a a))) vec))))
  28.  

Tim, I test your code ,  Z axis  have flaw.  see demo

Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 03:09:41 AM
Still have flaw... Z axis
Code - Auto/Visual Lisp: [Select]
  1. (setq pt (getpoint "\n Specify base point: "))
  2. (setq pt2 (getpoint pt "\nSpecify the direction: "))
  3. (setq rad (getdist "\n Enter inner diameter: "))
  4. (setq otr (getdist "\n Enter Outer diameter: "))
  5. (setq len (getdist "\n Enter length: "))
  6. (setq vec (mapcar (function -) pt2 pt))
  7.     (list
  8.         '(0 . "CIRCLE")
  9.         '(100 . "AcDbEntity")
  10.         '(100 . "AcDbCircle")
  11.         (cons 10 (trans pt 1 vec))
  12.         (cons 40 (* rad 0.5))
  13.         (cons 210 vec)
  14.     )
  15. )
  16. (setq ent1 (entlast))
  17. (command "_region" ent1 "")
  18. (setq ss1 (entlast))
  19.     (list
  20.         '(0 . "CIRCLE")
  21.         '(100 . "AcDbEntity")
  22.         '(100 . "AcDbCircle")
  23.         (cons 10 (trans pt 1 vec))
  24.         (cons 40 (* otr 0.5))
  25.         (cons 210 vec)
  26.     )
  27. )
  28. (setq ent2 (entlast))
  29. (command "_region" ent2 "")
  30. (setq ss2 (entlast))
  31. (command "_subtract" ss2 "" ss1 "")
  32. (command "_extrude" (entlast) "" len)
  33.  
Title: Re: Draw a tube ,need help.
Post by: NICK_VNV on June 30, 2015, 03:35:47 AM
.. 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:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tube ( /  @pto @pt2 os cm)
  2.   (if (setq @pto (getpoint "\nSpecify base point: "))
  3.    (progn
  4.     (setq @pt2 (getpoint @pto "\nSpecify second point or press <Enter> to draw a tube along the Z axis: "))
  5.     (setq cm (getvar "cmdecho")) (setvar "cmdecho" 0)
  6.     (command "_undo" "_a" "_on" "_undo" "_group")
  7.     (if (null #ra1) (setq #ra1 5.0) )
  8.     (if (null #ra2) (setq #ra2 8.0) )
  9.     (if (null #len) (setq #len 20.0) )
  10.     (setq #cr (getdist @pto (strcat "\nEnter inner diameter: <" (rtos #ra1) "> ")))
  11.     (if #cr (setq #ra1 #cr) ) (initget "T")
  12.     (setq #cr (getdist @pto (strcat "\nEnter Outer diameter OR [Thickness (T)]: <" (rtos #ra2) "> ")))
  13.     (if (member #cr (list "t" "T"))
  14.      (if (setq #cr (getreal (strcat "\nEnter Thickness: <" (rtos (- #ra2 #ra1)) "> ")))
  15.       (setq #ra2 (+ #ra1 #cr))
  16.      )
  17.      (if #cr (setq #ra2 #cr) )
  18.     )
  19.     (setq #cr (getdist @pto (strcat "\nEnter length: <" (rtos #len) "> ")))
  20.     (if #cr (setq #len #cr) )
  21.     (setq os (getvar "osmode")) (setvar "osmode" 0)
  22.     (setq @p1 (polar @pto 0 (/ #ra1 2.0)))
  23.     (setq @p2 (polar (polar @pto 0 (/ #ra2 2.0)) (* pi 1.5) #len))
  24.     (command "_.Rectang" @p1 @p2 "_.Revolve" "_l" "" @pto (polar @pto (/ pi 2) 1) 360)
  25.         (if @pt2
  26.          (command "_.Rotate3d" "_l" "" "_Z" @pto "_r" @pto (polar @pto (/ pi 2) -1) @pto @pt2 )
  27.          (command "_.Rotate3d" "_l" "" "_X" @pto 90)
  28.         )
  29.         (command "_undo" "_e")
  30.     (setvar "osmode" os)
  31.     (setvar "cmdecho" cm)
  32.     (princ)
  33.    )
  34.   )
  35. )
  36.  
Title: Re: Draw a tube ,need help.
Post by: ribarm on June 30, 2015, 03:49:57 AM
I would use path option of extrude like Tim suggested...

Code - Auto/Visual Lisp: [Select]
  1. (setq pt (getpoint "\n Specify base point: "))
  2. (setq pt2 (getpoint pt "\nSpecify the direction: "))
  3. (setq rad (getdist "\n Enter inner diameter: "))
  4. (setq otr (getdist "\n Enter Outer diameter: "))
  5. (setq len (getdist "\n Enter length: "))
  6. (setq vec (mapcar (function -) pt2 pt))
  7.     (list
  8.         '(0 . "LINE")
  9.         (cons 10 (trans pt 1 0))
  10.         (cons 11 (trans (mapcar '+ pt (mapcar '* (mapcar '/ vec (list (distance pt pt2) (distance pt pt2) (distance pt pt2))) (list len len len))) 1 0))
  11.     )
  12. )
  13. (setq path (entlast))
  14.     (list
  15.         '(0 . "CIRCLE")
  16.         '(100 . "AcDbEntity")
  17.         '(100 . "AcDbCircle")
  18.         (cons 10 (trans pt 1 vec))
  19.         (cons 40 (* rad 0.5))
  20.         (cons 210 vec)
  21.     )
  22. )
  23. (setq ent1 (entlast))
  24. (command "_region" ent1 "")
  25. (setq ss1 (entlast))
  26.     (list
  27.         '(0 . "CIRCLE")
  28.         '(100 . "AcDbEntity")
  29.         '(100 . "AcDbCircle")
  30.         (cons 10 (trans pt 1 vec))
  31.         (cons 40 (* otr 0.5))
  32.         (cons 210 vec)
  33.     )
  34. )
  35. (setq ent2 (entlast))
  36. (command "_region" ent2 "")
  37. (setq ss2 (entlast))
  38. (command "_subtract" ss2 "" ss1 "")
  39. (command "_extrude" (entlast) "" "_P" path)
  40. (entdel path)
  41.  
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 04:00:48 AM
.. 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:


Hi NICK.

I see your modification :press <Enter> to draw a tube along the Z axis

So, problem like  #9  ,  Z axis have tow direction , up or down ?
Title: Re: Draw a tube ,need help.
Post by: NICK_VNV on June 30, 2015, 05:15:14 AM
Hi, if you still want to use your old code you can simply specify positive/negative length to change Z direction up/down and replace
Code: [Select]
(command "_.Rotate3d" "_l" "" "_X" @pto 90)
with
Code: [Select]

(command "_.Rotate3d" "_l" "" "_X" @pto 270)
for draw tube like "positive=up", "negative=down".
Title: Re: Draw a tube ,need help.
Post by: CAB on June 30, 2015, 07:30:43 AM
AIberto,
Welcome to the Swamp.

Would this task be a homework assignment?

Thanks

Alan
Title: Re: Draw a tube ,need help.
Post by: T.Willey on June 30, 2015, 10:07:11 AM
<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)
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 11:14:10 AM
I would use path option of extrude like Tim suggested...


Hi marko , Thanks you for you help. It's nice .
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 11:19:50 AM
AIberto,
Welcome to the Swamp.

Would this task be a homework assignment?

Thanks

Alan

Dear Alan
pleasure to meet you. Not a homework , This is a practice.
Thanks

Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 11:22:56 AM
<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)


Thanks Tim
Marko has helped me . now It's ok !
Code - Auto/Visual Lisp: [Select]
  1. ; http://www.theswamp.org/index.php?topic=49677.0
  2. (defun c:tube(/ )
  3.    (if (setq pt (getpoint "\n Specify base point: "))
  4.         (progn
  5.         (setq pt2 (getpoint pt "\nSpecify the directio: "))
  6.         (if (null #ra1) (setq #ra1 5.0))
  7.         (if (null #ra2) (setq #ra2 8.0))
  8.         (if (null #len) (setq #len 20.0))
  9.         (setq rad (getdist(strcat "\nEnter inner diameter: <" (rtos #ra1) "> ")))
  10.         (if (= rad nil)(setq rad #ra1))
  11.         (setq #ra1 rad)
  12.         (initget "T")
  13.         (setq otr (getdist (strcat "\nEnter Outer diameter OR [Thickness (T)]: <" (rtos #ra2) "> ")))
  14.         (if (member otr (list "t" "T"))
  15.         (if (setq tck (getreal (strcat "\nEnter Thickness: <" (rtos (- #ra2 #ra1)) "> ")))
  16.         (setq otr (+ rad tck))(setq otr (+ rad (- #ra2 #ra1))))
  17.         (if(= otr nil)(setq otr #ra2 )))
  18.         (setq #ra2 otr)
  19.         (setq len (getdist(strcat "\nEnter length: <" (rtos #len) "> ")))
  20.         (if(= len nil)(setq len #len))
  21.         (setq #len len)
  22.         (setq vec (mapcar (function -) pt2 pt))
  23.         (entmake
  24.                 (list
  25.                         '(0 . "LINE")
  26.                         (cons 10 (trans pt 1 0))
  27.                         (cons 11 (mapcar '+ (trans pt 1 0) (mapcar '* (mapcar '/ vec (list (distance pt pt2) (distance pt pt2) (distance pt pt2))) (list len len len))))
  28.                 )
  29.         )
  30.         (setq path (entlast))
  31.         (entmake
  32.                 (list
  33.                         '(0 . "CIRCLE")
  34.                         '(100 . "AcDbEntity")
  35.                         '(100 . "AcDbCircle")
  36.                         (cons 10 (trans pt 1 vec))
  37.                         (cons 40 (* rad 0.5))
  38.                         (cons 210 vec)
  39.                 )
  40.         )
  41.         (setq ent1 (entlast))
  42.         (command "_region" ent1 "")
  43.         (setq ss1 (entlast))
  44.         (entmake
  45.                 (list
  46.                         '(0 . "CIRCLE")
  47.                         '(100 . "AcDbEntity")
  48.                         '(100 . "AcDbCircle")
  49.                         (cons 10 (trans pt 1 vec))
  50.                         (cons 40 (* otr 0.5))
  51.                         (cons 210 vec)
  52.                 )
  53.         )
  54.         (setq ent2 (entlast))
  55.         (command "_region" ent2 "")
  56.         (setq ss2 (entlast))
  57.         (command "_subtract" ss2 "" ss1 "")
  58.         (command "_extrude" (entlast) "" "_P" path)
  59.         (entdel path)
  60.         )
  61.         )
  62.   (princ)
  63. )
  64.  
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 12:37:04 PM
Hi, if you still want to use your old code you can simply specify positive/negative length to change Z direction up/down and replace
Code: [Select]
(command "_.Rotate3d" "_l" "" "_X" @pto 90)
with
Code: [Select]

(command "_.Rotate3d" "_l" "" "_X" @pto 270)
for draw tube like "positive=up", "negative=down".

Thanks Nick,
I think this is not best.  specified the direction already , so no need options
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 12:47:02 PM
The code at  #19, a little defect.

The  value of Outer diameter must  Greater than(> ) inner diameter

Code - Auto/Visual Lisp: [Select]
  1. (setq tf t)
  2. (while tf
  3.   (initget "T")
  4.   (setq otr (getdist (strcat "\nEnter Outer diameter OR [Thickness (T)]: <" (rtos #ra2) "> ")))
  5.   (if (member otr (list "t" "T"))
  6.     (progn (if (setq tck (getreal (strcat "\nEnter Thickness: <" (rtos (- #ra2 #ra1)) "> ")))
  7.              (setq otr (+ rad tck))
  8.              (setq otr (+ rad (- #ra2 #ra1)))
  9.            )
  10.            (setq tf nil)
  11.     )
  12.     (progn
  13.       (if (= otr nil)
  14.         (setq otr #ra2)
  15.       )
  16.       (if (<= #ra2 #ra1)
  17.         (princ "\nID Greater than OD,Please Enter again!")
  18.         (setq tf nil)
  19.       )
  20.     )
  21.   )
  22. )
  23.  
Title: Re: Draw a tube ,need help.
Post by: ribarm on June 30, 2015, 01:27:27 PM
Alberto, I've modified my code :

this :
Code - Auto/Visual Lisp: [Select]
  1. (cons 11 (mapcar '+ (trans pt 1 0) (mapcar '* (mapcar '/ vec (list (distance pt pt2) (distance pt pt2) (distance pt pt2))) (list len len len))))
  2.  

should be :
Code - Auto/Visual Lisp: [Select]
  1. (cons 11 (trans (mapcar '+ pt (mapcar '* (mapcar '/ vec (list (distance pt pt2) (distance pt pt2) (distance pt pt2))) (list len len len))) 1 0))
  2.  
Title: Re: Draw a tube ,need help.
Post by: AIberto on June 30, 2015, 08:52:56 PM
Alberto, I've modified my code :

this :
Code - Auto/Visual Lisp: [Select]
  1. (cons 11 (mapcar '+ (trans pt 1 0) (mapcar '* (mapcar '/ vec (list (distance pt pt2) (distance pt pt2) (distance pt pt2))) (list len len len))))
  2.  

should be :
Code - Auto/Visual Lisp: [Select]
  1. (cons 11 (trans (mapcar '+ pt (mapcar '* (mapcar '/ vec (list (distance pt pt2) (distance pt pt2) (distance pt pt2))) (list len len len))) 1 0))
  2.  

Hi marko .Thank you ! gooooood!