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

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Draw a tube ,need help.
« Reply #15 on: June 30, 2015, 07:30:43 AM »
AIberto,
Welcome to the Swamp.

Would this task be a homework assignment?

Thanks

Alan
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

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

AIberto

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


AIberto

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

AIberto

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

AIberto

  • Guest
Re: Draw a tube ,need help.
« Reply #21 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.  
« Last Edit: June 30, 2015, 08:50:34 PM by AIberto »

ribarm

  • Gator
  • Posts: 3272
  • Marko Ribar, architect
Re: Draw a tube ,need help.
« Reply #22 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.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

AIberto

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