<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need a Lisp for Civil3d Pipes in Civil 3D Customization Forum</title>
    <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862721#M1663</link>
    <description>&lt;P&gt;Can you explain in a little more detail what you want the lisp to do? I can see why you'd want one invert to match the surface, but both?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jun 2024 15:24:52 GMT</pubDate>
    <dc:creator>hippe013</dc:creator>
    <dc:date>2024-06-26T15:24:52Z</dc:date>
    <item>
      <title>Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12861943#M1662</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;Can someone make a lisp for Civil3d pipes, which can move invert levels of multiple selected pipes to surface level.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 09:15:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12861943#M1662</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-06-26T09:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862721#M1663</link>
      <description>&lt;P&gt;Can you explain in a little more detail what you want the lisp to do? I can see why you'd want one invert to match the surface, but both?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 15:24:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862721#M1663</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-06-26T15:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862784#M1664</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;I was actually asked recently (not by the OP here) to add a tool to do this to the Sincpac. It is for subdrains added to a grading plan.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 15:49:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862784#M1664</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-06-26T15:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862841#M1665</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637"&gt;@Jeff_M&lt;/a&gt;&amp;nbsp;I'll bet that you get all sorts of requests to add to your software. Some ideas may be good, while others might make one wonder, "Why?"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have code for pipes in my repository; however, it appears that working with pipes via Lisp, particularly structures, can be quite prone to bugs. It is rather easy to adjust a pipe to a surface, but then to adjust the structures to follow is where the bugs come in. At least in my experience.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I should at-least be able to provide some example code, but making a Lisp command bullet-proof gets to be a bit of work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 16:15:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862841#M1665</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-06-26T16:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862850#M1666</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637"&gt;@Jeff_M&lt;/a&gt;&amp;nbsp;I'll bet that you get all sorts of requests to add to your software. Some ideas may be good, while others might make one wonder, "Why?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You got that right!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I gave up using lisp to work with pipes long ago, .NET is so much easier...&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 16:20:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862850#M1666</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-06-26T16:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862915#M1667</link>
      <description>&lt;P&gt;The code below is a quick example of setting pipe inverts to a Tin Surface. Note that this does not update the structures. It also prompts the user to select each pipe individually. Though this can be easily modified to&amp;nbsp;satisfy&amp;nbsp;&amp;nbsp; individual needs. Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun c:PipeToSurface ( / surfSS surf pipeSS pipe success)
  (princ "\nSelect Surface: ")
  (setq surfSS (ssget ":s+." '(( 0 . "AECC_TIN_SURFACE"))))
  (if surfSS
    (progn
      (setq surf (vlax-ename-&amp;gt;vla-object (ssname surfSS 0)))
      (while (setq pipeSS (ssget ":s+." '(( 0 . "AECC_PIPE"))))
	(setq pipe (vlax-ename-&amp;gt;vla-object (ssname pipeSS 0)))
	(setq success (SetPipeInvertsToSurface pipe surf 0.00))
	(if success
	  (princ "\nPipe Inverts have been set to surface.")
	  (princ "\nPipe does not fully lay on surface.")
	  )
	)
      )
    )
  (princ)
  )


    
  


;SetPipeInvertsToSurface - Sets Pipes Start &amp;amp; End Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeInvertsToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeInvertsToSurface (pipe surf vertOffset / p0 p1 halfdia args0 args1 elev0 elev1 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  (setq halfDia (/ (vlax-get-property pipe 'InnerDiameterOrWidth) 2.0))
  
  ;Try and get the Surface Elevation at the StartPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Try and get the Surface Elevation at the EndPoint
  (setq args1 (list surf 'FindElevationAtXY (car p1) (cadr p1)))
  (setq elev1 (vl-catch-all-apply 'vlax-invoke-method args1))

  ;Proceed only if both ends lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)) (not(vl-catch-all-error-p elev1)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (+ elev0 halfdia vertOffset)))
      (setq np1 (list (car p1) (cadr p1) (+ elev1 halfdia vertOffset)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 16:47:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12862915#M1667</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-06-26T16:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12863938#M1668</link>
      <description>&lt;P&gt;I want to add pipes (utilities) to show them in the sections and profile and move them down (z axis) to provided depth so that we can show labels of elevation and top of pipe. I just need middle of pipe to match surface elevation.&lt;BR /&gt;hope you understand.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 05:28:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12863938#M1668</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-06-27T05:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12863960#M1669</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;The code below is a quick example of setting pipe inverts to a Tin Surface. Note that this does not update the structures. It also prompts the user to select each pipe individually. Though this can be easily modified to&amp;nbsp;satisfy&amp;nbsp;&amp;nbsp; individual needs. Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun c:PipeToSurface ( / surfSS surf pipeSS pipe success)
  (princ "\nSelect Surface: ")
  (setq surfSS (ssget ":s+." '(( 0 . "AECC_TIN_SURFACE"))))
  (if surfSS
    (progn
      (setq surf (vlax-ename-&amp;gt;vla-object (ssname surfSS 0)))
      (while (setq pipeSS (ssget ":s+." '(( 0 . "AECC_PIPE"))))
	(setq pipe (vlax-ename-&amp;gt;vla-object (ssname pipeSS 0)))
	(setq success (SetPipeInvertsToSurface pipe surf 0.00))
	(if success
	  (princ "\nPipe Inverts have been set to surface.")
	  (princ "\nPipe does not fully lay on surface.")
	  )
	)
      )
    )
  (princ)
  )


    
  


;SetPipeInvertsToSurface - Sets Pipes Start &amp;amp; End Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeInvertsToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeInvertsToSurface (pipe surf vertOffset / p0 p1 halfdia args0 args1 elev0 elev1 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  (setq halfDia (/ (vlax-get-property pipe 'InnerDiameterOrWidth) 2.0))
  
  ;Try and get the Surface Elevation at the StartPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Try and get the Surface Elevation at the EndPoint
  (setq args1 (list surf 'FindElevationAtXY (car p1) (cadr p1)))
  (setq elev1 (vl-catch-all-apply 'vlax-invoke-method args1))

  ;Proceed only if both ends lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)) (not(vl-catch-all-error-p elev1)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (+ elev0 halfdia vertOffset)))
      (setq np1 (list (car p1) (cadr p1) (+ elev1 halfdia vertOffset)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Thank you for your Lisp. This is a nice lisp to match both invert levels to surface levels.&lt;/P&gt;&lt;P&gt;Could you please make it to match only middle of pipe to surface level and if it can match top of pipe to surface level it will be more useful.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 05:43:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12863960#M1669</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-06-27T05:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12867178#M1670</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14578040"&gt;@saqib_tipa&lt;/a&gt;&amp;nbsp;I certainly can, however if you look at the code the changes required are rather non-trivial.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below I have added two additional subroutines. They work in the same fashion as the one I post above.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One to match the center of pipe to surface and the other to match the top, outside of pipe to the surface.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;;SetPipeCenterToSurface - Sets Pipes Start &amp;amp; End Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeCenterToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeCenterToSurface (pipe surf vertOffset / p0 p1 halfdia args0 args1 elev0 elev1 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  
  ;Try and get the Surface Elevation at the StartPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Try and get the Surface Elevation at the EndPoint
  (setq args1 (list surf 'FindElevationAtXY (car p1) (cadr p1)))
  (setq elev1 (vl-catch-all-apply 'vlax-invoke-method args1))

  ;Proceed only if both ends lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)) (not(vl-catch-all-error-p elev1)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (+ elev0 vertOffset)))
      (setq np1 (list (car p1) (cadr p1) (+ elev1 vertOffset)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )


;SetPipeTopToSurface - Sets Pipes Start &amp;amp; End Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeTopToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeTopToSurface (pipe surf vertOffset / p0 p1 halfdia args0 args1 elev0 elev1 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  (setq halfDia (/ (vlax-get-property pipe 'OuterDiameterOrWidth) 2.0))
  
  ;Try and get the Surface Elevation at the StartPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Try and get the Surface Elevation at the EndPoint
  (setq args1 (list surf 'FindElevationAtXY (car p1) (cadr p1)))
  (setq elev1 (vl-catch-all-apply 'vlax-invoke-method args1))

  ;Proceed only if both ends lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)) (not(vl-catch-all-error-p elev1)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (- (+ elev0 vertOffset) halfdia)))
      (setq np1 (list (car p1) (cadr p1) (- (+ elev1 vertOffset) halfdia)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you able to modify the PipeToSurface command (see my original post) to use one of the subroutines that I post here?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 14:18:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12867178#M1670</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-06-28T14:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12868532#M1671</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14578040"&gt;@saqib_tipa&lt;/a&gt;&amp;nbsp;I certainly can, however if you look at the code the changes required are rather non-trivial.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below I have added two additional subroutines. They work in the same fashion as the one I post above.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One to match the center of pipe to surface and the other to match the top, outside of pipe to the surface.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;;SetPipeCenterToSurface - Sets Pipes Start &amp;amp; End Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeCenterToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeCenterToSurface (pipe surf vertOffset / p0 p1 halfdia args0 args1 elev0 elev1 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  
  ;Try and get the Surface Elevation at the StartPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Try and get the Surface Elevation at the EndPoint
  (setq args1 (list surf 'FindElevationAtXY (car p1) (cadr p1)))
  (setq elev1 (vl-catch-all-apply 'vlax-invoke-method args1))

  ;Proceed only if both ends lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)) (not(vl-catch-all-error-p elev1)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (+ elev0 vertOffset)))
      (setq np1 (list (car p1) (cadr p1) (+ elev1 vertOffset)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )


;SetPipeTopToSurface - Sets Pipes Start &amp;amp; End Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeTopToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeTopToSurface (pipe surf vertOffset / p0 p1 halfdia args0 args1 elev0 elev1 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  (setq halfDia (/ (vlax-get-property pipe 'OuterDiameterOrWidth) 2.0))
  
  ;Try and get the Surface Elevation at the StartPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Try and get the Surface Elevation at the EndPoint
  (setq args1 (list surf 'FindElevationAtXY (car p1) (cadr p1)))
  (setq elev1 (vl-catch-all-apply 'vlax-invoke-method args1))

  ;Proceed only if both ends lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)) (not(vl-catch-all-error-p elev1)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (- (+ elev0 vertOffset) halfdia)))
      (setq np1 (list (car p1) (cadr p1) (- (+ elev1 vertOffset) halfdia)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you able to modify the PipeToSurface command (see my original post) to use one of the subroutines that I post here?&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your help again.&amp;nbsp; I tried to combine 2nd subroutine and got the result. It works nicely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a little request that rather than picking surface levels from both ends of pipe it should pick surface elevation exactly from mid of pipe and adjust pipe middle level accordingly.&lt;/P&gt;&lt;P&gt;Hope you understand.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 08:58:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12868532#M1671</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-06-29T08:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12871886#M1672</link>
      <description>&lt;P&gt;I think that this latest request you should be able to complete. Feel free to ask if you have any questions. Also, feel free to mark of one the posts as a solution to your original question. The example code that I have provided should provide give you enough information as to how to complete your latest request. You might have questions about computing the midpoint between two points and I can help you with that. However, I am not here to fill people's code requests. I prefer that they learn to write to the code themselves. Let me know what questions you might have.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards &amp;amp; Happy Coding!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 16:09:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12871886#M1672</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-07-01T16:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12871954#M1673</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for the reply. You are right we should learn to write the code. I have tried to learn its kind of hard to learn till now and I really appreciate you and all other who try to help and try to teach.&lt;/P&gt;&lt;P&gt;Please see my 7th post I was already requesting this before I just missed to tag you when I was requesting about center of pipe. Its not all new request and please I will be happy if you can manage it to work with middle of pipe and match top of the pipe to the surface we select.&lt;/P&gt;&lt;P&gt;Hope you can understand and yes I will surely mark them all as 'accept' it is always in my mind.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 16:43:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12871954#M1673</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-07-01T16:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12871981#M1674</link>
      <description>&lt;P&gt;In the example code that I have provided, we get and store the start and end points as P0 &amp;amp; P1. You want to get the middle point in between those two points. We need to get the angle in the XY plane between those two points. We also need to get the distance between those two points so that we can cut that distance in half. We then use the Polar function to compute the mid-point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;;Lets create a copy of the two points as 2D points.
(setq p02d (list (car p0) (cadr p0) 0))
(setq p12d (list (car p1) (cadr p1) 0))

;Get the Angle between the two points
(setq ang (angle p02d p12d))

;Get the 2D Distance and cut the distance in half
(setq dist (/ (distance p02d p12d) 2.0))

;Compute the Mid-Point
(setq midPnt (polar p02d ang dist))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that you have the mid-point, you can use the code above to try and extract the surface elevation at that point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 16:57:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12871981#M1674</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-07-01T16:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12872063#M1675</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the reply. I will try to combine these codes to make it work as we need. I am not sure if I will manage it to compile. I understood that we just got that mid point where we want to extract elevation but don't understand completely where and what else should we change in previous provided code because of my limited knowledge of coding. But I will try and let you know by tomorrow. If I am unable to compile this code then will need your further assistance.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 17:36:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12872063#M1675</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-07-01T17:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12872086#M1676</link>
      <description>&lt;P&gt;Sounds good! I look forward to seeing what you come up with.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 17:43:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12872086#M1676</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-07-01T17:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12873312#M1677</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;In the example code that I have provided, we get and store the start and end points as P0 &amp;amp; P1. You want to get the middle point in between those two points. We need to get the angle in the XY plane between those two points. We also need to get the distance between those two points so that we can cut that distance in half. We then use the Polar function to compute the mid-point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;;Lets create a copy of the two points as 2D points.
(setq p02d (list (car p0) (cadr p0) 0))
(setq p12d (list (car p1) (cadr p1) 0))

;Get the Angle between the two points
(setq ang (angle p02d p12d))

;Get the 2D Distance and cut the distance in half
(setq dist (/ (distance p02d p12d) 2.0))

;Compute the Mid-Point
(setq midPnt (polar p02d ang dist))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that you have the mid-point, you can use the code above to try and extract the surface elevation at that point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I tried for a long time to combine the codes but unfortunately could not make a final working Lisp, as I am not much knowledge of what code should go before or after or what needs to be changed because of new code. I know it's messed up. I tried to change few things but could not manage it. Please combine those codes so that it can work correctly.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun c:PipeToSurface ( / surfSS surf pipeSS pipe success)
  (princ "\nSelect Surface: ")
  (setq surfSS (ssget ":s+." '(( 0 . "AECC_TIN_SURFACE"))))
  (if surfSS
    (progn
      (setq surf (vlax-ename-&amp;gt;vla-object (ssname surfSS 0)))
      (while (setq pipeSS (ssget ":s+." '(( 0 . "AECC_PIPE"))))
	(setq pipe (vlax-ename-&amp;gt;vla-object (ssname pipeSS 0)))
	(setq success (SetPipeTopToSurface pipe surf 0.000))
	(if success
	  (princ "\nPipe Inverts have been set to surface.")
	  (princ "\nPipe Mid not lay on surface.")
	  )
	)
      )
    )
  (princ)
  )


    
  


;SetPipeTopToSurface - Sets Pipes Mid Top Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeTopToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeTopToSurface (pipe surf vertOffset / p0 p1 p02d p12d halfdia args0 elev0 output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1(vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  (setq halfDia (/ (vlax-get-property pipe 'OuterDiameterOrWidth) 2.0))
   ;--------------------------------
  ;Try and get the Surface Elevation at MidPoint
  (setq args0 (list surf 'FindElevationAtXY (car p0) (cadr p0)))
  (setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

;Lets create a copy of the two points as 2D points.
(setq p02d (list (car p0) (cadr p0) 0))
(setq p12d (list (car p1) (cadr p1) 0))

;Get the Angle between the two points
(setq ang (angle p02d p12d))

;Get the 2D Distance and cut the distance in half
(setq dist (/ (distance p02d p12d) 2.0))

;Compute the Mid-Point
(setq midPnt (polar p02d ang dist))

 ;--------------------------------
  ;Proceed only if Mid of pipe lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)))
    (progn
      (setq nmidPnt (list (car midPnt) (cadr midPnt) (- (+ elev0 vertOffset) halfdia)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point nmidPnt))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 09:31:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12873312#M1677</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-07-02T09:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12874385#M1678</link>
      <description>&lt;P&gt;It looks like you are trying to get the elevation from the surface from the end points and then computing the midpoint. You will need to compute this mid-point first and then place that into the arguments for the surface elevation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;;Lets create a copy of the two points as 2D points.
(setq p02d (list (car p0) (cadr p0) 0))
(setq p12d (list (car p1) (cadr p1) 0))

;Get the Angle between the two points
(setq ang (angle p02d p12d))

;Get the 2D Distance and cut the distance in half
(setq dist (/ (distance p02d p12d) 2.0))

;Compute the Mid-Point
(setq midPnt (polar p02d ang dist))

;Try and get the Surface Elevation at MidPoint
(setq args0 (list surf 'FindElevationAtXY (car midPnt) (cadr midPnt)))
(setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that this helps clarify things for you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 18:01:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12874385#M1678</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-07-02T18:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12876884#M1679</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;It looks like you are trying to get the elevation from the surface from the end points and then computing the midpoint. You will need to compute this mid-point first and then place that into the arguments for the surface elevation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;;Lets create a copy of the two points as 2D points.
(setq p02d (list (car p0) (cadr p0) 0))
(setq p12d (list (car p1) (cadr p1) 0))

;Get the Angle between the two points
(setq ang (angle p02d p12d))

;Get the 2D Distance and cut the distance in half
(setq dist (/ (distance p02d p12d) 2.0))

;Compute the Mid-Point
(setq midPnt (polar p02d ang dist))

;Try and get the Surface Elevation at MidPoint
(setq args0 (list surf 'FindElevationAtXY (car midPnt) (cadr midPnt)))
(setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that this helps clarify things for you.&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Hello &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for the reply, when I saw your reply and you just posted the partial code I thought it will now take months to finalize my requested code because of me not having enough knowledge of these codes. I tried again for a long time to compile it and see what mistakes are there in my last compiled code. I saw I have changed and removed last part where we have to give start and end invert levels which we have taken from surface at pipe middle point. Before I thought that we have to give that level at pipe middle only but then realized there is no such thing pipe middle level in civil3d. Then I tried few more changing and at last I got the code I was looking for.&lt;/P&gt;&lt;P&gt;Thanks to you for your codes and helping me to understand these things.&amp;nbsp; It will save my time from manually inputting levels of pipes.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;But please remember I really don't know that much of these codes if I have to built this kind of code from scratch I really can't because I don't know how to start what coding,&amp;nbsp;arguments and commands are needed to built that code.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Thank you so much again for your time and help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 18:51:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12876884#M1679</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-07-03T18:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12877002#M1680</link>
      <description>&lt;P&gt;Excellent! I am happy that you were able to figure out what changes that you needed to make.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Learning how to code in LISP, or any other programming language, can be challenging and time consuming. However, it can be very rewarding once you do learn, as you can then automate these tedious tasks. There are many people on these forums that are more than willing to help with any questions that you may have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you be willing to post your final code for others to see?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 19:43:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12877002#M1680</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2024-07-03T19:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need a Lisp for Civil3d Pipes</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12877740#M1681</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394"&gt;@hippe013&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you, I wish I could learn coding and make Lisps for me and others, but I am still in learning phase and for some people it is difficult to learn this Lisp language fast and I am one from them. But always try to learn. You are right it is very useful in daily working tasks to make them automate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really respect and &lt;SPAN&gt;appreciate&lt;/SPAN&gt; those people wo always try to help others.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, why not it's all your code and I just compiled it.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun c:PipeToSurface ( / surfSS surf pipeSS pipe success)
  (princ "\nSelect Surface: ")
  (setq surfSS (ssget ":s+." '(( 0 . "AECC_TIN_SURFACE"))))
  (if surfSS
    (progn
      (setq surf (vlax-ename-&amp;gt;vla-object (ssname surfSS 0)))
      (while (setq pipeSS (ssget ":s+." '(( 0 . "AECC_PIPE"))))
	(setq pipe (vlax-ename-&amp;gt;vla-object (ssname pipeSS 0)))
	(setq success (SetPipeTopToSurface pipe surf 0.000))
	(if success
	  (princ "\nPipe Inverts have been set to surface.")
	  (princ "\nPipe Mid not lay on surface.")
	  )
	)
      )
    )
  (princ)
  )


;SetPipeTopToSurface - Sets Pipes Mid Top Points onto a surface with a given vertical offset.
;Returns (T) if both points lay on the Surface                                              
;Returns (nil) if one or both of the end points do not lay on a surface.                    
;Example: (setq success (SetPipeTopToSurface pipeObject surfaceObject 0.00))            
(defun SetPipeTopToSurface (pipe surf vertOffset / p0 p1 p02d p12d halfdia args0 elev0 midPnt output)
  (setq p0 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 0))))
  (setq p1 (vlax-safearray-&amp;gt;list (vlax-variant-value (vlax-get-property pipe 'PointAtParam 1))))
  (setq halfDia (/ (vlax-get-property pipe 'OuterDiameterOrWidth) 2.0))
;Lets create a copy of the two points as 2D points.
(setq p02d (list (car p0) (cadr p0) 0))
(setq p12d (list (car p1) (cadr p1) 0))

;Get the Angle between the two points
(setq ang (angle p02d p12d))

;Get the 2D Distance and cut the distance in half
(setq dist (/ (distance p02d p12d) 2.0))

;Compute the Mid-Point
(setq midPnt (polar p02d ang dist))

;Try and get the Surface Elevation at MidPoint
(setq args0 (list surf 'FindElevationAtXY (car midPnt) (cadr midPnt)))
(setq elev0 (vl-catch-all-apply 'vlax-invoke-method args0))

  ;Proceed only if Mid of pipe lay on a surface
  (if (and (not(vl-catch-all-error-p elev0)))
    (progn
      (setq np0 (list (car p0) (cadr p0) (- (+ elev0 vertOffset) halfdia)))
      (setq np1 (list (car p1) (cadr p1) (- (+ elev0 vertOffset) halfdia)))
      (vlax-invoke-method pipe 'SetStartAndEndPoints (vlax-3d-point np0) (vlax-3d-point np1))
      (setq output T)
      )
    (setq output nil)
    )
  output
  )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;EM&gt;(This is working for me, but if there any errors you may point them)&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 05:45:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/need-a-lisp-for-civil3d-pipes/m-p/12877740#M1681</guid>
      <dc:creator>saqib_tipa</dc:creator>
      <dc:date>2024-07-04T05:45:05Z</dc:date>
    </item>
  </channel>
</rss>

