Filter Non-Hosting Reference Planes

Hi All,

I’m trying to filter non-hosting reference planes. I can’t seem to find anything in API but I know its possible because of here.

A Link to API would be really great. Thanks

According to the link you provided you will have to try and delete the workplane and see if a exception gets thrown. If you want to keep the reference plane, you will have to roll back the transaction afterwards.

Thanks for this. So after the exception gets thrown, I will know which reference planes have hosted elements. Can I rollback transaction in script or are you referring to a manual undo.

By script yes, take a look at at spring nodes and the delete node. Just add a subtransaction and roll it back again.

I did a quick test for you, all credit to @Dimitar_Venkov for the python script. I just added a sub transaction and made it return elements in stead of strings. I also filtered the planes without name first.

EDIT: Tested the script in Revit 2017 and it seems like you can delete Refrence Planes that are hosts without any warnings. Thus this method will not work.

ReferencePlanes.FilterHostingPlanes.dyn (5.8 KB)


#Copyright(c) 2016, Dimitar Venkov
# @5devene,

import clr
from Autodesk.Revit.DB import *

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

ids = [e.Id for e in UnwrapElement(tolist(IN[0]) )]

if IN[1]:
	deleted, failed = [], []
	st = SubTransaction(doc)
	for id in ids:
			del_id = doc.Delete(id)
			deleted.extend([d for d in del_id])
		except : failed.append(id)
	s = set(deleted)
	failed1 = [x for x in failed if x not in s]
	failedElements = [doc.GetElement(id) for id in failed1]
	deletedElements = [doc.GetElement(id) for id in deleted]
	OUT = deletedElements,failedElements
	OUT = "Set confirm to True", "", ""

Thank you for this. We needed a place to start to remove unnecessary reference planes in a project.