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: 

pressure network parts lists get PressurePartSize using .NET

42 REPLIES 42
SOLVED
Reply
Message 1 of 43
benkas
2217 Views, 42 Replies

pressure network parts lists get PressurePartSize using .NET

Hello,

I am creating a pressure pipe network using .net.

 

I would like to know how I can get the PressurePartSize to be able to use in the

public ObjectId AddLinePipe method (LineSegment3d line, PressurePartSize partSize);

I know the classes are defined as Internal, does anyone know any method of getting access to the class?

something like this https://forums.autodesk.com/t5/civil-3d-customization/how-to-access-pressure-network-parts-lists-usi... 

 

I tried to adapt the function to return PressurePartSize instead of PressurePartsLists but I couldn't


Can someone help me?


thanks

Labels (3)
42 REPLIES 42
Message 2 of 43
Jeff_M
in reply to: benkas

I have not done much with the PressurePipes, but this works to get the desired pipe. If you know the GUID for the part you could just use the partslist.GetPart(guid) method instead of looping through the list.

 

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                //this is the extension method I have previosuly posted to this forum
                var partslists = civdoc.Styles.GetPressurePartListsExt();
                var partslist = (PressurePartList)tr.GetObject(partslists[0], OpenMode.ForRead);
                var parts = partslist.GetParts(PressurePartDomainType.Pipe);
                PressurePartSize useThisPart = null;
                foreach (PressurePartSize part in parts)
                {
                    //things that make you hmmmm.... why does the DiameterNominal return a string in the format shown insted of a double?
                    var size = part.GetProperty(PressurePartContextType.DiameterNominal);
                    var family = part.GetProperty(PressurePartContextType.PartFamilyName);
                    if ((string)size == "24 in x 24 in")
                        if ((string)family == "pipe-push on-ductile iron-350 psi")
                        {
                            useThisPart = part;
                            break;
                        }
                }
                if (useThisPart != null)
                {
                    //create the pipe using the found part
                }
                tr.Commit();
            }
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 43
benkas
in reply to: Jeff_M

@Jeff_M Thanks for the answer, but my problem is Autodesk.Civil.DatabaseServices.Styles.PressurePartList is inaccessible.

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0122	'PressurePartList' is inaccessible due to its protection level	Pipes	D:\Tubagem\V2\app\Pipes\Civil.cs	102	Active
Message 4 of 43
Jeff_M
in reply to: benkas

@benkas  Which version of Civil 3D are you using?

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 43
benkas
in reply to: Jeff_M

I using Civil 2020.

 

I solved this way :

var partslist = tr.GetObject(partslists[0], OpenMode.ForRead);

                System.Type objType = System.Type.GetType("Autodesk.Civil.DatabaseServices.Styles.PressurePartList, AeccPressurePipesMgd", false, true);
                var myArrayMethodInfo = objType.GetMethods();

                var myGetPressPartLists = myArrayMethodInfo[8];
                var arParam = new object[1];
                arParam[0] = PressurePartDomainType.Pipe;
               var pressPartLists = myGetPressPartLists.Invoke(partslist, arParam);

Thanks for the help @Jeff_M 

Message 6 of 43
benkas
in reply to: Jeff_M

in civil 2021 this code work. thanks @Jeff_M 

Message 7 of 43
benkas
in reply to: benkas

@Jeff_M can you help me add appurtenance / fitting to the pressure pipe? please!!

Message 8 of 43
harsh.shahVPZTM
in reply to: Jeff_M

This code works for 2021 Civil3d Only?
I tried on Civil3d 2018 and there is no definition like GetPressurePartListsExt(). It is giving an error in 2018.

 

Message 9 of 43
Jeff_M
in reply to: harsh.shahVPZTM

It helps to take note of what I put as a comment in the code I posted:

                //this is the extension method I have previosuly posted to this forum
                var partslists = civdoc.Styles.GetPressurePartListsExt();

 

Then a search of this forum for GetPressurePartListsExt would give you a link to the thread this post is in:

https://forums.autodesk.com/t5/civil-3d-customization/how-to-access-pressure-network-parts-lists-usi...

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 43
harsh.shahVPZTM
in reply to: Jeff_M

Hi Jeff,

Thank you for your reply.

In C3D 2018, PressurePartSize and PressurePartList are inaccessible due to the protection level.

Also I had previously used the code from the link you shared
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;
}


var partslists = doc.Styles.GetPressurePartListsExt(),
GetPressurePartListsExt() - this method gives error and it stays StylesRoot does not contain a definition for GetPressurePartListsExt. Is there a way to add it to the definitions?

Any suggestions. Thank you.
Message 11 of 43
harsh.shahVPZTM
in reply to: benkas

Hi,

From pressPartLists how are you able to extract the PressurePartSize?
And PressurePartSize is protected in 2018,2019,2020.
Message 12 of 43
benkas
in reply to: harsh.shahVPZTM

@harsh.shahVPZTM try this in civil 2021

 

 public static StyleCollectionBase GetPressurePartsListsExt(StylesRoot styles)
        {
            var myType = typeof(StylesRootPressurePipesExtension);

            var myArrayMethodInfo = myType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);

            StyleCollectionBase pressPartLists;
            var myGetPressPartLists = myArrayMethodInfo[0]; // the number 0 here depends on the composition of AeccPressurePipesMgd.dll library
            var arParam = new object[1];
            arParam[0] = styles;
            pressPartLists = myGetPressPartLists.Invoke(null, arParam) as StyleCollectionBase;
            return pressPartLists;
        }

 public static void GetCatalog()
        {
            var doc = CivilApplication.ActiveDocument;
            using (Transaction tr = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
            {
                using (Autodesk.AutoCAD.ApplicationServices.DocumentLock docLock = Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    StyleCollectionBase partslists = GetPressurePartsListsExt(doc.Styles);
                    foreach (var plObj in partslists)
                    {
//try civil 2021
                        PressurePartList partList = (PressurePartList)tr.GetObject(plObj, OpenMode.ForRead);
                         List<PressurePartSize> parts = partslist.GetParts(PressurePartDomainType.Pipe);
                 List<PressurePartSize> appurtenance = partslist.GetParts(PressurePartDomainType.Appurtenance);
                 List<PressurePartSize> fitting = partslist.GetParts(PressurePartDomainType.Fitting);
                    }

                }
                tr.Dispose();
            }
        }

 

in civil 2018, 2019, 2020 you are use the reflexion, something identical to what is in the function GetPressurePartsListsExt, type this

 

System.Type objTypePressurePart = System.Type.GetType("Autodesk.Civil.DatabaseServices.Styles.PressurePartSize, AeccPressurePipesMgd", false, true);
var myArrayMethodInfo = objTypePressurePartList.GetMethods();
var myGetPressPartLists = myArrayMethodInfo[43]; //key the method to use

myGetPressPartLists.Invoke(partlist, arParam)

 

Message 13 of 43
benkas
in reply to: benkas

@harsh.shahVPZTM try this in civil 2018, 2019, 2020 

 System.Type objTypePressurePartList = System.Type.GetType("Autodesk.Civil.DatabaseServices.Styles.PressurePartList, AeccPressurePipesMgd", false, true);
                var myArrayMethodInfo = objTypePressurePartList.GetMethods();

                var myGetPressPartLists = myArrayMethodInfo[8];
                var arParam = new object[1];
                arParam[0] = PressurePartDomainType.Pipe;
                var pressPartListsObj = myGetPressPartLists.Invoke(partslist, arParam);
                var pressPartLists = ((IEnumerable)pressPartListsObj).Cast<object>().ToList();

 

Message 14 of 43
harsh.shahVPZTM
in reply to: benkas

@benkas Hi thank you for your help. 

 

I have got up to the point of getting the pressure part list. From this list, i want to run a loop to check all the parts and their description and compare it with a value i have.

 

PressurePartSize pSize = null;
foreach (PressurePartSize part in pressPartLists)

{

}

PressurePartSize in C3D 2018-2020, it is protected. 

 

var pressPartLists = ((IEnumerable)pressPartListsObj).Cast<object>().ToList();

From pressPartLists, I am not able to reach the description of a part. 

 

Any idea. Thanks again.

 

Message 15 of 43
benkas
in reply to: harsh.shahVPZTM

@harsh.shahVPZTM I don't know, maybe something like this:

PressurePartSize pSize = null;
System.Type objTypePressurePartSize = System.Type.GetType("Autodesk.Civil.DatabaseServices.Styles.PressurePartSize, AeccPressurePipesMgd", false, true);
var myArrayMethodInfo = objTypePressurePartList.GetMethods();
var myGetPressPartSize = myArrayMethodInfo[8]; //see method key from myArrayMethodInfo


foreach (PressurePartSize part in pressPartSizes)
{
var arParam = new object[0]; //set number necessary params, in this case zero
arParam[0] = PressurePartDomainType.Pipe;//set params, case necessary
 var pressPartListsObj = myGetPressPartSize.Invoke(part, arParam);
var pressPartSizeLists = ((IEnumerable)pressPartListsObj).Cast<object>().ToList();
}

it must be something like this

Message 16 of 43
harsh.shahVPZTM
in reply to: benkas

Thank you benkas.
I tried with PressurePartSize but it is protected in Civil3d 2018 and i cannot use that.
Error - PressurePartSize is inaccessible due to its protection level.
Message 17 of 43
benkas
in reply to: harsh.shahVPZTM

@harsh.shahVPZTM the best is to use the civil 2021 or 2022.

I had the same problems as you, I changed the version of the civil and most of the problems with the pressure pipes were solved

Message 18 of 43
harsh.shahVPZTM
in reply to: benkas

Yeah it works perfectly in 2021. Will do that. Thanks again @benkas.
Message 19 of 43
benkas
in reply to: harsh.shahVPZTM

@harsh.shahVPZTM if you can get the fittings and appurtenances object id to use here

PressurePipeNetwork.AddFitting (ObjectId fittingId) 
PressurePipeNetwork.AddAppurtenance (ObjectId appurtenanceId)

tell me please.

 

saw your post about "Creating Pressure Pipe, Fittings, Appurtenances from Excel Data

I'm working on an identical project, I can add pipes, but Fittings and Appurtenances I can't.
because I haven't been able to get the objectId of these objects.

Message 20 of 43
harsh.shahVPZTM
in reply to: benkas

@benkas 

Yes sure will let you know. Do tell me if you crack it as well. 

 

Also you are using Civil3d 2021 for your work?

 

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report