I am trying to create a script that can create quite a few different types of elements – roofs, walls, floors, direct shapes, etc – and to do this I need to use both built-in RIR components and custom python components that open and close transactions. I can get it to basically work once when I startup, but if I change the initial parameters for the script, or even just recompute the script, then it fails and I have errors all over the place, ranging from “1. Solution exception: Starting a new transaction is not permitted. . .” to the component just failing to update. From what I have tested, the errors are coming from multiple transactions and operations trying to happen all at once, or at least more than one at a time. But this is not an issue if I only use the RIR built-in components. So, my question is, is there any way to fix this so that the python components can stay in line and at least basically work like the built-in components?
I can describe it in more detail if you would like, or I can privately send you the script to take a look at, but I am not able to post it here at this time.
Hi Devin,
I have the same issues for scripts that I have done. The scripts eventually do work if I try and run them enough, but before they work I always get this same error.
I am doing my t.start() and then doing a series of loops and operations typically and then at the end of this I do my t.commit() . I wonder if this is the best way and if my start and commit should be within my loop?
Could you let me know how you tested this to see where the errors happened? and do you start your script by having it disabled and then enabling?
I think that I basically resolved this, although it still requires a Toggle (Boolean component) to be False at all times other than when you want to “bake” the elements. I used the sample code from the RIR guide for handling the transaction. I found that using the ‘with’ statement, things are quite a bit more stable. It is located here: Rhino.Inside®.Revit . And here is that code:
# create and start the transaction
with DB.Transaction(doc, '<give a descriptive name to your transaction>') as t:
t.Start()
# change Revit document here
# commit the changes after all changes has been made
t.Commit()
I still wish there was a way to replicate the behavior that the built-in element creation components exhibit, but I haven’t been able to figure that out at this point.
Yes, you basically have it right. It is also on that page.
Here is the relevant code:
if Trigger:
# create and start the transaction
with DB.Transaction(doc, '<give a descriptive name to your transaction>') as t:
t.Start()
# change Revit document here
# commit the changes after all changes has been made
t.Commit()
Excellent- do you just use the trigger if you want to bake something into rhino
Or would you also use the trigger just to start the transaction- so you wanted to set a parameter.
I have the same issue where the built in components work fine but I get issues when I start to use scripted components.
So to conclude- do you simply press the trigger only when you want to run that script- so it only ever runs when you ask it to- to avoid the script in effect running all the times etc?
I would just suggest studying that page for more information about transactions. My original question was more complex then what is being shown on that page, but I think it will certainly answer your questions.
My issue was almost exactly the same as yours- and ive tested this and it works fantastically thankyou! I assume if you dont use the trigger the script is just trying to run over and over.
It’s not the same. I want my custom python components to behave like the built in components–without a toggle. It can obviously be done since that’s how the built in components work.