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)
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.
Hi @c.poupin I want to apply two times undo though postable command. Is it possible ? if it is, then how should I proceed ? I have forced another undo python node till first one executes but the second one is not working.
Can you please tell me how to undo two times ?
#Postable Command by nathan.chapman
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.UI import RevitCommandId
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.UI import ExternalCommandData
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
RunIt = IN[0]
if RunIt == True:
commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Undo)
uiapp.PostCommand(commandId)
#uiapp.PostCommand(commandId)
errorReport = "Success"
else:
errorReport = "Failed to do the action"
#Assign your output to the OUT variable
OUT = errorReport
I encountered another undo problem just a few days ago.
It´s a code that sets sheet parameters with param.Set().
While I can undo that in revit perfectly fine, I can not undo it when setting the parameters in dynamo or pyrevit.
It´s a really really rare case that a transaction is not allowing me to undo it later in the revit UI.
Edit: Not sure if I actually tried that with dynamo…maybe just a pyrevit problem…
def update_parameter(sheet, param, param_name, current_value, new_value):
if WorksharingUtils.GetCheckoutStatus(doc, sheet.Id) != CheckoutStatus.OwnedByOtherUser:
t = Transaction(doc, "Set Sheet Parameter")
t.Start()
try:
# Check if new_value is a float and a whole number
if isinstance(new_value, float) and new_value.is_integer():
new_value = str(int(new_value)) # Convert to integer string if it's a whole number
else:
new_value = str(new_value) # Otherwise, just convert to string
param.Set(new_value)
t.Commit()
print("Success: {0} - {1}, the parameter value {2} was changed from {3} to {4}".format(sheet.SheetNumber, sheet.Name, param_name, current_value, new_value))
except Exception as e:
print("ERROR: {0} - {1} for {2} from {3} - Exception: {4}".format(sheet.SheetNumber, sheet.Name, param_name, current_value, str(e)))
t.RollBack()
else:
print("ERROR: {0} - {1} is owned by another user, the parameters could not be set.".format(sheet.SheetNumber, sheet.Name))```