How FileteredElementCollector of View works?

How FileteredElementCollector of View works?

gprofile
Enthusiast Enthusiast
1,109 Views
9 Replies
Message 1 of 10

How FileteredElementCollector of View works?

gprofile
Enthusiast
Enthusiast

Can someone please explain how the FilteredElementCollector of the view works?

var doc = this.ActiveUIDocument.Document;
var fec = new FilteredElementCollector(doc, doc.activeView.Id);
// Does it collect all the elements based on view bounding box or view range or View level id?????

It seems to me that the Filter also collects the elements from the view below even though the view range of the active view is set to the default like this:

Level heightsLevel heights

So the "fec" sometimes outputs wrong elements which doesn't belong to this view.

0 Likes
1,110 Views
9 Replies
Replies (9)
Message 2 of 10

Yien_Chao
Advisor
Advisor
0 Likes
Message 3 of 10

gprofile
Enthusiast
Enthusiast

Thanks...

I am not sure if I use the SelectableInView filter right, the result is the same

var fec = new FilteredElementCollector(doc, activeView.Id).OfCategory(bic);
var selInView = new SelectableInViewFilter(doc, activeView.Id);

if (selInView.PassesFilter(element)) 
{
	//Select the elements here
}

// Is this right???
0 Likes
Message 4 of 10

Yien_Chao
Advisor
Advisor

hi,

 

with the selectableInView, any element of any categories that could be selected by the user in the view will appear, even if its hidden behind another element.

 

With the ElementCategoryFilter, you will only select the elements visible in the view, of the specified category.

 

In both case, the view range affect the selection.

0 Likes
Message 5 of 10

gprofile
Enthusiast
Enthusiast

Sorry for the confusion, I could select the Category I want to select using OfCategory quick filter and it works perfectly. The problem is with filtering of elements that belongs not only from active view but also from the view below. I have tried setting the view range limited to active view, but the result is the same.

 

Please look at this example below:

Active View PropertiesActive View Properties

 

View Range PropertiesView Range Properties

 

Task Dialog showing FilteredElementCollector of the View with false elements from the view belowTask Dialog showing FilteredElementCollector of the View with false elements from the view below

int count = 1;
var RevUiDoc = this.ActiveUIDocument;
var RevDoc = RevUiDoc.Document;

var bic = BuiltInCategory.OST_Floors;
var activeView = RevDoc.ActiveView;
var fec = new FilteredElementCollector(RevDoc, activeView.Id).OfCategory(bic);
var selInView = new SelectableInViewFilter(RevDoc, activeView.Id);

var elementLevels = new StringBuilder();
elementLevels.AppendLine("ACTIVE VIEW NAME: " + activeView.Name);
elementLevels.AppendLine("ACTIVE VIEW LEVEL ID: " + activeView.GenLevel.Id);
elementLevels.AppendLine();

foreach (var element in fec) {
	if (selInView.PassesFilter(element)) {
		elementLevels.AppendLine(count + " . " + "ELEMENT ID: " + element.Id);
		elementLevels.AppendLine("ELEMENT LEVEL ID: " + element.LevelId);
		elementLevels.AppendLine("ACTIVE VIEW LEVEL ID: " + activeView.GenLevel.Id);
		elementLevels.AppendLine();
		count++;
	}
}

TaskDialog.Show("Elements in active view", elementLevels.ToString());

Why does it select the elements from wrong views... Eventhough the view properties is limited to this view???

 

0 Likes
Message 6 of 10

gprofile
Enthusiast
Enthusiast

Can somebody please help me with this ???

0 Likes
Message 7 of 10

TripleM-Dev.net
Advisor
Advisor

Hi,

 

The FilteredElementCollector retrieves everything that's visible in the view.

So even if you're floorplan viewrange is set only to a single level (as in you're sample) it's possible something from another level is selected. For example a family that's placed a level lower, but has geometry (or even 2d info) expand beyond the level to the level in you're sample. (or even a element placed a level higher)

 

If you need all elements of a certain level use the Collector functions to filter for the level.

Otherwise you could even mis a element placed on the level but not visible (detail level, geometry modelled higher etc.)

 

Sample: Wall, the baseoffset can be set higher then the level it's on, so then you're filter will mis it or select it while it's on another level.

 

So it depends what you're goal is, select all in view or all placed on a specific level.

Both methods (workable samples even I think) are posted on this forum and also see the SDK samples.

(Filter By Level, Filter By View)

 

Best regards,

Michel

0 Likes
Message 8 of 10

gprofile
Enthusiast
Enthusiast

Thanks for your detailed explanation.

 

So which means if I need both then I would have to collect all the elements in view and filter them by level. However I guess this logic won't work if the elements are dependent on View and independent of Level.

 

 

0 Likes
Message 9 of 10

TripleM-Dev.net
Advisor
Advisor

Hi,

 

Actually really depends what the purpose is of the addin.

If you want all elements of a specific level, but limited by the element only visible in view then there are a few approaches.

You can use a ElementFilteredCollection By view and limit it by a Level(filter)

use: ElementFilteredCollection.Wherepasses(ElementLevelFilter)

 

Search this for for 'ElementFilter' and 'ElementLevelFilter', I think there will be enough samples (or SDK)

One note though; ElementFilter can be a QuickFilter, but ElementLevelFilter is derived from the slowfilter.

Depending on how many element should be processed, you may limit the ElementFilteredCollection first by a Quickfilter. For example if you only need walls, then filter it first on WallElements.

 

You can let me know if you need further help with the approach or code. 

 

Best Regards,

Michel.

 

0 Likes
Message 10 of 10

gprofile
Enthusiast
Enthusiast

Thanks for your reply. Its a macro.

 

I will try and see what actually fits in my case.

 

Have a good day.

0 Likes