I’m trying to add a material parameter to multiple families that I’m creating through dynamo, but the second one I do is giving me this error: “Warning: Parameter.AddParameter operation failed.
A sub-transaction can only be active inside an open Transaction.”
I even used a Data stream wait node so that the second starts after the first, but it didn’t help.
What should I do to make the script work? Is there a another better way to achieve what I want perhaps?
Screenshot and example file below.
@erfajo I wish you could post a link to the said conversation. I am having a hard time recalling any specifics. I have answered 100s of questions on this forum, and unfortunately cannot remember all of the different conversations that I had here over the years.
It appears to me that the component that is causing the issue is from @erfajo package, and that its using a SubTransaction. Since SubTransactions can only be started when there is already an open Transaction and there is no guarantee in Dynamo that this is the case at all times, I think its best to recommend this:
@erfajo should remove the SubTransaction routine from his nodes and instead use the standard methods available to Dynamo developers from the TransactionManager class.
@erfajo should check if there is an open Transaction, before attempting to start a SubTransaction. There are API methods available for that, and it would have been a good coding practice to do so.
For situations where you want to force the Transaction to end, just use Transaction.End node. Place it after the node that does some modification to the Revit DB, and these changes will be committed right away.
I think that sums up what the issue here is.
OK, @erfajo denies using SubTransactions and I have no reason not to believe him, so let’s assume that this is not the issue.
If that’s the case, then the only place in this script that I can see a potential for this kind of error to occur is actually at the Document.LoadFamily this can only happen when there are no transactions open in the current Document. Just put Transaction.End before any load nodes. Can you try that?
Ps. @erfajo why so aggressive? Relax for a second. No one is accusing you of anything. I figured from the conversation that we were having that this is what must be happening in your nodes. Since they are not Open Source, I don’t really have an easy way of verifying that really quickly. I basically went off of a hunch. Didn’t mean to offend anyone. Apologies, if you were offended, but seriously, take a chill pill.
I think this is why I prefer to use Python so much for these types of things. I know that Orchid has many great nodes, but since they are closed (not arguing that’s a bad thing) it makes these types of things hard to fix on the fly. I have made many graphs that do multiple operations on multiple families and although a bit harder, the python approach is the most steamlined and provides in my opinion, the quickest run times as well. Plus you can use any manor of Transactions you would like. This is why I have shared “code” several times before to the rebuke of @erfajo.