Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't get References for PickObjects method pre-selection

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
407 Views, 2 Replies

Can't get References for PickObjects method pre-selection

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!

2 REPLIES 2
Message 2 of 3
FAIR59
in reply to: Anonymous

try this:

 

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

Hi!

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report