Filter Non-Hosting Reference Planes

revit
python

#1

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.

http://www.revitapidocs.com/2016/ac600729-3355-2dcf-3663-79b569e51cfb.htm

A Link to API would be really great. Thanks


#2

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.


#3

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.


#4

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


#5

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)

USE MANUAL MODE ONLY

#Copyright(c) 2016, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
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 = [], []
	TransactionManager.Instance.EnsureInTransaction(doc)
	st = SubTransaction(doc)
	st.Start()
	for id in ids:
		try:
			del_id = doc.Delete(id)
			deleted.extend([d for d in del_id])
		except : failed.append(id)
	st.RollBack()
	TransactionManager.Instance.TransactionTaskDone()
	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
else:
	OUT = "Set confirm to True", "", ""

#6

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