Get access to Revit Project Browser tree via Win32 api calls

Get access to Revit Project Browser tree via Win32 api calls

ebrown1029
Explorer Explorer
960 Views
1 Reply
Message 1 of 2

Get access to Revit Project Browser tree via Win32 api calls

ebrown1029
Explorer
Explorer

Trying to get access to the Revit Project Browser tree. so I can traverse and act on desired tree nodes. Using Spy++ to get class id as highlighted below. Then trying to SendCommand to get the root of the tree.... its returning 0; I also tried the SendCommandOn the parent window and it also failed.

 

Can anyone help?

 

 

ProjectBrowserSpy.png

 

The treeRoot variable in line:

 

int treeRoot = SendMessage((int)hWnd, TVM_GETNEXTITEM, TVGN_ROOT, IntPtr.Zero);" 

 

below is returning 0;

 

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)

{

  Process[] processes = Process.GetProcessesByName("Revit");

  if (0 < processes.Length)

    { 

     IntPtr mainWindowHandle = processes[0].MainWindowHandle;

     EnumChildWindows(mainWindowHandle, winEnumCallBack, IntPtr.Zero);

     }

   return Result.Succeeded;

}

 

 

static bool winEnumCallBack(IntPtr hWnd, IntPtr lParam)

{

   StringBuilder className = new StringBuilder(100);

   IntPtr result = GetClassName(hWnd, className, className.Capacity);

   if (className.ToString() == "Afx:0000000140000000:b:0000000000010003:0000000000000006")

      {

      int treeRoot = SendMessage((int)hWnd, TVM_GETNEXTITEM, TVGN_ROOT, IntPtr.Zero);

// treeRoot returning 0 - Help !!!!!

      }

   return true;

}

 

0 Likes
961 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Dear Ebrown,

 

Thank you for your query.

 

Yes, the project browser window and its tree view appear to be non-trivial to find.

 

I am appending a screen snapshot of what I see in Spy++.

 

Based on that, I would search all Revit child windows whose caption begins with "Project Browser - ".

 

I would ignore the window class name if that does not lead to the desired result.

 

I hope this helps.

 

Best regards,

 

Jeremy

 

project_browser_spy_02.png

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes