Novice - HideElements throwing transaction not closed error

My goal is to hide all of a certain type of elements in the model.

I am converting a bunch of Dynamo scripts over to Python, but I am very new to Python and the RevitAPI.

I have the following code:

els = get_elements_by_fam_name('fam_name')

t = Transaction(doc, __title__)
t.Start()

# Loop through elements
for el in els:
    owner_view = doc.GetElement(el.OwnerViewId)
    owner_view.HideElements(el.Id)

t.Commit() #Commit the transaction

I am doing something wrong with the HideElements() method. If I comment that line out, I can test and print all sorts of things in regards to making sure I am getting the elements, the owner views, etc. But I always get an error with the HideElements portion. I don’t know what I am missing.

Thanks for any assistance and for your patience with the new guy. :smiley:

1 Like

HideElements() takes an list collection or IList as an input

The answer should be along these lines (on my phone so expect turbulences)

from pyrevit.framework import List

elems_ids =List[DB.ElementId]([elem.Id for elem in elems])
active_view = doc.ActiveView
owner_view.HideElements(elems_ids)
2 Likes