In my script there are 2 transactions that are commited.
if i use an alert dialog after with exitscript=True the 2 transactions are rolled back.
Same if i use sys.exit(0).
Any idea? I want to cancel a script if the user don want to run the part after the alert question.
Without your code it’s hard to understand what goes wrong.
I think your code is this:
forms.alert("Do you want to continue?", exitscript=True)
I’d suggest you use something like this.
forms.alert("Do you want to continue?", yes=True, no=True, exitscript=True)
Alternative
if forms.alert("Do you want to continue?", yes=True, no=True):
#continue with script
PEBCAK
with revit.Transaction('name of transaction'):
# do stuff, the context manager handles the commited transactions
see the documentation for the alert window
Thank you for reply. The problem is that the exitscript option cancels Transactions commited before.
The wrapped revit.Transaction way is also rolled back if sys.exit(0) or forms.alert with exitscript=True follows after i the code. It seems that there is no way to leave a script and keep changes made before.
Again,
Why exit script?
Why don’t you just leave it as it is?
script.
do things
alert ‘hey you want to conintue’
if yes: continue.
(if not: … no need to do a single thing. A script doesn’t need an exit)
if forms.alert("Do you want to continue?", yes=True, no=True):
#continue with script
Thats the way i solved it now.
The question was if there is a possibility to cancel a script at a defined point without loosing steps made before.
I’m assuming the code was something similar to mine:
t1 = Transaction(doc, "T1")
t1.Start()
# code
t1.Commit()
forms.alert("Do you want to run the optional part?", yes=True, no=True, exitscript=True)
# optional part of the script
Now when you click “No” on the alert, it also discards the transaction which has already been commited.
Now this solution:
if forms.alert("Do you want to continue?", yes=True, no=True):
#continue with script
works, but in a case of a script with multiple such alerts, the script easily gets to 4 or 5 indents and becomes quite unreadable.
Is there any way to exit the script mid-code without indenting the rest of it?
yes this is exactly my case.
It would be nice to have an exit option in the mid-code without rollback of already commited transactions.