I try to set transparent walls, using pyRevit. I do the following:
categories = List[ElementId]()
wallCatId = ElementId(BuiltInCategory.OST_Walls)
categories.Add(wallCatId)
ogs = OverrideGraphicSettings()
ogs.SetSurfaceTransparency(70)
t = Transaction(doc, "New parameter filter")
t.Start()
filter = ParameterFilterElement.Create(doc, "Walls filter", categories)
t.Commit()
all_views = FilteredElementCollector(doc).OfClass(View).ToElements()
for i in all_views:
if (i.ViewType == ViewType.ThreeD) or (i.ViewType == ViewType.FloorPlan):
views_to_treat.append(i)
t = Transaction(doc, "New visibility filter")
t.Start()
for i in views_to_treat:
i.AddFilter(filter.Id)
i.SetFilterOverrides(filter.Id, ogs)
t.Commit()
Nothing happens, I don't know why. Is it my "categories" that is wrongly defined (how can I know what kind of ElementId it expects? Is it the Id of the Wall Category? In that case, it should be ok here)? Or is it when applying the filter override to the view?
Any help would be greatly appreciated! Arnaud.
I can see that you are applying the transparency filter to Walls. I am not 100% sure that this is the most efficient way to achieve this since we can override transparency via Category override. Please keep in mind that Filters are limited as we can apply only a handful of them to the view. There is a max number. I don't remember from top of my head, but there is. Also, order of filters matters, as they can potentially override each other's rules based on order. Either way overriding transparency can be achieved by changing it on a Category like so:
catId = ElementId(BuiltInCategory.OST_Walls)
all_views = FilteredElementCollector(doc).OfClass(View).ToElements()
overrides = OverrideGraphicSettings()
overrides.SetSurfaceTransparency(70)
t = Transaction(doc, "Override Categories")
t.Start()
for i in all_views:
if ((i.ViewType == ViewType.ThreeD) or (i.ViewType == ViewType.FloorPlan)) and (i.IsCategoryOverridable(catId)):
try:
i.SetCategoryOverrides(catId, overrides)
except:
# print out error?
pass
t.Commit()
Also, just a few generic comments. Try to minimize the amount of times you iterate over lists, especially if they are the same items. If you can do what you need to do in the first loop, then that's the best. The above can be simplified even more with list comprehension but I wanted to keep it "obvious" for educational purposes.
I am also checking if Category is overridable before attempting to do so. Why? Because if view category overrides are controlled by a view template, it will not allow us to set the overrides. Also some categories don't have a surface transparency override ex. lines if I remember correctly.
Finally I like to put it all in a try/except statement so that i can catch any issues in my loop and still continue with other items. if I don't do that, and one view fails, we would have failed the whole operation.
This is what the result should be: