I would like to create a view that only contains the elements of few given categories, I’m not sure what is the best way to achieve this. Examples I found are not really illustrating what I’m trying to do.
I’ve tried the following code but it doesn’t seem to produce the expected result, all elements in my model are still visible. For instance I would like to isolate only walls in my newly created view:
public static ElementId Create3DView(Document doc, ElementId filterId)
{
ViewFamilyType vft = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.Cast<ViewFamilyType>()
.FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);
var viewId = ElementId.InvalidElementId;
using (Transaction t = new Transaction(doc, "Create 3d view"))
{
t.Start();
View3D view = View3D.CreatePerspective(doc, vft.Id);
view.DisplayStyle = DisplayStyle.FlatColors;
view.Name = Guid.NewGuid().ToString();
if (filterId != ElementId.InvalidElementId)
{
view.AddFilter(filterId);
view.SetFilterVisibility(filterId, true);
}
viewId = view.Id;
t.Commit();
}
return viewId;
}
public static void test()
{
var id = ElementId.InvalidElementId;
using (Transaction t = new Transaction(doc, "Create filter"))
{
t.Start();
var categories = new List<ElementId>();
categories.Add(new ElementId(BuiltInCategory.OST_Walls));
var pfe = ParameterFilterElement.Create(
doc, "filter", categories);
id = pfe.Id;
t.Commit();
}
var viewId = Create3DView(doc, id);
// ...
}