Author Topic: Draw a tube ,need help.  (Read 7038 times)

0 Members and 1 Guest are viewing this topic.

AIberto

  • Guest
Draw a tube ,need help.
« 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.  

ChrisCarlson

  • Guest
Re: Draw a tube ,need help.
« Reply #1 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

NICK_VNV

  • Newt
  • Posts: 63
Re: Draw a tube ,need help.
« Reply #2 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)
   )
  )
)
Sorry for my English...

AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #3 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 ?




ChrisCarlson

  • Guest
Re: Draw a tube ,need help.
« Reply #4 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: "))

AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #5 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:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Draw a tube ,need help.
« Reply #6 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.  
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #7 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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Draw a tube ,need help.
« Reply #8 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #9 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


AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #10 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.  

NICK_VNV

  • Newt
  • Posts: 63
Re: Draw a tube ,need help.
« Reply #11 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.  
Sorry for my English...

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Re: Draw a tube ,need help.
« Reply #12 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.  
« Last Edit: June 30, 2015, 04:03:17 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #13 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 ?

NICK_VNV

  • Newt
  • Posts: 63
Re: Draw a tube ,need help.
« Reply #14 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".
Sorry for my English...