String Search ADN Plugin of the Month

Best regards from Andalusia!

Leaving the beach in Nerja

Here is just a short note to point out that my first ADN Plugin of the Month has been published on Autodesk Labs: the November ADN Plugin of the Month is the

Revit String Search
.

Look at the developer notes at the end for reasons why you should take a look at this :)

String Search

Description

Search Revit project elements and their parameter values for a given string value.

Standard string search options can be specified to define how the string is matched, which Revit elements and which of their parameters are searched.

Results are presented in a modeless navigator form listing the search hits. Selecting a search hit zooms to and highlights the Revit element containing it.

System Requirements

This plugin has been tested with Revit Architecture 2011 and 2012, and requires the .NET Framework 3.5.

A pre-built version of the plug-in has been provided which works on both Revit 2011 and 2012, and on both the 32- and 64-bit Windows systems.

The source code has been provided as a Visual Studio 2008 C# project. It is not required to run the plugin.

Usage

In Revit, click “Add-Ins” > “String Search” panel > “String Search” to launch the command.

In the dialogue that appears, you can type in the search string in the ‘Find what’ text box.

Click ‘OK’. The command will search for the given string on all standard and user parameters of all elements in the current view.

All occurrences of the search string are listed in a data grid view in a modeless navigator dialogue. Double click on a row in the navigator to zoom to the element.

A log file of the search operation and its results is created in your temporary directory. To view the log file, right click on the search form and select ‘Display Log File’.

The string matching options and the elements and parameters to search can be modified as follows.

String Search form

Options

Category: Limit the search to elements belonging to a specific category. All other categories will be skipped. Specify an asterisk ‘*’ to search all categories. This is the default setting.

Parameter name: You can specify the name of a specific parameter to search in. All other parameters will be skipped. Specify an asterisk ‘*’ to search all parameters. This is the default setting.

Find options: Match case and match whole parameter limit the string pattern matching to more specific cases, i.e. the upper and lower case of each character must match, and the specified search string must match the entire parameter value.

Element selection: You can search the currently selected element set, all elements in the current view, or all elements in the entire project. The latter can be slow.

Instances versus Types and Symbols: You can specify whether to search in the BIM elements themselves, such as walls and family instances, or in the element types, such as wall types and family symbols. When searching element types, there is no way to limit the search to selected elements (because they cannot be selected) or to a view (because they are not displayed graphically). By default, all elements in the current view are searched. Searching types is not additional to instances, it is complementary. You can search either element types (derived from ElementType in the API) or instances, but not both at once.

Parameter selection: You can select whether only standard built-in Revit parameters are searched, or user-defined family and shared parameters, or both.

Advanced: You have the option of using a regular expression to specify the search string. This option is intended for users with advanced programming knowledge and is not suited for non-programmers. The .NET Regex library is used for this. For more detail about regular expression, please refer to the one of the available ‘cheat sheets’.

You can also search in BuiltInParameters, which are only visible through the Revit API. Again, this option is intended for users with advanced programming knowledge and is not suited for others. With this option, the parameter selection option is ignored and the ‘Parameter name’ setting switches to a list of all built-in parameters. Again, you can search in all of them using the asterisk ‘*’, or pick a specific one. Searching all built-in parameters across the entire project can be extremely slow.

Examples

To search for a string ‘abc’ in all parameter values of all elements in the current view, simply type in ‘abc’ as the search string and hit OK. If any occurrences are found, they are listed in the modeless navigator window. You can continue working in Revit as normal. If you double click an entry in the navigator, the Revit screen will zoom in to the selected element and highlight it.

To search for all structurally non-bearing walls, you might make use of the built-in parameter option as follows:

  • Enter the search string ‘Non-bearing’
  • Under Category, select Walls
  • Under Advanced, select ‘Search BuiltInParameters’
  • Under Built-in parameter, select WALL_STRUCTURAL_USAGE_TEXT_PARAM

Click OK and examine the results in the navigator.

Notes for Developers

  • Hopefully optimal interaction with modeless search result navigator, as described for the

    modeless loose connector navigator
    .

  • Neat external application implementation using built-in image resources.
  • Handling of duplicate built-in parameter enumeration values.
  • Identical source code for both Revit 2011 and 2012.

Comments

8 responses to “String Search ADN Plugin of the Month”

  1. Hi Jeremy,
    That’s a great plugin, thanks for sharing.
    Without wanting to sound ungrateful, I wanted to give feedback on a few things I tried which didn’t quite work out:
    1) I recently wanted to search for all lighting fixture tags showing a particular value. This add-in doesn’t do it because the value isn’t in a parameter of the lighting fixture tag. Is it even possible to modify the code to do this, i.e. find lighting fixture tags based on the values of parameters in the lighting fixtures they’re related to?
    2) The add-in doesn’t appear to search all parameters, e.g. I searched for the offset value of lighting fixtures but it couldn’t find them.
    3) It would be great to be able to make a selection set of the entire results list.

  2. best photo from your photo collection!

  3. Hi Jeremy:
    How can I use API to load the Keyboard Shortcut file(*.xml) or is there some methods to load this file automaticly?Could you give me some ideas?
    Thanks very much!
    guming.

  4. Dear Guming,
    Currently, I’m afraid the API does not provide direct support for loading the Keyboard Shortcut file.
    The only workaround I can think of is to simulate the user input to trigger this functionality, e.g. using UI Automation as described in
    http://thebuildingcoder.typepad.com/blog/automation
    or sending a keyboard shortcut like in
    http://thebuildingcoder.typepad.com/blog/2010/11/launching-a-revit-command.html
    Cheers, Jeremy.

  5. Dear C M,
    Thank you very much for your appreciation and feedback.
    1. The way the tool is currently designed, there is no way to search for objects of a specific type in a specific relationship to objects of another type which have certain values. I cannot really imagine how you would design a generic user interface for such a specification. It would be easily solvable by writing your own add-in, though, which is what I would suggest doing for such a case.
    2. True, it currently only searches for string values. I had originally implemented searching for all value data types, but my initial testers complained that the whole thing was too generic and hard to understand, so I simplified it by limiting the searches to strings. You could easily add floating point number support as well, though, and the stubs for that are all there in the code.
    3. That is a great suggestion and easily doable. Since you have the code, you can implement it yourself as well. I’ll put it on my todo list, though, in addition.
    Cheers, Jeremy.

  6. Thanks for the feedback Jeremy.
    1) It’s good to know this kind of relationship can be accessed.
    2) I hadn’t appreciated it was string only.
    3) Cool!

  7. Hi Jeremy:
    How can I use API to load the Keyboard Shortcut file(*.xml) or is there some methods to load this file automaticly?Could you give me some ideas?
    Thanks very much!
    guming.

  8. Thank you,Jeremy!
    Guming.

Leave a Reply to gumingCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading