public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { if (commandData == null || commandData.Application == null || commandData.Application.ActiveUIDocument == null) { TaskDialog.Show("Revit", "Comment Editor requires an open document."); return Result.Failed; } UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; // Access current selection Selection sel = uidoc.Selection; if (sel.GetElementIds().Count != 1) { TaskDialog.Show("Revit", "Comment Editor requires a single element selected."); return Result.Failed; } m_element = doc.GetElement(sel.GetElementIds().FirstOrDefault()); Parameter comment = m_element.GetParameters("Comments").FirstOrDefault(); if (comment == null) { TaskDialog.Show("Revit", "Comment Editor requires the selected element to have a comment parameter"); return Result.Failed; } CommentEditorDialog ced = new CommentEditorDialog(); Window cew = new Window(); cew.Content = ced; cew.Title = "Comment Editor"; cew.Width = ced.grid.Width; cew.Height = ced.grid.Height; ced.Text = comment.AsString(); cew.ResizeMode = ResizeMode.NoResize; cew.ShowDialog(); if (cew.DialogResult.Value == false) { return Result.Cancelled; } using (Transaction tx = new Transaction(doc)) { tx.Start("Edit Element Comment"); comment.Set(ced.Text); tx.Commit(); } return Result.Succeeded; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { if (commandData == null || commandData.Application == null || commandData.Application.ActiveUIDocument == null) { TaskDialog.Show("Revit", "Comment Editor requires an open document."); return(Result.Failed); } UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; // Access current selection Selection sel = uidoc.Selection; if (sel.GetElementIds().Count != 1) { TaskDialog.Show("Revit", "Comment Editor requires a single element selected."); return(Result.Failed); } m_element = doc.GetElement(sel.GetElementIds().FirstOrDefault()); Parameter comment = m_element.GetParameters("Comments").FirstOrDefault(); if (comment == null) { TaskDialog.Show("Revit", "Comment Editor requires the selected element to have a comment parameter"); return(Result.Failed); } CommentEditorDialog ced = new CommentEditorDialog(); Window cew = new Window(); cew.Content = ced; cew.Title = "Comment Editor"; cew.Width = ced.grid.Width; cew.Height = ced.grid.Height; ced.Text = comment.AsString(); cew.ResizeMode = ResizeMode.NoResize; cew.ShowDialog(); if (cew.DialogResult.Value == false) { return(Result.Cancelled); } using (Transaction tx = new Transaction(doc)) { tx.Start("Edit Element Comment"); comment.Set(ced.Text); tx.Commit(); } return(Result.Succeeded); }