How to access pressure network parts lists using VB.NET

How to access pressure network parts lists using VB.NET

Anonymous
Not applicable
2,555 Views
8 Replies
Message 1 of 9

How to access pressure network parts lists using VB.NET

Anonymous
Not applicable

Hi,

I'm developing a tool that deals with both pipe networks and pressure pipe networks using VB.NET.

I can obtain the object Ids of pipe networks parts lists and can easily access their properties. However, for pressure networks parts lists I coudn't find a way even to obtain the Object Ids of existing parts lists in the drawing; I'm wondering if pressure parts lists are basically exposed in the API. Can anybody help?

 

Thanks,

Remah Foda

0 Likes
Accepted solutions (2)
2,556 Views
8 Replies
Replies (8)
Message 2 of 9

Jeff_M
Consultant
Consultant
Welcome to the forums, Remah!

Pressure pipes are somewhat exposed, but no documentation exists that I know of. You must add a reference to AeccPressurePipesMgd.dll

Use the "Search this Board" tool to the right of the message listing, enter "Pressure", you will find quite a few similar messages and answers,
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi Jeff,

Thanks for trying to help. I already have the reference of AeccPressurePipesMgd.dll and can access the objects of "pressure pipe" and "pressure network" through it.

What I can't reach specifically is the "parts list" object of the pressure networks. I read some articles about this reference library and checked the object browser also but didn't find it. I'm trying to find a different way to catch it if any.

0 Likes
Message 4 of 9

Jeff_M
Consultant
Consultant
Accepted solution

Sorry, Remah, I misunderstood your request. Looking at the dll file with Ilspy I see that the GetPressurePartLists() method is defined as an Internal extension method, not Public, so it's not directly exposed. However, using Reflection you can still get the PartListCollection as an object...all of the PressurePartList classes are defined as Internal, so actually working with them may prove difficult. 

 

Here is an extension method, in c# as that is what I know, to get the PartLists:

        public static object GetPressurePartListsExt(this StylesRoot styles)
        {
            object[] args = { styles };
            var mytype = typeof(Autodesk.Civil.DatabaseServices.Styles.StylesRootPressurePipesExtension);
            var mi = mytype.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
            var m = mi[0]; //at this time there is only 1 member, may need to adjust in the future
            var plist = m.Invoke(null, args);
            return plist;
        }


//and I would call it like so from wherever:
                var pplist = civdoc.Styles.GetPressurePartListsExt();
Jeff_M, also a frequent Swamper
EESignature
Message 5 of 9

Anonymous
Not applicable
Accepted solution

That's excellent, thanks Jeff.

I wrote an equivalent VB code and it worked well. I can now obtain the names and objectIds of the existing pressure parts lists.

I'm sharing this VB code here below:

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.Civil.DatabaseServices
Imports Autodesk.Civil.ApplicationServices

'for reflection of private methods of pressure parts list
Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports Microsoft.VisualBasic


Public Class MyCommands
    <CommandMethod("GetPressurePartsLists")> Public Sub cmdGetPressurePartsLists()

        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor 'autocad document editor
        Dim civDoc As CivilDocument = CivilApplication.ActiveDocument 'civil 3d document

        'get pressure part lists collection
        Dim pressPartLists As Styles.StyleCollectionBase = MyTypes.GetPressurePartsListsExt(civDoc.Styles)
        ed.WriteMessage(vbLf & vbLf & "The number of pressure parts lists = " & pressPartLists.Count)

        'list the names of existing pressure parts lists
        Using trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
            Try
                Dim partsList As Autodesk.Civil.DatabaseServices.Styles.StyleBase
                For Each id As ObjectId In pressPartLists
                    partsList = trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
                    ed.WriteMessage(vbLf & partsList.Name)
                Next
            Catch
            End Try
        End Using

    End Sub

End Class
Public Class MyTypes

    'This function obtains the pressure parts list in a drawing
    Public Shared Function GetPressurePartsListsExt(styles As Styles.StylesRoot) As Styles.StyleCollectionBase

        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor 'autocad document editor
        Dim myType As Type = GetType(Styles.StylesRootPressurePipesExtension)

        'get the private method
        Dim myArrayMethodInfo As MethodInfo() = myType.GetMethods((BindingFlags.Static Or BindingFlags.NonPublic))
        ed.WriteMessage(vbLf & "The number of protected methods is " & myArrayMethodInfo.Length.ToString() & ".")

        ' Display information for all methods.
        Dim i As Integer
        For i = 0 To myArrayMethodInfo.Length - 1
            Dim myMethodInfo As MethodInfo = CType(myArrayMethodInfo(i), MethodInfo)
            ed.WriteMessage(vbLf & "The name of the method is " & myMethodInfo.Name & ".")
        Next i

        'run the method of getpressurelists
        Dim pressPartLists As Styles.StyleCollectionBase
        Dim myGetPressPartLists As MethodInfo = myArrayMethodInfo(0) 'the number 0 here depends on the composition of AeccPressurePipesMgd.dll library
        Dim arParam(0) As Object
        arParam(0) = styles
        pressPartLists = myGetPressPartLists.Invoke(Nothing, arParam)

        Return pressPartLists

    End Function

End Class
0 Likes
Message 6 of 9

heitz15
Advocate
Advocate
@Anonymous Would you mind sharing the code that you used to obtain the object Ids of pipe networks parts lists and access their properties? Ima newbie and im tryng to do the same
0 Likes
Message 7 of 9

heitz15
Advocate
Advocate
@Jeff_M

I guess you could help me too?
Message 8 of 9

benkas
Enthusiast
Enthusiast

@Jeff_M, @Anonymous is there any way to access other internal methods?

 

For example PressurePartSize?

 

I need create pressure network and need this information

0 Likes
Message 9 of 9

mbrynildsenUSQBS
Contributor
Contributor

Remah,

Do you know how I can set the Pressure Network "Default Parts List" with VB?

0 Likes