Reputation: 4375
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);
// ...
}
Upvotes: 1
Views: 131
Reputation: 8339
One possible method is IsolateCategoriesTemporary
. I assume that you want more than just a temporary setting, though. For that, you can use the HideElements
method. Just create view, implement a filtered element collector that selects all elements in that view that do not belong to the desired category, and hide them. Here is a sample code snippet to Isolate Elements with Revit API and Python that looks as if you could make good use of it for this purpose.
Upvotes: 1