From 735470c0856ab4cb0a0e847fe958d23c3b7e8838 Mon Sep 17 00:00:00 2001 From: giobel Date: Wed, 2 Feb 2022 17:00:26 +1100 Subject: [PATCH] add move viewports --- ReviTab/ApplicationRibbon.cs | 2 + .../MoveViewportToSheet.cs | 76 +++++++++++++++++++ ReviTab/ReviTab.csproj | 1 + 3 files changed, 79 insertions(+) create mode 100644 ReviTab/Buttons Documentation/MoveViewportToSheet.cs diff --git a/ReviTab/ApplicationRibbon.cs b/ReviTab/ApplicationRibbon.cs index 9b14c6a..00fc61e 100644 --- a/ReviTab/ApplicationRibbon.cs +++ b/ReviTab/ApplicationRibbon.cs @@ -88,6 +88,8 @@ public Result OnStartup(UIControlledApplication a) splitButtonsViews.Add(CreatePushButton("btnDuplicateViews", "Duplicate Views", "", "pack://application:,,,/ReviTab;component/Resources/duplicateSheets.png", "ReviTab.DuplicateSheets", "Duplicate selected sheets with viewports, schedules and legends.")); splitButtonsViews.Add(CreatePushButton("btnExtractDetail", "Extract Detail", "", "pack://application:,,,/ReviTab;component/Resources/duplicateSheets.png", "ReviTab.ExtractDetail", "Cut and Paste lines to a new detail")); + + splitButtonsViews.Add(CreatePushButton("btnMoveViewport", "Move Viewports", "", "pack://application:,,,/ReviTab;component/Resources/duplicateSheets.png", "ReviTab.MoveViewportToSheet", "Move selected viewports to another Sheet")); #if !SAM diff --git a/ReviTab/Buttons Documentation/MoveViewportToSheet.cs b/ReviTab/Buttons Documentation/MoveViewportToSheet.cs new file mode 100644 index 0000000..5665a59 --- /dev/null +++ b/ReviTab/Buttons Documentation/MoveViewportToSheet.cs @@ -0,0 +1,76 @@ +using System.Collections.Generic; +using Autodesk.Revit.ApplicationServices; +using Autodesk.Revit.Attributes; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using forms = System.Windows.Forms; + +namespace ReviTab +{ + [Transaction(TransactionMode.Manual)] + public class MoveViewportToSheet : IExternalCommand + { + public Result Execute( + ExternalCommandData commandData, + ref string message, + ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Application app = uiapp.Application; + Document doc = uidoc.Document; + + + ICollection viewportsToMove = uidoc.Selection.PickObjects(ObjectType.Element, "Select viewports to move"); + + + FilteredElementCollector sheets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)); + + using (var form = new FormAddActiveView("Enter Sheet Number")) + { + form.ShowDialog(); + + if (form.DialogResult == forms.DialogResult.Cancel) + { + return Result.Cancelled; + } + + string sheetNumber = form.TextString.ToString(); + + ViewSheet viewSh = null; + + foreach (ViewSheet sht in sheets) + { + if (sht.SheetNumber == sheetNumber) + { + viewSh = sht; + break; + } + } + + using (Transaction t = new Transaction(doc, "Move Viewports")) + { + t.Start(); + + foreach (Reference selectedViewportId in viewportsToMove) + { + Viewport vp = doc.GetElement(selectedViewportId) as Viewport; + XYZ vpCenter = vp.GetBoxCenter(); + ElementId vpId = vp.ViewId; + doc.Delete(vp.Id); + Viewport.Create(doc, viewSh.Id, vpId, vpCenter); + } + + t.Commit(); + } + + if (viewSh != null) + { + uidoc.ActiveView = viewSh; + } + } + return Result.Succeeded; + } + } +} diff --git a/ReviTab/ReviTab.csproj b/ReviTab/ReviTab.csproj index 7cfbd8d..5f96878 100644 --- a/ReviTab/ReviTab.csproj +++ b/ReviTab/ReviTab.csproj @@ -333,6 +333,7 @@ +