Wednesday, April 27, 2016

Delete Empty Elevation Marker Tags

It is pretty common for a model to end up with a bunch of abandoned elevation marker tags. There are a bunch of ways that this can happen and depending on how you have your elevation tag symbols defined can be difficult to find visually for removal.



One of the supreme beings that I used to work with at CASE built a means of doing this in Dynamo.

This is a simple routine that finds these and eradicates them from your model...


[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();
}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.