RevitLookup Search by Element and Unique Id

Александр Пекшев aka Modis @Pekshev recently submitted a pull request to snoop the stable representation of references for RevitLookup.

Now he implemented another useful enhancement to search and snoop elements by element id or unique id:

Search and Snoop by Element Id or Unique Id

Alexander's RevitLookup pull request #42 adds a 'search by and snoop' command:

Add "Search by and snoop" command that allows you to search and snoop for elements by condition:

Search and Snoop command

A small addition to the project: search for items by ElementId or UniqueId and then snoop them.

Search options implemented in the form of a drop-down list provide for the possibility of further future expansion (for example, search by parameters or something similar):

Search and Snoop form

This view option can be useful for developers who receive an ElementId while debugging an application and need to learn about it later in Revit.

Thank you very much, Alexander, for this great functionality added with minimal implementation effort, as you can see by looking and the pull request files changed.

File Changes

Besides the module RevitLookup\CS\Snoop\Forms\SearchBy.cs defining the new form, the only changes are the following to add the new menu entry and implement the new external command:

In App.cs:

  optionsBtn.AddPushButton(new PushButtonData(
    "Search and Snoop...""Search and Snoop...", 
    ExecutingAssemblyPath, "
    RevitLookup.CmdSearchBy"));

In TestCmds.cs:

using RevitLookup.Snoop.Forms;

. . .

/// <summary>
/// Search by and Snoop command: Browse 
/// elements found by the condition
/// </summary>
[TransactionTransactionMode.Manual )]
[RegenerationRegenerationOption.Manual )]
public class CmdSearchBy : IExternalCommand
{
  public Result Execute(
    ExternalCommandData cmdData,
    ref string msg,
    ElementSet elems )
  {
    Result result;

    try
    {
      Snoop.CollectorExts.CollectorExt.m_app = cmdData.Application;
      UIDocument revitDoc = cmdData.Application.ActiveUIDocument;
      Document dbdoc = revitDoc.Document;
      Snoop.CollectorExts.CollectorExt.m_activeDoc = dbdoc; // TBD: see note in CollectorExt.cs

      SearchBy searchByWin = new SearchBy( dbdoc );
      ActiveDoc.UIApp = cmdData.Application;
      searchByWin.ShowDialog();
      result = Result.Succeeded;
    }
    catch( System.Exception e )
    {
      msg = e.Message;
      result = Result.Failed;
    }

    return result;
  }
}

The Built-in Select by Id Command, Zoom To and StringSearch

Revit does already provide a built-in command that you should be aware of providing similar functionality, at least for selecting an element by element id: Manage > Inquiry > Select by ID > Show:

Select by ID command

It prompts you to enter the element id and adds the element to the current selection with the option to zoom to it graphically as well:

Select by ID form

Once you have selected an element in this manner, you can use the traditional RevitLookup 'snoop current selection' to explore its data.

The 'zoom to' option is very similar to the zoom to selected elements functionality discussed last week, implemented using ShowElements.

This could obviously be integrated into RevitLookup as well, if so desired.

Another useful piece of functionality that could be integrated is an adaptation of my old StringSearch add-in, originally ADN Plugin of the Month back in 2011.

It implements the possibility to search for, list modelessly, select and zoom to elements based on strings in their properties, parameters and other data, including support for regular expressions.

RevitLookup Update

Back to here and now, though.

I integrated Alexander's code and fixed some minor compilation errors due to working with Visual Studio 2015.

He presumably used a newer version supporting more permissive C# syntax to create the pull request.

The new functionality is included in RevitLookup release 2018.0.0.8.