public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { using (BrowserWindow browserWindow = new BrowserWindow()) { // the following two lines let the Revit application be this window's owner, so that it will always be on top of the Revit screen even when the user tries to switch the current screen. System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(browserWindow); helper.Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; browserWindow.ShowDialog(); // Variables string fullPath = browserWindow.selectedPath; int countBackups = 0; // Check that path is not empty and path is a folder if (fullPath == null) { return(Result.Cancelled); } else if (!Directory.Exists(fullPath)) { MessageWindows.AlertMessage("Error", "Selected path not found in the system"); return(Result.Cancelled); } else { // Remove backups Helpers.RemoveBackupHelpers.DeleteBackups(fullPath, ref countBackups); // Check number of files deleted if (countBackups > 0) { MessageWindows.AlertMessage("Remove Backup Files", countBackups.ToString() + " backup files have been deleted."); } else { MessageWindows.AlertMessage("Warning", "No files have been found"); } return(Result.Succeeded); } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; // Retrieve active View View activeView = doc.ActiveView; ViewType actViewType = activeView.ViewType; // Array of view types excluded ViewType[] viewTypes = { ViewType.Report, ViewType.Schedule, ViewType.ThreeD, ViewType.Walkthrough, ViewType.Undefined }; // Check current view has origin and it can be drawn on a plane if (viewTypes.Contains(actViewType) == false) { // Retieve normal to view XYZ normal = activeView.ViewDirection; // Define horizontal and vertical projection length double length = 10; double x = 0; double y = 0; double z = 0; // Assing value to coordinates that are not perpendicular to view if (normal.X == 0) { x = length; } if (normal.Y == 0) { y = length; } if (normal.Z == 0) { z = length; } // Create points coordinates XYZ origin = XYZ.Zero; XYZ p1 = new XYZ(x, y, z); XYZ p2 = new XYZ(-x, -y, -z); XYZ p3 = new XYZ(-x, y, -z); XYZ p4 = new XYZ(x, -y, z); Transaction t = new Transaction(doc, "Creteate Origin Marker"); t.Start(); // Create line Line diagonal1 = Line.CreateBound(p1, p2); Line diagonal2 = Line.CreateBound(p3, p4); doc.Create.NewDetailCurve(activeView, diagonal1); doc.Create.NewDetailCurve(activeView, diagonal2); t.Commit(); return(Result.Succeeded); } else { MessageWindows.AlertMessage("Error", "ViewType not supported, please open a supported View \nlike Plan, Section or Drafting View."); return(Result.Failed); } }