How to get elements from linked document with using by color(Visibility/Graphics) filter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello. Developers.
I'm currently working on getting the elements of the linked document from the currently active view.
The client's environment has more than 100 linked documents.
This part is the biggest problem.
There are too many linked documents and all linked elements are loaded.
To solve this, we decided to load only the elements visible in the active view.
I know, This discussion has been very much.
Because the view of the active view and the linked document's view is different,
it shouldn't use view as the second argument of
-- FilteredElementCollector collector = new FilteredElementCollector(m_doc, active_view) --
So, I tried to get the elements in the Bounding Box using the crop box.
This also loads all linked elements that exist within the crop box.
Even though it should only load visible elements...
I want to get only the visible elements of the linked document using the color filter
in the visibility graphic settings.
Is this possible?
acitive view state Image.
// AutoDwg View ID 수집
View view = new FilteredElementCollector(m_doc)
.OfClass(typeof(View))
.Cast<View>()
.Where(x => x.ViewName.ToUpper().Contains("AUTODWG"))
.SingleOrDefault();
FilteredElementCollector collector = new FilteredElementCollector(m_doc);
List<Element> RvtLinkTypeElems = collector.OfCategory(BuiltInCategory.OST_RvtLinks)
.OfClass(typeof(RevitLinkType))
.ToElements()
.Cast<Element>()
.ToList();
ICollection<ElementId> filterIDs = view.GetFilters();
List<ElementId> visibleColorFilterIDs = filterIDs.Where(x => view.GetFilterVisibility(x) == true).ToList();
foreach (Element elem in RvtLinkTypeElems)
{
RevitLinkType linkType = elem as RevitLinkType;
bool ishidden = linkType.IsHidden(view);
// Check Link Filter checked
if (linkType.IsHidden(view)) continue;
// Check Color Filter checked
foreach (var item in visibleColorFilterIDs)
{
var colorFilter = m_doc.GetElement(item);
//.
//.
//.
// I don't know what to do.
}
foreach (Document linkedDoc in m_uiapp.Application.Documents)
{
if (linkedDoc.Title.ToUpper().Replace(".RVT", "").Equals(linkType.Name.ToUpper().Replace(".RVT", "")))
{
try
{
FilteredElementCollector collLinked = new FilteredElementCollector(linkedDoc);
List<Category> cats = new List<Category>();
var fcoll = new FilteredElementCollector(linkedDoc)
.OfClass(typeof(ParameterFilterElement))
.Cast<ParameterFilterElement>();
foreach (ParameterFilterElement pfe in fcoll)
{
foreach (ElementId item in pfe.GetCategories())
{
cats.Add(m_doc.Settings.Categories.get_Item((BuiltInCategory)item.IntegerValue));
}
}
var catgroup = cats.GroupBy(x => x.Name);
List<ElementId> cableTryIDs = cats
.Where(x => x.Name.Contains("Cable Trays")
|| x.Name.Contains("케이블 트레이"))
.Select(x => x.Id).ToList();
var cabletryas = collLinked.WhereElementIsNotElementType()
.Where(x => x.Category != null && cableTryIDs.Contains(x.Category.Id))
.ToList();
}
catch (Exception exl)
{
System.Windows.Forms.MessageBox.Show($"{linkedDoc.Title}\r\n{exl.Message}");
}
}
}
}