This message can be aborted, which stops the whole script from running. When I press “delete” my objects are gone.
Is there a way to “test” if a cut of the objects is possible, before really cutting it? This would be a much cleaner workflow, because I could just spit out a popup telling that, for example, 5 cutouts won´t work, instead of deleting them and getting them back from a backup file…
The “SolidSolidCutUtils” have a method called “CanElementCutElement”.
Unfortunately I have to use the InstanceVoidCutUtils.AddInstanceVoidCut(doc,item1,item2). This does not seem anything like “CanElementCutElement”.
Currently, I run the InstanceVoidCutUtils.AddInstanceVoidCut(doc,item1,item2) and when it fails there is a revit popup.
When I press cancel it aborts the whole process.
When I press “Delete Instances” my script goes on working, but the objects are gone. Is there any way to get the ids from this popup and rollback the deletion or anything alike?
Hi Kulkul,
thanks for asking. Next time, I will provide the file straight away… I got a solution now, which works quite ok now. I start a Transaction for every single object and cancel it when it fails. When finished I look if Element 1 is cut with Element 2. If it´s not, I add it to a list, so I can use it later to figure out what the problem is.
Before I had all objects in one transaction. When aborting this one, all other cuts were rolled back as well.
Is there a better way to reach what I got now?
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
from Autodesk.Revit import DB
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import traceback
doc = DocumentManager.Instance.CurrentDBDocument
items1 = UnwrapElement(IN[0])
items2 = UnwrapElement(IN[1])
cuttingElements = IN[1]
log = []
errorElements = []
errorLog = []
def cut_geometry(doc, item1, item2, transaction_name, cutElement):
t = DB.Transaction(doc, transaction_name)
try:
t.Commit()
except:
pass
try:
t.Start()
InstanceVoidCutUtils.AddInstanceVoidCut(doc, item1, item2)
t.Commit()
except:
try:
errorLog.append(traceback.format_exc())
t.Dispose()
except:
errorLog.append("Dispose failed")
pass
def is_element_cut(item1, item2):
isCut = InstanceVoidCutUtils.InstanceVoidCutExists(item1, item2)
if isCut == False:
errorElements.append(item2)
return isCut
cutObjects = []
counter = 0
for x, y, cutE in zip(items1, items2, cuttingElements):
cutObjects.append(cut_geometry(doc, x, y, str(counter), cutE))
log.append(is_element_cut(x, y))
counter += 1
OUT = errorElements,log,errorLog