filter or analyze selection

matt.johnson1253
Explorer

filter or analyze selection

matt.johnson1253
Explorer
Explorer

Hello all, I have a rather basic question.

 

I am creating a plugin where the user is prompted to select an element.  I want them to select a Model Line.  

 

1. Is there a way to filter the selection.PickObject() function so that only model lines are selectable?

 

2. How can I find out if a given element is a Model Line or not?  I can't tell from the API docs if that's a Category, Family, Type or something else.  

 

Thanks for any insights.  

0 Likes
Reply
142 Views
1 Reply
Reply (1)

Mohamed_Arshad
Advisor
Advisor

HI @matt.johnson1253 
  

   You can use ISelectionFilter Interface this will helps you select only Defined Element in your Model Line. Kindly Check the Below code Implementation.

 

Reference Code:

 

public Result Execute(ExternalCommandData commandData, ref string msg, ElementSet elements)
        {

            UIApplication uiApp = commandData.Application;
            Application app = uiApp.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;

           Reference refer= uiDoc.Selection.PickObject(ObjectType.Element, new SelectionFilter());

            if(refer !=null)
            {
                ModelCurve curve = doc.GetElement(refer) as ModelCurve;
            }
}




    public class SelectionFilter : ISelectionFilter
    {
        public bool AllowElement(Element elem)
        {
            bool result = false;

           if(elem is ModelCurve)
            {
                result = true;
            }

            return result;
        }

        public bool AllowReference(Reference reference, XYZ position)
        {
            return true;
        }
    }

 

Additional Links:

https://spiderinnet.typepad.com/blog/2011/04/implement-the-iselectionfilter-interface-of-revit-api.h... 

 

 

Hope this will helps 🙂

Thanks & Regards,
Mohamed Arshad K
0 Likes