# Each execution registers as a single undo action

**URL:** <https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044>\
**Category:** Revit\
**Tags:** revit, python, dynamo\
**Created:** [January 11, 2024, 9:22am UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044 "2024-01-11T09:22:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishalghuge2500](https://avatars.discourse-cdn.com/v4/letter/v/7ea924/32.png) [@vishalghuge2500](https://forum.dynamobim.com/u/vishalghuge2500)\
**Post date:** [January 11, 2024, 9:22am UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044/1 "2024-01-11T09:22:36Z")

</div>

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?

 ![Side Faces finish_2024-01-11_02-47-26](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/5/e5bf6fce6fdebd3fad23a81ce62ad504a5a5f4a2.png)  

  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/b/3bdf48bd1c050b4034806da7eb09736148c4ed16.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [January 11, 2024, 10:33am UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044/2 "2024-01-11T10:33:02Z")

</div>

@vishalghuge2500 ,

i solved this here very well! check it

> [@How to make a bulk-task to 1 by 1 task in dynamo by Transaktion?](https://forum.dynamobim.com/t/how-to-make-a-bulk-task-to-1-by-1-task-in-dynamo-by-transaktion/83215):
>
> Hello Dynos, i do very simple excercise put a string to comments. The task works well, but i want, that each filling is a task(strg+z)… import clr clr.AddReference('RevitAPI') from Autodesk.Revit.DB import \* from System.Collections.Generic import \* clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument app = DocumentManager.Instance.C…

you can “reverse” the issue passed on the topic… it seems to make a group transaction

KR

Andreas

---

<div class="post-metadata">

**Author:** ![bharat.minocha](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bharat.minocha/32/174524_2.png) [@bharat.minocha](https://forum.dynamobim.com/u/bharat.minocha)\
**Post date:** [January 11, 2024, 12:13pm UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044/3 "2024-01-11T12:13:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vishalghuge2500](https://avatars.discourse-cdn.com/v4/letter/v/7ea924/32.png) [@vishalghuge2500](https://forum.dynamobim.com/u/vishalghuge2500)\
**Post date:** [January 12, 2024, 4:24am UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044/4 "2024-01-12T04:24:02Z")

</div>

@Draxl_Andreas  
sorry I’m still leaning python scripting. I dont get your solution. please give it a try.

@c.poupin

```auto
#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)

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [January 12, 2024, 11:32pm UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044/5 "2024-01-12T23:32:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vishalghuge2500](https://avatars.discourse-cdn.com/v4/letter/v/7ea924/32.png) [@vishalghuge2500](https://forum.dynamobim.com/u/vishalghuge2500)\
**Post date:** [January 15, 2024, 4:35am UTC](https://forum.dynamobim.com/t/each-execution-registers-as-a-single-undo-action/97044/6 "2024-01-15T04:35:10Z")

</div>

@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?
