
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to use the API to iterate through all the pipes in the model and tally the total length of different pipe sizes. I found some sample code here (http://help.autodesk.com/view/RVT/2014/ESP/?guid=GUID-B9C38F9B-A11B-4369-B879-0A641A3E725F) which reports the various pipe sizes for each Pipe Segment. I'm trying to add simple Total Length tallying piece to this to prove my concept but I am having trouble matching up the Pipe Segment Name from each pipe and the Segment.Name from the Global Pipe Segments. Here is my code:
BuiltInParameter pipeSegmentParam = BuiltInParameter.RBS_PIPE_SEGMENT_PARAM; BuiltInParameter pipeLengthParam = BuiltInParameter.INSTANCE_LENGTH_PARAM; // Get all pipes in the project FilteredElementCollector collectorPipes = new FilteredElementCollector(doc); collectorPipes.OfClass(typeof(Autodesk.Revit.DB.Plumbing.Pipe)); IEnumerable<Pipe> pipes = collectorPipes.ToElements().Cast<Pipe>();
FilteredElementCollector collectorPipeType = new FilteredElementCollector(doc); collectorPipeType.OfClass(typeof(Segment)); IEnumerable<Segment> segments = collectorPipeType.ToElements().Cast<Segment>(); foreach (Segment segment in segments) { StringBuilder strPipeInfo = new StringBuilder(); strPipeInfo.AppendLine("Segment: " + segment.Name); strPipeInfo.AppendLine("Roughness: " + segment.Roughness); strPipeInfo.AppendLine("Pipe Sizes:"); double dLengthFac = 12; // used to convert stored units, 304.8 for Imperial to Metric, 12 for Imperial foreach (MEPSize size in segment.GetSizes()) { double totalLength = 0.0; foreach (Pipe pipe in pipes) { Parameter pipeSegment = pipe.get_Parameter(pipeSegmentParam); double pipeSize = pipe.Diameter; if (pipeSegment.AsString() == segment.Name.ToString()) { if (pipeSize == size.NominalDiameter) { totalLength = totalLength + pipe.get_Parameter(pipeLengthParam).AsDouble(); } } } strPipeInfo.AppendLine(string.Format("Nominal: {0:F3}, ID: {1:F3}, OD: {2:F3}", size.NominalDiameter * dLengthFac, size.InnerDiameter * dLengthFac, size.OuterDiameter * dLengthFac)); strPipeInfo.AppendLine(string.Format("Total Length: {0:F3}", totalLength)); } TaskDialog.Show("PipeSetting Data", strPipeInfo.ToString()); break; }
When I run this, I get zero length for all pipe sizes in the dialog window even though I know I have pipes in the model with the corresponding pipe type. When I debug and inspect the values, I notice that the variable pipeSegment has a whole bunch of values but none of which appear to match the built in parameter RBS_PIPE_SEGMENT_PARAM that I am trying to get. This appears to cause my first if statement to always be false. So how do you find the Pipe Segment property on a pipe to compare it to the Pipe Segment names in the project? Or is there a better way to solve this?
Solved! Go to Solution.