public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Get the Current Session / Project from Revit UIApplication uiapp = commandData.Application; //Get the Current Document from the Current Session Document doc = uiapp.ActiveUIDocument.Document; //Create a new instance of the WPF form WPF.MEPSpaceFromRoomWPF form = new WPF.MEPSpaceFromRoomWPF(doc); //Use the Main Windo Handle and Window Helper to make the Revit window the Owner. THis will //prevent task dialogs from going behind the main window or losing focus Helpers.JtWindowHandle rvtwin = new Helpers.JtWindowHandle(commandData.Application.MainWindowHandle); //THis class specifically helps WPF coordinate with Win Form properties System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(form) { Owner = rvtwin.Handle }; //Show the form as a dialog and check the return value if (form.ShowDialog().Value) { //Let Revit know it executed successfully. This is also how you can roll back the entire feature. return(Result.Succeeded); } else { //Let Revit know it was cancelled and all changes will be automatically rolled back if any were made. return(Result.Cancelled); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Get the Current Session / Project from Revit UIApplication uiapp = commandData.Application; //Get the application (Revit) that will Own the modeless dialog IWin32Window revit_window = new Helpers.JtWindowHandle(ComponentManager.ApplicationWindow); //create a new instance of the WarningsForm and pass it the UIApplication variable Forms.WarningsForm frm = new Forms.WarningsForm(uiapp); //Display the form in a modeless form which means you can continue to work in Revit when it is open frm.Show(revit_window); //Let Revit know it executed successfully. This is also how you can roll back the entire feature. return(Result.Succeeded); }