How to Iterate over elements by MEP System Name

How to Iterate over elements by MEP System Name

Anonymous
Not applicable
2,262 Views
2 Replies
Message 1 of 3

How to Iterate over elements by MEP System Name

Anonymous
Not applicable

Dear all.

 

I want to do selection by MEP System Name. Is this possible?

 

MEP System.png

 

If cannot, this is how i am planning to do:

  • to pick one element
  • get parameter of System Type and System Name
  • Check all MEP element with same System Type and System Name.

Is there a better way to do this?

 

I have tried below codes as in

http://thebuildingcoder.typepad.com/blog/2013/02/simple-mep-system-traversal.html,

but the results seems incorrect where the number of connector/elements is different from my MEP system elements in my Revit project .

 

void TraverseSystems(Autodesk.Revit.DB.Document doc) {

FilteredElementCollector systems = new FilteredElementCollector(doc).OfClass(typeof(MEPSystem));

int i, n;
string s;
string[] a;

StringBuilder message = new StringBuilder();

foreach (MEPSystem system in systems) {

message.AppendLine("\n\nSystem Name: " + system.Name);
message.AppendLine("\nBase Equipment: " + system.BaseEquipment);

ConnectorSet cs = system.ConnectorManager.Connectors;

i = 0;
n = cs.Size;
a = new string[n];

s = string.Format("\n{0} element{1} in ConnectorManager: ", n, PluralSuffix(n));

foreach (Connector c in cs) {
Element e = c.Owner;

if (null != e) {
a[i++] = "\n" + e.GetType().Name + " " + e.Id.ToString();
}
}

message.AppendLine(s + string.Join(", ", a));

i = 0;
n = system.Elements.Size;
a = new string[n];

s = string.Format( "\n{0} element{1} in System: ", n, PluralSuffix(n));

foreach (Element e in system.Elements) {
a[i++] = "\n" + e.GetType().Name + " " + e.Id.ToString();
}

message.AppendLine(s + string.Join(", ", a));
}

n = systems.Count<Element>();

string caption = string.Format("Traverse {0} MEP System{1}", n, (1 == n ? "" : "s"));

TaskDialog dlg = new TaskDialog(caption);
dlg.MainContent = message.ToString();
dlg.Show();
}

 

MEP System Count.png

 

0 Likes
2,263 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

I've found a way to iterate using parameter name from link below:

 

http://thebuildingcoder.typepad.com/blog/2010/06/element-name-parameter-filter-correction.html

 

here is my code:

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) {
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;

string strMEPSysName = "Mechanical Supply Air 2";


FilteredElementCollector fec = new FilteredElementCollector(doc);
ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.RBS_SYSTEM_NAME_PARAM));
FilterStringRuleEvaluator fsre = new FilterStringEquals();
FilterRule fr = new FilterStringRule(pvp, fsre, strMEPSysName, true);
ElementParameterFilter epf = new ElementParameterFilter(fr);

fec = fec.WherePasses(epf);
foreach (Element el in fec) {
Debug.Print(el.Category.Name + " : " + el.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString() + " : " + el.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString() + " : " + el.Id);
}
return Result.Succeeded;
}

 

0 Likes
Message 3 of 3

aignatovich
Advisor
Advisor

You may also explore properties of MEPSystem children classes, such as

BaseEquipment (The base panel or equipment of the system.)
DuctNetwork (The ducts and fittings contained within the system. The return value doesn't include terminals or equipments, the ducts and fittings are returned in no particular order)
Elements (Terminal elements in the system. The return value is a read only collection and doesn't include the base equipment or panel.)

for MechanicalSystem. BaseEquipment, PipingNetwork, Elements properties for PlumbingSystem.