Results 1 to 3 of 3

Thread: Code to filter the number of element from selection

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2014-12
    Posts
    1
    Login to Give a bone
    0

    Default Code to filter the number of element from selection

    I'm beginner of revit API. I am going to create a code to determine the number of element from the selection in active view. The below is the code for the wall but I don't know how to determine the number of beam or column. It's relate to classes or family instance.

    I hope everyone can show me the way to make it. Thanks all!!

    Code:
    public void alex01()
    {
    UIDocument uidoc= ActiveUIDocument;
    Autodesk.Revit.UI.Selection.SelElementSet collection= uidoc.Selection.Elements;
    TaskDialog.Show("Revit","Number of selected elements : " + collection.Size.ToString());
    SelElementSet abcd = SelElementSet.Create();
    SelElementSet none = SelElementSet.Create();
    foreach(Autodesk.Revit.DB.Element elements in collection)
    {
    if(elements is Wall)
    {
    abcd.Add(elements);
    }
      }
     uidoc.Selection.Elements = abcd;
    if(0!=abcd.Size)
    {
    TaskDialog.Show("revit",uidoc.Selection.Elements.Size.ToString()+" walls are selected");
    
    }
    else
    {
    TaskDialog.Show("revit","no walls have been selected!!");
    }
    uidoc.Selection.Elements= none;
    }
    Last edited by Wanderer; 2014-12-26 at 03:47 PM. Reason: added code tags

  2. #2
    Mod / Salary / SM Wanderer's Avatar
    Join Date
    2001-12
    Location
    St. Louis
    Posts
    5,408
    Login to Give a bone
    0

    Default Re: Code to filter the number of element from selection

    Quote Originally Posted by alexhung91687250 View Post
    I'm beginner of revit API. I am going to create a code to determine the number of element from the selection in active view. The below is the code for the wall but I don't know how to determine the number of beam or column. It's relate to classes or family instance.

    I hope everyone can show me the way to make it. Thanks all!!

    Code:
    public void alex01()
    {
    UIDocument uidoc= ActiveUIDocument;
    Autodesk.Revit.UI.Selection.SelElementSet collection= uidoc.Selection.Elements;
    TaskDialog.Show("Revit","Number of selected elements : " + collection.Size.ToString());
    SelElementSet abcd = SelElementSet.Create();
    SelElementSet none = SelElementSet.Create();
    foreach(Autodesk.Revit.DB.Element elements in collection)
    {
    if(elements is Wall)
    {
    abcd.Add(elements);
    }
      }
     uidoc.Selection.Elements = abcd;
    if(0!=abcd.Size)
    {
    TaskDialog.Show("revit",uidoc.Selection.Elements.Size.ToString()+" walls are selected");
    
    }
    else
    {
    TaskDialog.Show("revit","no walls have been selected!!");
    }
    uidoc.Selection.Elements= none;
    }
    Hi there, I'm going to move this from the Dot Net API forum in the programming area, over to the Revit - API forum in the Revit area, as I think it might be better served there. Cheers!
    Melanie Stone
    @MistresDorkness

    Archibus, FMS/FMInteract and AutoCAD Expert (I use BricsCAD, Revit, Tandem, and Planon, too)
    Technical Editor
    not all those who wander are lost

  3. #3
    Active Member
    Join Date
    2015-10
    Location
    Escondido, CA
    Posts
    91
    Login to Give a bone
    0

    Default Re: Code to filter the number of element from selection

    Beams and columns are represented in the Revit API by the FamilyInstance class. You can use the StructuralType property of the FamilyInstance class to determine whether the FamilyInstance is a beam, column, or something else. Below is one way you could modify your method to find the number of selected beams, columns and braces.

    Code:
    public void alex01()
            {
                UIDocument uidoc = ActiveUIDocument;
                Autodesk.Revit.UI.Selection.SelElementSet collection = uidoc.Selection.Elements;
                TaskDialog.Show("Revit", "Number of selected elements : " + collection.Size.ToString());
                SelElementSet abcd = SelElementSet.Create();
                SelElementSet none = SelElementSet.Create();
                int numBeams = 0, numCols = 0, numBraces = 0;
                foreach (Autodesk.Revit.DB.Element elements in collection)
                {
                    if (elements is Wall)
                    {
                        abcd.Add(elements);
                    }
    
                    if (elements is FamilyInstance)
                    {
                        FamilyInstance instance = elements as FamilyInstance;
                        switch (instance.StructuralType)
                        {
                            case Autodesk.Revit.DB.Structure.StructuralType.Beam:
                                numBeams++;
                                break;
                            case Autodesk.Revit.DB.Structure.StructuralType.Brace:
                                numBraces++;
                                break;
                            case Autodesk.Revit.DB.Structure.StructuralType.Column:
                                numCols++;
                                break;
                            case Autodesk.Revit.DB.Structure.StructuralType.Footing:
                                break;
                            case Autodesk.Revit.DB.Structure.StructuralType.NonStructural:
                                break;
                            case Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming:
                                break;
                            default:
                                break;
                        }
                    }
                }
    
                TaskDialog.Show("Revit", String.Format("{0} beams selected, {1} columns selected, and {2} braces selected.", numBeams, numCols, numBraces));
                uidoc.Selection.Elements = abcd;
                if (0 != abcd.Size)
                {
                    TaskDialog.Show("revit", uidoc.Selection.Elements.Size.ToString() + " walls are selected");
    
                }
                else
                {
                    TaskDialog.Show("revit", "no walls have been selected!!");
                }
                uidoc.Selection.Elements = none;
            }
    By the way, the Selection.Elements property has been deprecated in Revit 2015 and you should use Selection.GetElementIds() to get the ids of the selected elements and Selection.SetElementIds() to change the selected elements.

Similar Threads

  1. Filter the selected element revit api 2011
    By rinu.bs in forum Revit - API
    Replies: 5
    Last Post: 2010-10-12, 12:11 PM
  2. parameter filter using level element id
    By Ning Zhou in forum Revit - API
    Replies: 2
    Last Post: 2010-01-28, 02:35 PM
  3. Filter by selection
    By dmb.100468 in forum Revit MEP - Wish List
    Replies: 0
    Last Post: 2007-01-25, 04:04 PM
  4. DXF code to filter on line length
    By rvanrooyen in forum VBA/COM Interop
    Replies: 3
    Last Post: 2005-09-01, 09:13 AM
  5. Selection Filter
    By amy.stuart in forum AutoCAD LT - General
    Replies: 1
    Last Post: 2005-07-24, 02:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •