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.
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.
#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", "", ""