Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to prompt user to select an existing pipe network in VBA ?

8 REPLIES 8
Reply
Message 1 of 9
ruipfbarreiros
744 Views, 8 Replies

How to prompt user to select an existing pipe network in VBA ?

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

---------------------------------------

Using Building Design Suite 2019
8 REPLIES 8
Message 2 of 9

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,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 3 of 9

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?

Message 4 of 9
Jeff_M
in reply to: davidurbanpe

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

 

2020-09-10_15-03-55.png

 

Have you considered moving away from VBA to a .NET language?

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 9
davidurbanpe
in reply to: Jeff_M

yes.

davidurbanpe_0-1599775735553.png

and when I select my pipe the object returned is formatted like 

davidurbanpe_1-1599776102877.png

 

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.

 

Message 6 of 9
Jeff_M
in reply to: davidurbanpe

@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. 

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 9
norman.yuan
in reply to: davidurbanpe

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.

 

Message 8 of 9
Jeff_M
in reply to: norman.yuan

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.

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 9
davidurbanpe
in reply to: Jeff_M

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report