Selection Filter with User interaction

GaryOrrMBI
Collaborator

Selection Filter with User interaction

GaryOrrMBI
Collaborator
Collaborator

The pieces are there but...

What I would like to do is use the Revit.UI FilterDialog to allow the user to define the parameters and parameter values of objects of a given class to be applied to a selection set (Specifically NOT a View Filter) so they can then act upon the selected elements.

 

I have created a function that does the job but it's clunky and doesn't have all of the grouping, nor the ability to do and/or options so, while it serves better than nothing I would really love to replace my dialog with the much better existing FilterDialog (which already does everything that I would like to do).

The problem is that I can't find a way to use the FilterDialog without applying the results to a ParameterFilterElement which then can only be applied to a ViewFilter...

 

Is it possible to call the FilterDialog to create an active selection set from the results (given either a preselected group of objects to filter from, or a specific view to filter from, or from the database as a whole)?

 

-Gary

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Reply
Accepted solutions (1)
1,359 Views
4 Replies
Replies (4)

GaryOrrMBI
Collaborator
Collaborator

In truth this is something that the Revit developers should just write, might be easier (I added this to a similar suggestion on the wish list)...

Revit already has the pieces, we just need them expanded a bit in their usage:

GaryOrrMBI_0-1627043040710.png

 

To create something that works more like this (this thing isn't letting me add a screencast very well...):

 

 
 
 
 
Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes

AGGilliam
Collaborator
Collaborator
Accepted solution

It took a little bit of tinkering, but I was able to create a tool that allows you to select a bunch of elements and then filter that selection using the view filter dialog. You could also try searching for a particular filter if it's already been created or use a filtered element collector for the initial selection. Here's what I came up with:

            UIDocument uidoc = data.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            using (Transaction t = new Transaction(doc, "Filter"))
            {
                t.Start();

                // Grab initial selection
                List<Reference> sel = uidoc.Selection.PickObjects(ObjectType.Element).ToList();

                // Initiate view filter dialog
                FilterDialog dialog = new FilterDialog(doc, "Jambs");
                dialog.Show();

                // Grab the parameter filter you've just created
                ParameterFilterElement pfe = doc.GetElement(dialog.NewFilterId) as ParameterFilterElement;

                // Use the parameter filter to filter your current selection
                ElementFilter filter = pfe.GetElementFilter();
                List<ElementId> selection = new List<ElementId>();
                foreach (Reference r in sel)
                {
                    if (filter.PassesFilter(doc, r.ElementId))
                        selection.Add(r.ElementId);
                }
                uidoc.Selection.SetElementIds(selection);

                t.Commit();
            }

 

0 Likes

GaryOrrMBI
Collaborator
Collaborator

So it can be done. I'm so excited I might have to work this weekend to see if I can adopt it for my desires.

 

I thank you kindly

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)

GaryOrrMBI
Collaborator
Collaborator

I found myself making a couple of tweaks on these utilities and realized that I had never posted what I found while applying @AGGilliam 's solution so here it is:

It works well and is exactly what I asked for but there are a couple of small idiosyncrasies that need to be accounted for depending upon how a person might want to use such a tool. Myself, I'm using it as a fully dynamic selection filter (a replacement for the good ole AutoCAD selection filter that I always relied upon and have always been frustrated that Revit doesn't have (although they're soooo close to having it).

If I have items already selected when I launch it I can filter from that selection set, or choose to select everything from the current graphical view, or choose to select from the entire document.

The first tool that I had built (before AG provided their magic touch) is limited to selecting objects from one category at a time, and the Revit filter dialog overcomes that as well as providing much more robust and/or combinations for complicated arguments. The drawback to the Revit filter dialog is that the properties presented to select from are lists of all of the values for that property from within the entire document as opposed to my original functions within my custom dialog which stripped those properties down to what the selected entities actually have applied to them.

 

But, what the heck, Perhaps the Autodesk developers might get around to reading this, see how close they are to having a very useful tool, and go ahead and run with it.

 

In the meantime, I put together a Visual Studio 2019 solution that encompasses both versions for anyone that wants to play around with them. I'm not a programmer by any means, just someone that does what he can with the time allowed, so they could both stand a little cleaning up and optimizing. But you're welcome to what it is as it is. There are some comments in the code indicating some of the issues that were encountered. There is a version compiled for 2023 in the debug bin that you can load as is from the Add-In Manager.

 

-G

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)