Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rudderdon/6dde4c574146190a428e5c4478199f08 to your computer and use it in GitHub Desktop.
Save rudderdon/6dde4c574146190a428e5c4478199f08 to your computer and use it in GitHub Desktop.
Revit addin code to find and remove elevation marker tags that have no views associated to it
[Transaction(TransactionMode.Manual)]
public class CmdMain : IExternalCommand
{
/// <summary>
/// Command
/// </summary>
/// <param name="commandData"></param>
/// <param name="message"></param>
/// <param name="elements"></param>
/// <returns></returns>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document m_doc = commandData.Application.ActiveUIDocument.Document;
int m_cnt = 0;
IEnumerable<ElevationMarker> m_elem = from e in new FilteredElementCollector(m_doc)
.WhereElementIsNotElementType().OfClass(typeof (ElevationMarker))
let em = e as ElevationMarker
where em.HasElevations() == false
select em;
using (Transaction t = new Transaction(m_doc))
{
if (t.Start("Delete Empty Elevation Marker Tags") == TransactionStatus.Started)
{
foreach (var x in m_elem.ToList())
{
m_doc.Delete(x.Id);
m_cnt++;
}
t.Commit();
}
}
// Results
clsUtility.ShowTaskDialog(
"Results",
"Deleted Elevation Markers",
string.Format("Removed {0} Empty Elevation Marker Tags", m_cnt));
return Result.Succeeded;
}
catch (Exception ex)
{
clsUtility.ShowTaskDialog(
"Failure",
"Deleting Elevation Markers",
string.Format("Failed: \n{0}", ex));
return Result.Cancelled;
}
}
}
/// <summary>
/// Quick basic task dialog
/// </summary>
/// <param name="titleText"></param>
/// <param name="largeText"></param>
/// <param name="smallText"></param>
internal static void ShowTaskDialog(string titleText, string largeText, string smallText)
{
using (TaskDialog td = new TaskDialog(titleText))
{
td.CommonButtons = TaskDialogCommonButtons.Ok;
td.DefaultButton = TaskDialogResult.Ok;
td.TitleAutoPrefix = false;
td.MainInstruction = largeText;
td.MainContent = smallText;
td.Show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment