AutoLISP: Define a Pipe’s Path by 3D Curved Objects

Today’s featured routine is a gem if you need to make basic 3D Pipes. It does a couple of awesome thing: 1) It creates a pipe with an inner and outer diameter thus creating a true pipe. 2) Lets you specify the path of the pipe by selecting simple and complex objects such as polylines with arc segments, 3D polylines, arcs, circles, ellipses…3) Creates the pipe/tube as a 3D solid objects which will allow you to use the union and subtract commands if needed.

Here’s how:

  • CURVE2TUBE <enter> to start
  • Specify outer radius <enter>
  • Specify inner radius <enter>
  • Select object to define the path of the pipe

;;; CURVE2TUBE -Gilles Chanteau- (gile)
;;; Extrudes a "donut region" along a curve(s) object(s).
(defun c:curve2tube	(/	   AcDoc     Space     ext_rad
			 int_rad   ss	     obj       start
			 ext_circ  int_circ  ext_reg   int_reg


  (defun vlen (v)
    (sqrt (vxv v v))

  (defun vxv (v1 v2)
    (apply '+ (mapcar '* v1 v2))

  (defun vunit (v / l)
    (if	(/= 0 (setq l (vlen v)))
      (mapcar '(lambda (x) (/ x l)) v)

  (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq	Space
	 (if (= 1 (getvar "CVPORT"))
	   (vla-get-PaperSpace AcDoc)
	   (vla-get-ModelSpace AcDoc)
      (setq ext_rad (getdist "\nExternal radius: "))
      (setq int_rad (getdist "\nInternal radius: "))
      (setq ss
	       '((-4 . "<OR")
		 (-4 . "<AND")
		 (0 . "POLYLINE")
		 (-4 . "<NOT")
		 (-4 . "&")
		 (70 . 112)
		 (-4 . "NOT>")
		 (-4 . "AND>")
		 (-4 . "<AND")
		 (0 . "SPLINE")
		 (-4 . "&")
		 (70 . 8)
		 (-4 . "AND>")
		 (-4 . "OR>")
       (vla-StartUndoMark AcDoc)
       (foreach	path (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	 (setq obj (vlax-ename->vla-object path))
	 (setq start (vlax-curve-getPointAtParam
		       (vlax-curve-getStartParam obj)
	 (setq ext_circ (vla-addCircle Space (vlax-3d-Point start) ext_rad))
	 (setq int_circ (vla-addCircle Space (vlax-3d-Point start) int_rad))
	 (setq norm (vunit (vlax-curve-getFirstDeriv
			     (vlax-curve-getStartParam obj)
	 (vla-put-Normal ext_circ (vlax-3d-point norm))
	 (vla-put-Normal int_circ (vlax-3d-point norm))
	 (setq ext_reg (car (vlax-invoke Space 'addRegion (list ext_circ))))
	 (setq int_reg (car (vlax-invoke Space 'addRegion (list int_circ))))
	 (vla-Boolean ext_reg acSubtraction int_reg)
	 (vla-addExtrudedSolidAlongPath Space ext_reg obj)
	 (mapcar 'vla-delete (list obj ext_circ int_circ ext_reg))
       (vla-EndUndoMark AcDoc)

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: 3D, AutoLISP: Creating, AutoLISP: Modify, AutoLISP: Polylines. Bookmark the permalink.

2 Responses to AutoLISP: Define a Pipe’s Path by 3D Curved Objects

  1. putra says:

    dear admin thanks for your lisp file.
    actually i want to ask, how to make 3d pipe with lisp?for example i want to make pipe named A with Outside Diameter:100mm, Inside Diameter:8mm, height:20mm.
    many thanks and sorry for newbie question

    • AutoCAD Tips says:

      This lisp should work for you. I think that you might need to set the units for the drawing. You can do this by entering UNITS at the command line. And since you mentioned “mm” Millimeters, under the area that says “Insertion scale” change that to be Millimeters.
      Another tip to get this set up is to use the command MVSETUP while in model space as shown in the following link. The only difference is that instead of entering “A” for architectural units, you will enter “M” for Metric.

      hope this helps

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s