Add results (C#)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all. I'm very new to C#. I've been putting together bits of code to create a tool that gets the current selection (of pipe) and displays the "Length" parameter for each instance. The attached jpg shows the current result.
What I'd like to do next is provide a TOTAL length for all the pipes selected.
How can I append/add to my "p" value (below) for each instance?
(Sorry about the formatting of the code)
#region Namespaces
using System;
using System.Collections.Generic;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Windows.Forms;
using System.Diagnostics;
using Autodesk.Revit.DB.Plumbing;
using System.Text;
#endregion
namespace TryThis
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
// Select some elements in Revit before invoking this command
// Get the handle of current document.
UIDocument uidoc = commandData.Application.ActiveUIDocument;
// Get the element selection of current document.
Selection selection = uidoc.Selection;
ElementSet collection = selection.Elements;
if (0 == collection.Size)
// If no elements selected.
TaskDialog.Show("Revit", "You haven't selected any elements.");
}
else
{
String info = "Pipe Lengths are: ";
foreach (Pipe pipe in collection)
//this is the code I would like to add to for each instance of pipe, so I can pull a TOTAL later
Parameter p = pipe.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH);
info += "\n\t" + p.AsValueString();
}
TaskDialog.Show("Revit", info);
}
}
catch (Exception e)
{
message = e.Message;
return Autodesk.Revit.UI.Result.Failed;
}
return Result.Succeeded;
}
}
}