filter elements after selection

filter elements after selection

Anonymous
Not applicable
3,531 Views
4 Replies
Message 1 of 5

filter elements after selection

Anonymous
Not applicable

hello again,

 

This  is my first post in this forum

 

 

well,my problem is:

 

How I can filter elemet after selection?

 

IList<Element> pickedElements = uidoc.Selection.PickElementsByRectangle("Made rectangle");

 if (pickedElements.Count > 0)
                {

                    Lista_idElement = new List<string>();
          
                    foreach (Element element in pickedElements)

                    {
                        if (element is Wall)
                        {

                            { TaskDialog.Show("Revit", " wall"); }



                            // get ElementType
                            ElementId id = element.GetTypeId();
                            // get Element_id (idElement variable definida al principio)
                            idElement = element.Id.ToString();
                            // get type element ( type variable definida al principio)
                            tipo_elemento = doc.GetElement(element.GetTypeId()) as ElementType;




                            Lista_idElement.Add(idElement);
                            Lista_tipo_elemento.Add(tipo_elemento.ToString());

                            // get the builtin parameter

                            Parameter param_codigo = tipo_elemento.get_Parameter(BuiltInParameter.KEYNOTE_PARAM);
                            Parameter param_C1 = tipo_elemento.LookupParameter("C1");

                            paramametro_C1 = param_C1.AsString();

                           
                            parametro_codigo = param_codigo.AsString();


                            Lista_codigo.Add(parametro_codigo);


                            Lista_C1.Add(param_C1.ToString());

                        } 

                        else
                        { TaskDialog.Show("Revit", "No is wall"); }

                        }

With this code when i do the rectangle selection add to list "Lista_tipo_elemento" all the element ,not only the wall.

 

i look for some like....

 

foreach (Element element in pickedElements)

                    {
                        if (element is Wall)
                        {......make list of wall........}

if (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows)
{..........make list of windows........}

thanks¡¡¡

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

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Andrese,

 

I would completely separate the picking from all further operations.

 

Encapsulating it in a separate method might help, e.g.:

 

  List<ElementId> PickWalls()
  {
    // pick the walls
    PickElementsByRectangle ...
    return ...
  }

You can also add a selection filter argument to the pick method to limit the elements that can be picked to certain specific type.

 

The filter can use any criteria you like.

 

By the way, as a newbie, have you worked through the getting started material yet?

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

That can save you and the rest of the universe a bunch of questions...

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5

Anonymous
Not applicable

yeah¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ thanks¡¡¡¡¡¡¡¡¡¡¡

 

 

  IList<Element> pickedElements = uidoc.Selection.PickElementsByRectangle("Select by rectangle");
    
                if (pickedElements.Count > 0)
                {

                    foreach (Element element in pickedElements)

                    {
                        if (element is Wall)

                        { PickWalls.Add(element); 

                        }

                        if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows)
                            {
                            PickWindows.Add(element);
                        }
                    }

                    if (PickWalls.Count > 0)

                    {
                        foreach (Element muro in PickWalls)

                        {
                            ElementId id = muro.GetTypeId();
                           
					....get all the information...
                            
   
                        }

                    }


                    if (PickWindows.Count > 0)

                    {
                        foreach (Element ventana in PickWindows)

                        {

                            ElementId id = ventana.GetTypeId();
                            ....get all the information...
                        }


                    }

Thank you !!!!!!!

 

and thanks for the link of getting started material

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk

Thank you for the appreciation.

 

Glad it helped.

 

In your call to the pick method, you can still add a selection filter as well:

 

http://www.revitapidocs.com/2017/d552f44b-221c-0ecd-d001-41a5099b2f9f.htm

 

That would simplify the picking interaction for the user and guarantee that you receive nothing but wall and window elements.

 

http://www.revitapidocs.com/2017/9c967926-c396-6e6b-97a2-b6882d71b69e.htm

 

  bool AllowElement(Element e )
  {
    return e is Wall 
      || (null != e.Category && e.Category.Id.IntegerValue == ...
  }

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5

Anonymous
Not applicable

thanks!!!

 

i continuos learning....

0 Likes