PickObjects method PreSelected Argument

PickObjects method PreSelected Argument

Anonymous
Not applicable
1,224 Views
4 Replies
Message 1 of 5

PickObjects method PreSelected Argument

Anonymous
Not applicable

I'm trying to use the PickObjects method overload with the form...

public IList<Reference> PickObjects(
	ObjectType objectType,
	ISelectionFilter selectionFilter,
	string statusPrompt,
	IList<Reference> pPreSelected
)

The last argument "pPreSelected" appears to be used for pre-selecting elements in the active view. However its not clear what kind of references are required for this method. For example I want to pre-select some walls that I obtained through a FilteredElementCollector, but there isn't exactly a GetReference() method for the Wall class. I tried getting a reference from the wall geometry from the method below but the PickObjects method did not pre-select anything.

 

Any ideas? 

Thank you

   public static Reference GetWallReference(this Wall wall)
        {
            var AllReferences = new List<Reference>();
            var geoinst = wall.get_Geometry(NewOptions())
                .FirstOrDefault() as GeometryInstance;
            foreach (object item in geoinst.GetInstanceGeometry())
            {
                if (item is Solid)
                {
                    foreach (PlanarFace face in (item as Solid).Faces)
                    {
                        AllReferences.Add(face.Reference);
                    }
                    foreach (Edge edge in (item as Solid).Edges)
                    {
                        AllReferences.Add(edge.Reference);
                    }
                }
                else if (item is Autodesk.Revit.DB.Line)
                {
                    AllReferences.Add((item as Autodesk.Revit.DB.Line).Reference);
                }
            }
            return AllReferences
                .FirstOrDefault(refer => 
                refer.ElementReferenceType
                .Equals(ElementReferenceType.REFERENCE_TYPE_NONE) );
        }

 

 

0 Likes
Accepted solutions (1)
1,225 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Using the PickObject method...

public Reference PickObject(
	ObjectType objectType
)

I was able to pass the reference into the aforementioned PickObjects method and it worked to pre-select a element.  How can I obtain this same reference from a FilteredElementCollector? Or is it not possible?

0 Likes
Message 3 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous ,

From my understanding, when you already have some pre-selected elements in IList<Reference> R1 then you can add those R1 elements to IList<Reference> R2  in addition to elements that can be added to R2 using ISelectionFilter.

 

 

//Filter walls and get the element Ids of the walls and those are the Pre selected element ids
IList<ElementId> preSelectedElementIds =new IList<ElementId>();

//get reference from the preselectedelementid and add it to the IList<Reference> R1 IList<Reference> R1 = new List<Reference>(); foreach(ElementId eid in preSelectedElementIds) { Element e = doc.GetElement(eid); Reference R = new Reference(e); R1.Add(R); } //Create selectionFilter to select only certain type of element you want and pass it to PickObjects.
//So in R2 the total count of elements will be the additional of preselected elements and the number of elements you are going to select using selection filter
selFilter selF = new selFilter(); IList<Reference> R2 = uidoc.Selection.PickObjects(ObjectType.Element,selF, "SELECT ELEMENTS",R1);

I hope this helps.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

 

Prompts the user to select multiple objects which pass a custom filter while showing a custom status prompt string. A preselected set of objects may be supplied and will be selected at the start of the selection.

 

when you have two separate IList<Reference> R1 and IList<Reference> R2, then 

PickObjects Method (ObjectType, ISelectionFilter, String, IList(Reference))

 

helps you to add elements in R1 to R2 in addition to elements that can be selected by R2.

So R2 contains elements from both R1 and R2.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

Anonymous
Not applicable
Reference R = new Reference(e);

Simple. Works beautifully, thank you!

0 Likes