Hi,
I'd like my macro to prompt the user to select a pipe network that I will then export to excel. How is this possible to achieve?
Thanks
Hi,
I'd like my macro to prompt the user to select a pipe network >>> Try the following :
Dim oPipe As AeccPipe
Dim objEnt As AcadObject
Dim varPick As Variant
ThisDrawing.Utility.GetEntity objEnt, varPick, "Select a Pipe : "
If TypeOf objEnt Is AeccPipe Then
Set oPipe = objEnt
End If
-----
For Export to Excel, there is a sample code available in the Civil 3D installation folder :
C:\Program Files\Autodesk\AutoCAD Civil 3D 2013\Sample\Civil 3D API\COM\Vba\Pipe
ImportFromExcel - Import Pipes and Structures' data from a Excel file to the current drawing.
ExportToExcel - Export Pipes and Structures' data in a current drawing to a Excel file.
Hope this helps !
Thanks,
i try the method in 2021 and it never returns a pipe. if i break after the getentity it says my type is AcadObject/IAeccPipe. and thus never passes the if then statement. if i skip the if then statement it gives me a type mismatch. i tried running the suggested example and it never finds a pipe because the typeof statement gives a mismatch. what am i doing wrong?
Have you added the Pipe libraries to the project references? This image is from C3D 2017, as that is the only version I have enabled the VBA option. For 2021 it will be 13.3 instead of 11
Have you considered moving away from VBA to a .NET language?
yes.
and when I select my pipe the object returned is formatted like
and the test fails. i tried the pipes to excel and it didn't find any pipes because it failed the same way. couldn't find any pipe objects.
@davidurbanpe , I seem to recall running into this issue with a release of C3D sometime back (2009 or 2010?). Searching through the posts here I'm not seeing anything about it. It's been so long since I've used VBA I just can't recall things like this any longer.
Well, I tested with my C3D 2021 with following code (with the same references as your "References" dialog box shown. except for not referencing "AutoCAD/ObjectDBX Common 23.0 Type Library"), it works as expected:
Option Explicit
Public Sub TestPipe()
Dim ent As AcadEntity
Dim pt As Variant
Dim pipe As AeccPipe
On Error Resume Next
ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Select a pipe:"
If Not ent Is Nothing Then
If TypeOf ent Is AeccPipe Then
'' === Following ALSO WORKS! ===
'' If TypeOf ent Is IAeccPipe Then
Set pipe = ent
MsgBox pipe.Name
Else
MsgBox "Selected wrong entity!"
End If
End If
End Sub
If the comment in the code noted, you can also do
If TypeOf ent Is IAeccPipe Then
....
End If
in spite IAeccPipe is not listed in Object Browser.
Odd. I can confirm that in a new project the code for selecting a pipe works. However, using the PipeSample.dvb fails to find pipes/structures, whether the AeccPipe or IAeccPipe object is used. What I found is that by removing the 4 references for the C3D libraries, closing the references window, and re-adding the same references, then allows the PipeSample macros to work as expected.
I figured it out. somehow two versions of the Autodesk pipe and land 13.3 was installed and i had picked the one that didnt work. when I picked the second set it all worked.