Pipe Network parts on Profile View

By Augusto Goncalves

On a profile view, after add a pipe network part (structure or pipe), Civil 3D creates a new entity: ProfileViewPart. This object don’t have many methods, but it’s a database resident object (with ID and geometry).

So the question is: how get the part station and elevation of the profile view?

Using the part bounding box, we’ll access the XY coordinate on the model space. Then it’s possible to get the average point (or any other point, like minimum or maximum Y). Using that XY, we can go back to the profile view and ask what’s the station & elevation on that point.

The code sample below demonstrate the idea:

// select a part on the profile viewEditor ed = Application.DocumentManager.MdiActiveDocument.Editor;PromptEntityOptions peo = new PromptEntityOptions(  "Select a part on the profile view: ");peo.SetRejectMessage("nOnly parts on profile view");peo.AddAllowedClass(typeof(ProfileViewPart), true);PromptEntityResult per = ed.GetEntity(peo);if (per.Status != PromptStatus.OK) return; Database db = Application.DocumentManager.MdiActiveDocument.Database;using (Transaction trans = db.TransactionManager.StartTransaction()){  // get the part showing on the view  ProfileViewPart partPV = trans.GetObject(per.ObjectId,    OpenMode.ForRead) as ProfileViewPart;  Part part = trans.GetObject(partPV.ModelPartId,    OpenMode.ForRead) as Part;   // may have several PVs showing this part...  ObjectIdCollection pvIds = part.GetProfileViewsDisplayingMe();  foreach (ObjectId pvId in pvIds)  {    // get the average point of this structure on the profile view    // you may change this X,Y to the max or min...    Extents3d ext = partPV.GeometricExtents;    double x = (ext.MaxPoint.X - ext.MinPoint.X) / 2 + ext.MinPoint.X;    double y = (ext.MaxPoint.Y - ext.MinPoint.Y) / 2 + ext.MinPoint.Y;     // get the profile view    ProfileView pv = trans.GetObject(pvId, OpenMode.ForRead) as ProfileView;     // and the station/elevation on the profile view    double station = 0.0;    double elevation = 0.0;    pv.FindStationAndElevationAtXY(x, y, ref station, ref elevation);     ed.WriteMessage(      "n{0} showing on {1} at station: {2:0.00} | Elevation: {3:0.00}",      part.Name, pv.Name, station, elevation);  }}

Comments

3 responses to “Pipe Network parts on Profile View”

  1. Hi
    Good example, but there is a problem if a profile view part is visible in several ProfileViews, then its extents is actually box around all of them so x and y coordinates that you use for querying station and elevation are useless, and station or elevations you get in return are wrong.

  2. Thanks for your comment Damir, I haven’t tested this scenario… will need to double check it. Do you have an alternative suggestion?
    Best,
    Augusto Goncalves

  3. Hi Damir,
    Have you got any answer for this scenario?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading