FilteredElementCollector that only select items that were created in current view's phase.

FilteredElementCollector that only select items that were created in current view's phase.

TWhitehead_HED
Contributor Contributor
603 Views
2 Replies
Message 1 of 3

FilteredElementCollector that only select items that were created in current view's phase.

TWhitehead_HED
Contributor
Contributor

I've tried this a couple of different ways but none seem to do what I'm wanting (honestly all of the phase filtering I've tried seems to do nothing).  

 

Given this code to gather the phase of the current active view. 

Application app = commandData.Application.Application;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document; 

//variables we need 
Autodesk.Revit.DB.View currentView = doc.ActiveView;
//to find out what things are 'new' we have to get the phase of the view.  
Parameter phaseParam = currentView.get_Parameter(BuiltInParameter.VIEW_PHASE); //get the parameter from the view
ElementId phaseID = phaseParam.AsElementId(); //what is that id
Phase phase = doc.GetElement(phaseID) as Phase; //ok get the Phase of that thing
string phaseName = phase.Name; //now set this string to that. 

 

I'm using this code to get a list of the doors that are created in the same phase as the active view:

public static List<FamilyInstance> GetParentDoorsPhase(Document doc, ElementId phaseID)
        {
            //ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_CREATED));
            //FilterElementIdRule rule = new FilterElementIdRule(pvp,new FilterNumericEquals(), phaseID);
            //ElementParameterFilter filter = new ElementParameterFilter(rule);
            
            List<FamilyInstance> ret = new FilteredElementCollector(doc, doc.ActiveView.Id)
                        .OfCategory(BuiltInCategory.OST_Doors) //get all the doors 
                        .OfClass(typeof(FamilyInstance)) //just the instances
                        //.WherePasses(filter)
                        .Cast<FamilyInstance>()
                        .Where(q => q.Symbol.FamilyName.StartsWith("DOOR_") && q.CreatedPhaseId == phaseID) //where the family name starts with "DOOR_"
                        .ToList(); //turn this collector into a list
            return ret;
        }

But in testing, it returns a list of all doors in the view that start with "DOOR_".  I've also attempted using a ElementParameterFilter that didn't appear to filter out items based on phase.  

 

Any useful help would be greatly appreciated.  As you can tell based on all the comments in my code, this isn't my normal skillset.  

 

Tom 

0 Likes
Accepted solutions (1)
604 Views
2 Replies
Replies (2)
Message 2 of 3

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi @TWhitehead_HED ,

 

Code runs fine here (Revit 2022)

Tested with 7 doors (3 DOOR_ families in view's Phase, 2 DOOR_ families in previous phase and 2 other doors) in planview. Selects the 3 DOOR_ families of the view's Phase.

 

only added this after the first code block:

 List<FamilyInstance> Testlist = GetParentDoorsPhase(doc, phaseID);

 

- Michel

0 Likes
Message 3 of 3

TWhitehead_HED
Contributor
Contributor

Thanks @TripleM-Dev.net , you're right.  I just hadn't invoked the code in plug-in.  As barely a novice I'm more likely to assume my code isn't working as opposed to a dumb mistake (like calling the wrong chunk of code).  

 

Thanks again for verification.  

0 Likes