bool DeleteIfNotHosting( ReferencePlane rp )
{
bool rc = false;
Document doc = rp.Document;
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Delete ReferencePlane "
+ ( ++_i ).ToString() );
// Deletion simply fails if the reference
// plane hosts anything. If so, the return
// value ids collection is null.
// In Revit 2014, in that case, the call
// throws an exception "ArgumentException:
// ElementId cannot be deleted."
try
{
ICollection<ElementId> ids = doc.Delete(
rp.Id );
tx.Commit();
rc = true;
}
catch( ArgumentException )
{
tx.RollBack();
}
}
return rc;
}