Results 1 to 8 of 8

Thread: new element iterations

  1. #1
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default new element iterations

    I'm having a little trouble understanding how to replace filters. In order to collect all levels in the project I have (VB.NET):

    Dim doc As UIDocument = cd.Application.ActiveUIDocument
    Dim Col AsNew Autodesk.Revit.DB.FilteredElementCollector(doc.Document)
    Dim Lvls As ICollection(Of DB.Element) = Col.OfCategory(BuiltInCategory.OST_Levels)

    If i'm correct this gives me all the levels in the project. Second, I want to collect all of the objects in the project into a single set of elements and test if they are on a specified level. Do I need to do similar to above for each category? It also seemed like there was a suggestion in the changes and additions document that there was a way to filter directly for elements on a certain level, but I wasn't really understanding how it worked. Can anyone help me with this?

    fyi, I'm trying to update this command for 2011 and will be happy to share it when I get it working...
    Last edited by sfaust; 2010-05-04 at 04:10 PM. Reason: fix link

  2. #2
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default Re: new element iterations


    Ok, I'm having some issues with this. I realized one error is I have to add .toelements to the end to get this:

    Dim Lvls As ICollection(Of DB.Element) = Col.OfCategory(BuiltInCategory.OST_Levels).ToElements

    However, I am also trying to replace View.Elements and having issues. I have tried

    Dim eSet As ICollection(Of DB.Element) = collect.OwnedByView(ViewID).ToElements

    but that only gets me the detail components, etc. that are view specific. I need all the model elements visible in the current view ideally...

  3. #3
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default Re: new element iterations

    bueller...

  4. #4
    100 Club
    Join Date
    2007-10
    Location
    Brisbane
    Posts
    138
    Login to Give a bone
    0

    Default Re: new element iterations

    Hi Steve,


    Here's some code I've whipped up. I haven't tested it, but should work. The filtered element collector is confusing at first, but after a bit it becomes quite handy.

    ElementLevelFilter is what you are after, see Page 81 on the developers guide for some more info on the filters you can use.

    For the view.elements replacement, there is a constructor for FilteredElementCollector which you can supply an ID of a view that you want to restrict your search to. In my example, I just use the active view.

    The tricky part is that I believe you can't just run a filtered element collector without applying a filter to it, so you need to filter the elements somehow. Most of the time, this is fine, as you are looking for a particular type of element in the View so you should filter it down (rather than loop through - better for performance). But if you really want to loop over all of them, I'm not sure if there is an official way of doing it, but a trick I've used is to use a filter that excludes elements (ones which I know won't be in the list anyway).

    There is an ExclusionFilter class which you could use, but another way would be to use the WhereElementIsNotElementType method, which should be fine for what you are after (I think.. could be wrong) because element types are not likely to be in a view, rather the instances of those types will be.

    let me know if you have any questions or it doesn't work for you

    public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
    {

    Document doc = commandData.Application.ActiveUIDocument.Document;

    //Get all levels, can also do a category filter on OST_Levels I believe.
    FilteredElementCollector collector =
    new FilteredElementCollector(doc);

    ICollection<Element> levels = collector.OfClass(typeof(Level)).ToElements();
    foreach (Element level in levels)
    {
    //get all the elements in that level
    FilteredElementCollector levelElementCollector =
    new FilteredElementCollector(doc);
    ElementLevelFilter filter = new ElementLevelFilter(level.Id);
    levelElementCollector.WherePasses(filter);

    //final list
    ICollection<Element> elementsInLevel = levelElementCollector.ToElements();

    //do whatever with that list
    }


    //To get all elements in a certain view.
    FilteredElementCollector viewElementCollector = new FilteredElementCollector(doc, doc.ActiveView.Id);

    //then apply a filter to this collector to narrow the results down a bit.
    // I've not been sure about this part, as sometimes you may want ALL items in the view, in that case I've
    // done something like this:
    viewElementCollector.WhereElementIsNotElementType();
    ICollection<Element> elementsInView = viewElementCollector.ToElements();


    return Result.Succeeded;
    }

  5. #5
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default Re: new element iterations

    Ok, I think I get it (or at least closer). I'll mess around with my new knowledge tomorrow and see if I can get it . Thank you very much.

  6. #6
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default Re: new element iterations

    Ok, getting closer, but I need a bit more help I think. I got the elements to work with what you suggested (thank you) so that is working fine. The problem is that, as I discovered when I first created the command, workplane based elements don't have a level and are thus ignored by these filters, so I have to look for them another way. My first thought was to iterate project parameters the same way, look for the workplane parameter, and filter based on that being a certain value. This is the code I have:

    'Get the workplane parameter
    Dim ParmColl AsNew Autodesk.Revit.DB.FilteredElementCollector(ActiveUIDocument.Document)
    Dim Params As System.Collections.Generic.ICollection(Of Autodesk.Revit.DB.Parameter) = ParmColl.OfClass(GetType(Autodesk.Revit.DB.Parameter))
    Dim WPParam As Autodesk.Revit.DB.Parameter = Nothing
    ForEach p As Autodesk.Revit.DB.Parameter In Params
    If p.Definition.Name = "Work Plane"Then
    WPParam = p
    ExitFor
    EndIf
    Next
    'Get workplane based items
    Dim WPCollector AsNew Autodesk.Revit.DB.FilteredElementCollector(ActiveUIDocument.Document)
    Dim WPFilterRule As Autodesk.Revit.DB.FilterRule = Autodesk.Revit.DB.ParameterFilterRuleFactory.CreateEqualsRule(WPParam.Id, lvl.Name)
    Dim WPFilter AsNew Autodesk.Revit.DB.ElementParameterFilter(WPFilterRule)
    Dim WPSet As System.Collections.Generic.ICollection(Of Autodesk.Revit.DB.Element) = WPCollector.WherePasses(WPFilter).ToElements

    When I try to run it, it says:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Autodesk.Revit.Exceptions.ArgumentException: Input type is not a recognized API type
    Parameter name: type

    If I read that right it's an error in the GetType command, but I'm not sure what to do about it. Am I going about this the wrong way? The only other way I can think of is to get all model elements and iterate through, checking the workplane parameter...


  7. #7
    Active Member
    Join Date
    2005-09
    Posts
    69
    Login to Give a bone
    0

    Default Re: new element iterations

    Steve - sorry I havent got time to look at this more, but a couple of suggestions.

    A) Have you used the RevitLookup utility or debugging code to find the parameter you are looking for - is it one of the BuiltIn ones so you can use the ParameterValueProvider , ElementParameterFilter classes?

    B) If not, have you looked at using LINQ to post-process a filtered set. You should be able to use that to recover the parameter value using "Work Plane" and compare it - presumably the value will be the ElementId of the level, not the name.

  8. #8
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default Re: new element iterations

    Quote Originally Posted by david.bartliff View Post
    Steve - sorry I havent got time to look at this more, but a couple of suggestions.

    A) Have you used the RevitLookup utility or debugging code to find the parameter you are looking for - is it one of the BuiltIn ones so you can use the ParameterValueProvider , ElementParameterFilter classes?

    B) If not, have you looked at using LINQ to post-process a filtered set. You should be able to use that to recover the parameter value using "Work Plane" and compare it - presumably the value will be the ElementId of the level, not the name.
    Had not done these. Remember I'm a self taught novice not a pro . I haven't messed with the RevitLookup utility and I really don't know anything about LINQ but I will look at it. thank you so much for the suggestions.

Similar Threads

  1. 2015: "an element may not reference an element in another option..."
    By narlee in forum Revit Architecture - General
    Replies: 0
    Last Post: 2014-09-09, 06:19 PM
  2. 2012: Generating Random Iterations - CWL Panels
    By Limbatus in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2012-03-12, 07:07 PM
  3. Replies: 1
    Last Post: 2010-07-15, 08:43 PM
  4. Join a family element to a non-family element
    By adnama in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2009-11-08, 08:59 PM
  5. Structural Element may not be supported -- verify support for element
    By anthony.hoare in forum Revit Structure - General
    Replies: 0
    Last Post: 2007-06-27, 01:56 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
  •