Message 1 of 5
Adding custom forms to the Project Browser window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good afternoon.
I need to add a grid with button to the project browser window under the heading. Is there any way to implement this? I tried to do this:
using System;
using System.Reflection;
using System.IO;
using System.Windows.Forms;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace ProjectManagerModification
{
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class ModificationProjectManagerCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var uiApp = commandData.Application;
var uiDoc = uiApp.ActiveUIDocument;
IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
//Process[] processes = Process.GetProcesses();
//var targetProcess = processes.FirstOrDefault(p => p.MainWindowTitle.Contains("Revit"));
if (mainWindowHandle != IntPtr.Zero)
{
FindSubWindow(uiApp, mainWindowHandle);
}
return Result.Succeeded;
}
[DllImport("user32.dll")]
private static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
public static void FindSubWindow(Autodesk.Revit.UI.UIApplication uiApp, IntPtr mainWindowHandle)
{
EnumChildWindows(mainWindowHandle, (hWnd, lParam) =>
{
StringBuilder sb = new StringBuilder(256);
GetWindowText(hWnd, sb, sb.Capacity);
if (sb.ToString().Contains("Project Browser"))
{
System.Windows.Forms.MessageBox.Show("Find subwindow with title: " + sb.ToString());
System.Windows.Forms.Panel panel = new System.Windows.Forms.Panel();
panel.Dock = DockStyle.Fill;
System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
textBox.Text = "Text example";
textBox.Dock = DockStyle.Fill;
panel.Controls.Add(textBox);
System.Windows.Forms.Form subWindow = System.Windows.Forms.Form.FromHandle(hWnd) as System.Windows.Forms.Form;
subWindow.Controls.Add(panel);
subWindow.Controls.SetChildIndex(panel, 0);
return false;
}
return true;
}, IntPtr.Zero);
}
}
}
The idea is to add a panel with a button under the title of the project Manager window, clicking on which will open a window with filters to hide TreeView elements in the project browser.
Perhaps Windows Forms are not suitable for this window.