71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using System.Runtime.InteropServices;
|
|
using System.Windows;
|
|
|
|
using Autodesk.Revit.Attributes;
|
|
|
|
using Autodesk.Revit.DB;
|
|
|
|
using Autodesk.Revit.UI;
|
|
|
|
namespace ShrlAlgo.Addin.Test;
|
|
[Transaction(TransactionMode.Manual)]
|
|
[Regeneration(RegenerationOption.Manual)]
|
|
public class MonitorPickObject : IExternalCommand
|
|
{
|
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|
{
|
|
var uiApp = commandData.Application;
|
|
var uiDoc = uiApp.ActiveUIDocument;
|
|
var Doc = uiDoc.Document;
|
|
//GlobalMouseWatcher wather = new GlobalMouseWatcher();
|
|
try
|
|
{
|
|
var list = uiDoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, "");
|
|
if (list!=null)
|
|
{
|
|
MessageBox.Show(list.Count.ToString());
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
[DllImport("user32.dll", EntryPoint = "FindWindow")]
|
|
internal static extern IntPtr FindWindow(string ClassName, string WindowNamw);
|
|
[DllImport("user32.dll")]
|
|
internal static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);
|
|
internal const int WM_CLICK = 0x00f5;
|
|
[DllImport("user32")]
|
|
internal static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lparam);
|
|
internal delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);//回调函数
|
|
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
|
|
internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
|
[DllImport("user32.dll")]
|
|
internal static extern bool SetForegroundWindow(IntPtr hWnd); //设置窗体获得焦点
|
|
internal static IntPtr finish;
|
|
public static void SetOk()
|
|
{
|
|
var Revit = Autodesk.Windows.ComponentManager.ApplicationWindow;
|
|
if (Revit != IntPtr.Zero)
|
|
{
|
|
FindChildClassHwnd(Revit, IntPtr.Zero);
|
|
SendMessage(finish, WM_CLICK, IntPtr.Zero, 0);
|
|
}
|
|
}
|
|
|
|
private static bool FindChildClassHwnd(IntPtr hwndParent, IntPtr lParam)
|
|
{
|
|
var childProc = new EnumWindowProc(FindChildClassHwnd);
|
|
var hwnd = FindWindowEx(hwndParent, IntPtr.Zero, "Button", "完成");
|
|
if (hwnd != IntPtr.Zero)
|
|
{
|
|
finish = hwnd;
|
|
return false;
|
|
}
|
|
EnumChildWindows(hwndParent, childProc, IntPtr.Zero);
|
|
return true;
|
|
}
|
|
} |