zhangyuekai
2024-07-01 0e3464b6adf776686e66bb3189441ab1a65a088e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using HStation.RevitDev.RevitRelationMap.Forms;
 
namespace HStation.RevitDev.RevitRelationMap
{
    [Transaction(TransactionMode.Manual)]
    public class Export : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var form = new Form_RelationMap(commandData);
            //var revitHandle = Autodesk.Windows.ComponentManager.ApplicationWindow;
 
 
            //实例WPF窗体
            var revitHandle = Process.GetCurrentProcess().MainWindowHandle;
            form.Show(new WindowHandle(revitHandle));
 
 
            return Result.Succeeded;
        }
    }
 
    public class WindowHandle : IWin32Window
    {
        private IntPtr _handle;
 
        public WindowHandle(IntPtr h)
        {
            Debug.Assert(IntPtr.Zero != h, "expected non-null window handle");
 
            _handle = h;
        }
        public IntPtr Handle => _handle;
    }
}