Undo Dynamo Action

Hello Dynamo Friends :slight_smile:

I would like to know which actions that run in a dynamo script can be undone in revit after the run.

An example: I have a dynamo script that duplicates a view. After the run i can not undo that in revit.

Can i affect that behavior by wrapping something in the script in a transaction?

Pretty shure thats a revit thing and not a dynamo thing, would be thankfull for any information regarding the undo behavior :slight_smile:
Kind regards

2022-04-05_14h03_43

Hello,

If your script is realy doing something you can just go back!

KR

Andreas

Be wary though, there are 1-2 things you can’t just undo (I think deleting some items is one of these.)

Always save your Revit file BEFORE you run your script, that way if you can’t Ctrl+Z you still have your original file.

1 Like

Strange, i can undo a view duplication i made in revit, but not if i do it with dynamo. Maybe it has to do with oder things in my script, i will post more details on this later.

Hello,
You can use PostableCommand.Undo (‘one undo’)

import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

#import Revit APIUI namespace
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication

commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Undo)
uiapp.PostCommand(commandId)
3 Likes

Should be doable unless there is an additional issue at play (ie: opening the document in the background, syncing or saving). Please post the graph so we can help.

You can roll back a transaction… I don’t know but how your script looks like: