I've got a Macro I'm writing using the Sharp Develop Macro Editor (C# and Revit 2016).
It runs fine the first time after its built, but on the 2nd run it always results in an error. I've looked at all the variables, and everything seems to be the same on both runs.
The section of code is below, and the line in red always causes a "Object Reference not set to an instance of an object." on the second run and every run after that until the project is rebuilt.
foreach (ElementId Id in startingIds)
{
Element e = doc.GetElement(Id);
if(e.Category.Name.ToString() == "Generic Annotations")
{
selectedIds.Add(Id);
}
}//end foreach
The section of code starts with a collection of ElementId's that the user has selected (startingIds). It then adds all the Id's for generic annotations to a another collection - selectedIds. So the basic idea is to omit anything from the selection that isn't a generic annotation.
Any ideas on why I'm getting an error message?