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; } }