Macro gives an error on 2nd run

Macro gives an error on 2nd run

stever66
Advisor Advisor
493 Views
1 Reply
Message 1 of 2

Macro gives an error on 2nd run

stever66
Advisor
Advisor

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?

 

 

0 Likes
494 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Where is selectedIds declared? What's the code for that look like?
0 Likes