I ran my Dynamo script only twice, but in the undo history, it shows 13 times. I intend to run the script multiple times, and if something goes wrong, I should be able to undo the previous execution. How can I ensure that each execution registers as a single undo action?
i solved this here very well! check it
you can “reverse” the issue passed on the topic… it seems to make a group transaction
KR
Andreas
Hey @vishalghuge2500 if u would hv noticed it’s making the number of transaction equal to the number of your selection, i feel going through the @Draxl_Andreas reply would solve it, let us know if it does.
@Draxl_Andreas
sorry I’m still leaning python scripting. I dont get your solution. please give it a try.
#Copyright(c) 2016, Dimitar Venkov
# Cyril POUPIN : fix for structural Columns and Beams v2
# @5devene, dimitar.ven@gmail.com
import clr
import re
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
def output1(x):
if len(x) == 1: return x[0]
else : return x
surfaces, gpoints = [], []
sel1 = uidoc.Selection
ot1 = Selection.ObjectType.Face
ref_list = sel1.PickObjects(ot1, "Select the faces and press Finish.")
for ref in ref_list:
el1 = doc.GetElement(ref)
el1Type = doc.GetElement(el1.GetTypeId())
sf0 = el1.GetGeometryObjectFromReference(ref)
stableRef = ref.ConvertToStableRepresentation(doc)
n_ref = None
print(stableRef)
# force to recompute refrerence
if not ":0:INSTANCE:" in stableRef :
print('pass')
surface_repr = re.search(r'(:\d+:SURFACE$)', stableRef).group(1)
new_stableRef = el1.UniqueId + surface_repr
print(new_stableRef)
# dot not to reuse the ref local variable
n_ref = Reference.ParseFromStableRepresentation(doc, new_stableRef)
sf0 = el1.GetGeometryObjectFromReference(n_ref)
sf1 = sf0.ToProtoType()
#
elif isinstance(el1, FamilyInstance):
tf1 = el1.GetTotalTransform().ToCoordinateSystem()
sf1 = sf0.Convert(ref, tf1)
else:
tf1 = Transform.Identity.ToCoordinateSystem()
sf1 = sf0.Convert(ref, tf1)
#
for i in sf1:
refo = i.Tags.LookupTag("RevitFaceReference")
if refo is None and n_ref is not None:
i.Tags.AddTag("RevitFaceReference", n_ref)
elif refo is None and ref is not None:
i.Tags.AddTag("RevitFaceReference", ref)
else:
pass
surfaces.append(output1(sf1) )
gpoints.append(ref.GlobalPoint.ToPoint(True) )
#
OUT = output1(surfaces), output1(gpoints)
Hi,
there are probably one or more nodes closing and opening new transactions, try freezing the nodes one by one (starting from the end of the dynamo script) to identify the culprit
@c.poupin sorry your code is not culprit. its the Wall.ByProfile (WombatDynamo v.2.3.5)
I still haven’t figured out the solution. Is there any node or code that can wrap previous commands into a single command?