Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66666

Using elements selected before a command is started

$
0
0

How can I turn a list of ElementId's into a list of References to selected elements??

 

I want my command to work so that if elements are selected when the command is started, it uses the selected elements.  If no elements are selected,  the program should prompt the user to select the elements.  I can't quite get this to work.  The only way I can find to get the pre-selected elements returns a list of ElementId's:

 

         ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();

 

But I need element references to run the rest of my code, like I get with the PickObjects method:

 

        IList<Reference> selected = new List<Reference>();

        selected = uidoc.Selection.PickObjects(ObjectType.Element, "Select keynotes");

 

Here is the portion of code I have so far, that works for the post-selected elements, but not preselected elements;

 

ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
IList<Reference> selected = new List<Reference>();


 if (0 == selectedIds.Count)
            {
               //If no elements selected, prompt the user to select some
                selected = uidoc.Selection.PickObjects(ObjectType.Element, "Select keynotes");

             }

//get the parameter "MyParameter" from the first element in "selected".

//Is there a way to do this using ElementId's?

Element pickedID = doc.GetElement(selected[0]);
Parameter myparam = pickedID.LookupParameter("MyParameter");

 

 


Viewing all articles
Browse latest Browse all 66666

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>