Results 1 to 6 of 6

Thread: Finding all elements of a given ElementType

  1. #1
    Active Member
    Join Date
    2008-02
    Posts
    58
    Login to Give a bone
    0

    Default Finding all elements of a given ElementType

    I'm trying to gather all the Elements of a particular ElementType based on the type given. So for example If I'm given the WallType type in a generic class and I want the method to return a FilteredElementCollection of all the Wall objects in the document. Any idea how I might do this?

  2. #2
    All AUGI, all the time
    Join Date
    2006-08
    Posts
    636
    Login to Give a bone
    0

    Default Re: Finding all elements of a given ElementType

    something like below, not tested, let me know if not working.

    ElementClassFilter filter = new ElementClassFilter(typeof(Wall));
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    collector.WherePasses(filter);
    var query = from element in collector
    where (element as Wall).WallType == myWallType
    select element;
    List<Wall> myWalls = query.Cast<Wall>().ToList<Wall>();

  3. #3
    Active Member
    Join Date
    2008-02
    Posts
    58
    Login to Give a bone
    0

    Default Re: Finding all elements of a given ElementType

    Your suggestion won't work because I do not know the elements I'm looking for apriori. The trouble is in this line.
    Code:
    ElementClassFilter filter = new ElementClassFilter(typeof(Wall));
    I don't know that it's of type Wall, I only have the WallType type (not an instances of it).

  4. #4
    All AUGI, all the time
    Join Date
    2006-08
    Posts
    636
    Login to Give a bone
    0

    Default Re: Finding all elements of a given ElementType

    check for all cases like below, don't know if there's better method?

    // suppose et is ElementType
    WallType wt = et as WallType;
    if (wt != null) {
    ElementClassFilter filter = new ElementClassFilter(typeof(Wall));
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    collector.WherePasses(filter);
    var query = from element in collector
    where (element as Wall).WallType == myWallType
    select element;
    List<Wall> myWalls = query.Cast<Wall>().ToList<Wall>();
    }
    else {
    FloorType ft = et as FloorType;
    if (ft != null) {
    ...
    }
    }

  5. #5
    Active Member
    Join Date
    2008-02
    Posts
    58
    Login to Give a bone
    0

    Default Re: Finding all elements of a given ElementType

    Quote Originally Posted by joe.zhou View Post
    check for all cases like below, don't know if there's better method?
    This is exactly what I'm trying to avoid. I'd rather make the code modular so that in the future if additional ElementTypes are added to the API I don't have to update my code.

  6. #6
    Active Member
    Join Date
    2008-02
    Posts
    58
    Login to Give a bone
    0

    Default Re: Finding all elements of a given ElementType

    Ok I managed to get the functionality I wanted by using Categories. I took the first WallType in an iterator, then requested it's CategoryId and then use a WhereNotElementType and OfCategory methods on the filter to find the appropriate elements in the model.

Similar Threads

  1. Replies: 0
    Last Post: 2014-11-30, 01:16 PM
  2. 2013: Turning off elements in linked file also turns off elements in host model
    By GCIPRIANO in forum Revit MEP - General
    Replies: 2
    Last Post: 2013-07-21, 11:38 PM
  3. Elements in linked files obscure local elements
    By JoelB in forum Revit - Platform
    Replies: 5
    Last Post: 2010-11-15, 07:30 PM
  4. Show Elements that have Graphics Overrides Applied in Reveal Hidden Elements Mode
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2008-03-04, 04:06 PM
  5. Detail Lines are model elements, how about annotation elements?
    By scowsert in forum Revit Architecture - General
    Replies: 5
    Last Post: 2007-08-03, 07:08 PM

Posting Permissions

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