- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone!
I am having strange issue with following piece of code. Here I'm collecting all elements in current project and iterate through them to see if some of the elements are meets certain requirements. I have object RowItem to store all data.
Then I am trying to add ElementId of FamilyInstance to the current object. But strange thing is - if there are two elements in one room that are meets requirements their ElementIds don't differ after foreach loop (but differs in the process of cycling). I will try to explain further in code with comments. The problem occurs only when there is two instances of same family in one room, and I need to work it out. But just can't understand what's happening.
Any help will be highly appreciated!
AllElements = new FilteredElementCollector(doc) // Filtering all placed elements, works as expected
.WherePasses(filter) // design option filter
.WherePasses(multifilter) // multicategory filter
.WhereElementIsNotElementType()
.ToElements();
List<RowItem> passedItems = new List<RowItem>();
foreach (Element element in AllElements) // cycling through all placed elements
{
FamilyInstance elementInstance = element as FamilyInstance;
FamilySymbol elementSymbol = elementInstance.Symbol;
IEnumerable<RowItem> rowItem = null;
if (elementInstance.Room != null)
{
rowItem = dataList // List of RowItems from csv
.Where(x => x.familyName == elementSymbol.FamilyName) // if family name of element is same as in database
.Where(y => y.room == elementInstance.Room!.
get_Parameter(BuiltInParameter.ROOM_NAME).AsString()); // if element's room is same as in database
if (rowItem != null)
{
foreach (RowItem rw in rowItem)
//iterating through IEnumerable of objects to add ElementIds
//and add this objects to final List (passedItems)
{
passedItems.Add(rw);
passedItems.Last().element = element.Id;
Console.WriteLine(rowItem.Count() + " " + rw.familyName + " " + rw.room + " "
+ elementSymbol.FamilyName + " " + passedItems.Last().element);
// HERE it is all correct - Element Ids for different instances are different too.
// I literally reading the last element's Id correctly. But then..
}
}
}
}
foreach (RowItem ri in passedItems)
{
Console.WriteLine(ri.familyName + " " + ri.room + " " + ri.element);
// HERE ElementIds are no longer differs for two different elements. I just can't understand why
}
UPD.: I also tried it other way around, like so, but with same result:
rowItem = dataList
.Where(x => x.familyName == elementSymbol.FamilyName) // if family name of element is same as in database
.Where(y => y.room == elementInstance.Room!.
get_Parameter(BuiltInParameter.ROOM_NAME).AsString()); // if element's room is same as in database
if (rowItem != null)
{
foreach (RowItem rw in rowItem)
{
rw.element = element.Id;
passedItems.Add(rw);
}
}
I also tried not to use LINQ, and just for-looping to find matches. Same result. It's all OK while loop is going, but then it looks like ElementIds are just changing by themselves
UPD.2: Also just tried to use UniqueId instead of ElementId, and tried passing ElementId as string with conversion. Same result
Solved! Go to Solution.