how to draw piping in autocad 3d

Draw A 3D Polyline Pipe Like In AutoCAD Using Excel VBA


Introduction


The previous days I worked on a hydraulic project. I had to design some pipelines in an AutoCAD 3D drawing. In the particular case, I had the pipeline coordinates and pipe sizes in an Excel workbook, and so I thought that I should write a VBA code to automate this procedure. I remembered that some months ago, I published a VBA lawmaking for drawing 2d polylines in AutoCAD using data from Excel, so I started thinking of a fashion to expand this solution into 3 dimensions.

The manual style for cartoon a 3D "solid" polyline, which looks like a round pipeline in AutoCAD, involves the SWEEP command (meet the video below), a 3D polyline representing the pipeline path, a circle the radius of which corresponds to the pipe radius. Unfortunately, VBA doesn't have a SWEEP command/method, making the procedure a little bit difficult. However, it has a like method called AddExtrudedSolidAlongPath. This method creates an extruded solid given the contour and an extrusion path. The new solid is extruded from the current location of the region using the translation of the path to the region's Centroid. From the AutoCAD VBA help, we get its structure:

RetVal = Object.AddExtrudedSolidAlongPath(Contour, Path)

Where:
RetVal: 3DSolid object – the extruded 3DSolid object.
Object: ModelSpace Collection, PaperSpace Drove, Block – the objects this method applies to.
Contour object: input-just – the Region object only.
Path object: input-just – the Polyline, Circle, Ellipse, Spline, or Arc object just.
Remarks: You can extrude just 2D planar regions. The path should not lie on the same plane as the contour, nor should it have areas of high curvature.

Although the bachelor path objects do not include the 3D polyline, we can use this object, but taking into account that both Profile and Path objects must not lie on the aforementioned plane. We can overcome this limitation with a simple trick: nosotros rotate the Profile object! So, in this item case, we rotate the circumvolve 45 degrees over the y axis for the circle plane to be unlike than the 3D polyline aeroplane(s). Moreover, we employ the Move method to movement the 3D "solid" polyline dorsum to its original position (since the AddExtrudedSolidAlongPath method will start cartoon the 3D "solid" polyline at contour'southward coordinates – usually at (0,0,0)).


VBA code to depict a 3D polyline


Here is the VBA code for drawing the 3D "solid" polyline. If the user doesn't enter a radius value (which determines the piping radius), the lawmaking volition draw just the 3D polyline.

            Option Explicit  Sub Draw3DPolyline()      '--------------------------------------------------------------------------------------------------     'Draws a 3D polyline in AutoCAD using X, Y, and Z coordinates from the sheet Coordinates.     'If the user enter a radius value the code transforms the 3D polyline to a piping-like solid, using     'the AddExtrudedSolidAlongPath method. In this way, you can draw a pipeline straight from Excel!          'The code uses late bounden, so no reference to external AutoCAD (type) library is required.     'It goes without saying that AutoCAD must be installed at your computer before running this lawmaking.          'Written By:    Christos Samaras     'Engagement:          27/11/2013     'Terminal Updated:   12/03/2014     'Email:        [e-mail protected]     'Site:          https://www.myengineeringworld.internet     '--------------------------------------------------------------------------------------------------              'Declaring the necessary variables.     Dim acadApp                 Every bit Object     Dim acadDoc                 Equally Object     Dim LastRow                 Every bit Long     Dim acad3DPol               As Object     Dim dblCoordinates()        Equally Double     Dim i                       Equally Long     Dim j                       Every bit Long     Dim g                       Equally Long     Dim objCircle(0 To 0)       Equally Object     Dim CircleCenter(0 To two)    As Double     Dim CircleRadius            As Double     Dim RotPoint1(ii)            As Double     Dim RotPoint2(2)            As Double     Dim Regions                 As Variant     Dim objSolidPol             Every bit Object     Dim FinalPosition(0 To 2)   As Double               'Activate the coordinates sail and notice the terminal row.     With Sheets("Coordinates")         .Activate         LastRow = .Cells(.Rows.Count, "A").Terminate(xlUp).Row     End With              'Check if there are at to the lowest degree two points.     If LastRow < iii Then         MsgBox "There are not enough points to depict the 3D polyline!", vbCritical, "Points Error"         Exit Sub     End If          'Bank check if AutoCAD application is open. If not, create a new instance and make it visible.     On Error Resume Side by side     Fix acadApp = GetObject(, "AutoCAD.Application")     If acadApp Is Nothing Then         Set acadApp = CreateObject("AutoCAD.Application")         acadApp.Visible = True     Cease If          'Check if there is an AutoCAD object.     If acadApp Is Cypher Then         MsgBox "Sorry, it was incommunicable to beginning AutoCAD!", vbCritical, "AutoCAD Error"         Leave Sub     End If     On Error GoTo 0          'Check if there is an active cartoon. If no agile drawing is institute, create a new one.     On Error Resume Adjacent     Set acadDoc = acadApp.ActiveDocument     If acadDoc Is Zero And so         Gear up acadDoc = acadApp.Documents.Add     Terminate If     On Fault GoTo 0              'Get the one dimensional assortment size (= iii * number of coordinates (10,y,z)).     ReDim dblCoordinates(ane To 3 * (LastRow - 1))          'Laissez passer the coordinates to the i dimensional assortment.     k = 1     For i = ii To LastRow         For j = 1 To iii             dblCoordinates(k) = Sheets("Coordinates").Cells(i, j)             k = k + 1         Side by side j     Next i          'Check if the active infinite is paper space and change information technology to model space.     If acadDoc.ActiveSpace = 0 So '0 = acPaperSpace in early bounden         acadDoc.ActiveSpace = 1 'ane = acModelSpace in early on bounden     Stop If          'Draw the 3D polyline at model space.     Set acad3DPol = acadDoc.ModelSpace.Add3DPoly(dblCoordinates)          'Leave the 3D polyline open (the final point is not connected to the first i).     'Set up the next line to True if y'all demand to close the polyline.     acad3DPol.Closed = Faux     acad3DPol.Update          'Get the circle radius.     CircleRadius = Sheets("Coordinates").Range("E1").Value          If CircleRadius > 0 Then          'Set the circumvolve center at the (0,0,0) bespeak.         CircleCenter(0) = 0: CircleCenter(1) = 0: CircleCenter(two) = 0                  'Describe the circumvolve.         Set objCircle(0) = acadDoc.ModelSpace.AddCircle(CircleCenter, CircleRadius)                  'Initialize the rotational centrality.         RotPoint1(0) = 0: RotPoint1(1) = 0: RotPoint1(2) = 0         RotPoint2(0) = 0: RotPoint2(1) = 10: RotPoint2(2) = 0                  'Rotate the circumvolve in order to avoid errors with AddExtrudedSolidAlongPath method.         objCircle(0).Rotate3D RotPoint1, RotPoint2, 0.785398163 '45 degrees          'Create a region from the circle.         Regions = acadDoc.ModelSpace.AddRegion(objCircle)              'Create the "solid polyline".         Set objSolidPol = acadDoc.ModelSpace.AddExtrudedSolidAlongPath(Regions(0), acad3DPol)                          'Set the position where the solid should be transferred after its blueprint (its original position).         With Sheets("Coordinates")             FinalPosition(0) = .Range("A2").Value             FinalPosition(1) = .Range("B2").Value             FinalPosition(two) = .Range("C2").Value         Finish With                  'Motility the solid to its final position.         objSolidPol.Move CircleCenter, FinalPosition                     'Delete the circle.         objCircle(0).Delete                  'Delete the region.         Regions(0).Delete                                'If the "solid polyline" was created successfully delete the initial polyline.         If Err.Number = 0 Then             acad3DPol.Delete         Finish If              Cease If      'Zooming in to the cartoon surface area.     acadApp.ZoomExtents          'Release the objects.     Fix objCircle(0) = Nix     Prepare objSolidPol = Nothing     Fix acad3DPol = Zero     Gear up acadDoc = Null     Prepare acadApp = Nothing          'Inform the user that the 3D polyline was created.     MsgBox "The 3D polyline was successfully created in AutoCAD!", vbInformation, "Finished"  End Sub          

The to a higher place code was successfully tested in Excel and AutoCAD 2013 (both 32bit). Still, it should piece of work in other Excel/AutoCAD versions.


Demonstration video


The curt video below demonstrates both the manual (using SWEEP command) and the automated manner (Excel VBA) to create a 3D solid polyline in AutoCAD.


Downloads


Download
The file can be opened with Excel 2007 or newer. Delight enable macros before using it.


Read also


Describe A Polyline In AutoCAD Using Excel VBA
Drawing Circles In AutoCAD Using Excel & VBA
Add together Text In AutoCAD Using Excel & VBA
Add Dimensions In AutoCAD Using Excel & VBA
Drawing Points In AutoCAD Using Excel & VBA

Folio last modified: May 16, 2021

Hi, I am Christos, a Mechanical Engineer past profession (Ph.D.) and a Software Developer by obsession (10+ years of experience)! I founded this site back in 2011 intending to provide solutions to various engineering science and programming problems.

Add together Content Block

murraynecanat.blogspot.com

Source: https://myengineeringworld.net/2013/11/draw-3d-polyline-pipe--autocad-excel-vba.html

0 Response to "how to draw piping in autocad 3d"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel