Hello,
i have the problem when i change too many elements. Revit collabse or it “checks out the worksets”
i found the sleep function in the module time… it works well i can force revit to recover f.e. for one second… but it takes to much time! how can i set the code that it makes f.e. after 100 transaction a break by 1 sec ?
#functions
def tolist(x):
if hasattr(x,'__iter__'): return x
else: return [x]
#collector
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows)
all_elements = tolist(collector.WhereElementIsNotElementType().ToElements())
test_show = []
#Do some action in a Transaction
t = Transaction(doc,"Set Comments")
t.Start()
test_show = []
#Do some action in a Transaction
try:
for i in all_elements:
time.sleep(1)
comment = i.LookupParameter("Kommentare").Set("TEST")
test_show.append("Test")
except:
pass
t.Commit()
TransactionManager.Instance.TransactionTaskDone()
KR
Andreas
I don’t know if this is going to help. Right now you only have one transaction that encompasses your entire loop. So all the computation happens at once and then you just have one push of (for example) 1000 elements. I don’t know if pausing is going to really do anything to improve performance since the pause would still likely happen within the single transaction. You might want to look at using multiple transactions instead of one. In that case, you’d just count how many objects you have to interact with and split your loop up to use a counter with a max number of element interactions per transaction. Your transaction would then be within the main loop of your code.
Even then, you’re better off determining what is actually causing things to slow down and have issues. 115 elements is not a lot.
1 Like
@Nick_Boyts ,
that was a test. I saw that the run takes 115 seconds. So i will try to follow your discription… to make a bulk of transactions. Or can use time.sleep in a transaction group ?
KR
Andreas
I don’t have any knowledge on if or why a time delay would help with processing a transaction in Revit but you should be able to use it inside a transaction group too.
1 Like
It wouldn’t help at all. You’d eventually hit the same issues, but you’d wait 1 second between attempts until you hit the issue.
1 Like
@jacob.small ,
ok understand, so the down-performance happened in the transaction. So there is no “waiting” - ok.
KR
Andreas
1 Like
There are some issues with your code which may be creating your problem
You are using two types of Transactions - One from RevitServices namespace with TransactionManager.Instance.TransactionTaskDone()
and another from Autodesk.Revit.DB namespace t = Transaction(doc,"Set Comments")
etc.
Your code opens a transaction but does not close it with t.Close()
and may be causing memory or runtime issues
Improve this by either using TransactionManager.Instance.EnsureInTransaction(doc)
instead of t = ...
and removing all the t
transaction code or with Trasaction(doc, "Set Comments") as t:
and indenting the code up to and including t.Commit()
and removing the other type of transaction
The FilteredElementCollector Class always returns an iterable (unless you use the FirstElement()
method) so the tolist()
function is redundant
1 Like