Revit二次开发番外篇之改变PickObjects完成按钮的触发
标签:
365it |
分类: Revit二次开发番外篇 |
大家都知道PickObjects函数框选完构件群后必须在工具条上点击完成或取消按钮才能完成或退出任务,有用户反映有时没有注意到那个按钮,甚至以为程序出错了,所以能不能在用户框选完之后就弹出一个窗体来执行下一步操作,是完成还是取消!好吧让我想了好一会
,这个问题说难也难说不难也很难,只要你懂点WindowsAPI就可以了——正所谓!落花有意随流水,流水无意恋落花,不要忘记这是在WIndows系统上!这里使用非模态窗体给大家演示!
http://s10/mw690/006AhjOXzy75cA8SCaBf9&690
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Test :
IExternalCommand
{
public Result
Execute(ExternalCommandData commandData, ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument
uiDoc = uiApp.ActiveUIDocument;
Document
Doc = uiDoc.Document;
Form1 frm
= new Form1();
frm.Show();
return
Result.Succeeded;
}
}
public partial class Form1 :
System.Windows.Forms.Form
{
public
Form1()
{
InitializeComponent();
}
[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;
ExecuteEvent Exc = null;
ExternalEvent eventHandler = null;
private
void Form1_Load(object sender, EventArgs e)
{
Exc = new
ExecuteEvent();
eventHandler =
ExternalEvent.Create(Exc);
}
public
static void SetOk()
{
IntPtr Revit =
Autodesk.Windows.ComponentManager.ApplicationWindow;
if (Revit !=
IntPtr.Zero)
{
FindChildClassHwnd(Revit,
IntPtr.Zero);
SendMessage(finish, WM_CLICK, IntPtr.Zero,
0);
}
}
internal
static bool FindChildClassHwnd(IntPtr hwndParent, IntPtr
lParam)
{
EnumWindowProc childProc =
new EnumWindowProc(FindChildClassHwnd);
IntPtr hwnd =
FindWindowEx(hwndParent, IntPtr.Zero, "Button", "完成");
if (hwnd !=
IntPtr.Zero)
{
finish = hwnd;
return false;
}
EnumChildWindows(hwndParent,
childProc, IntPtr.Zero);
return true;
}
private
void button1_Click(object sender, EventArgs e)
{
SetOk();
this.Close();
}
private
void button3_Click(object sender, EventArgs e)
{
eventHandler.Raise();
}
}
public class ExecuteEvent :
IExternalEventHandler
{
public
void Execute(UIApplication app)
{
Document doc =
app.ActiveUIDocument.Document;
UIDocument uidoc =
app.ActiveUIDocument;
//框选目标构件群
IList list =
uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element,
"");
foreach (Reference refer in
list)
{
//逻辑代码
}
}
public
string GetName()
{
return "this is a
Test";
}
}
类代码
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Events;
namespace HelloWorld
{
}
窗体代码
using
System.Windows.Forms;
using
Autodesk.Revit.UI;
using
Autodesk.Revit.DB;
namespace
HelloWorld
{
}

加载中…