Can't get References for PickObjects method pre-selection

Can't get References for PickObjects method pre-selection

Anonymous
Not applicable
519 Views
2 Replies
Message 1 of 3

Can't get References for PickObjects method pre-selection

Anonymous
Not applicable

I have a collection of areas, and want to prompt the user to select additional areas by using PickObjects method. Unfortunately, PickObjects only accepts a list of references, and I cannot find a way to get references to my areas. Thought this might work, but it throws an "object reference not set to an instance of an object" error:

 

        internal IList<Reference> getRefs(List<Area> areas)
        {
            IList<Reference> selected = new List<Reference>();
            try
            {                
                foreach (Area area in areas)
                {
                    selected.Add((area as Object)as Reference);
                }
                return selected;
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            return null;           
        }

This thread seemed like it might contain helpful info on a similar problem, but the answer in there did not work for me: https://forums.autodesk.com/t5/revit-api-forum/using-elements-selected-before-a-command-is-started/t...

 

Help would be greatly appreciated!

0 Likes
Accepted solutions (1)
520 Views
2 Replies
Replies (2)
Message 2 of 3

FAIR59
Advisor
Advisor
Accepted solution

try this:

 

 foreach (Area area in areas)
 {
 	selected.Add(Reference.ParseFromStableRepresentation(doc,area.UniqueId));
                }
Message 3 of 3

aignatovich
Advisor
Advisor

Hi!

 

Maybe a little simpler, just new Reference(area) instead of Reference.ParseFromStableRepresentation

0 Likes