Skip to content

Commit

Permalink
add move viewports
Browse files Browse the repository at this point in the history
  • Loading branch information
giobel committed Feb 2, 2022
1 parent 35932b1 commit 735470c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ReviTab/ApplicationRibbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions ReviTab/Buttons Documentation/MoveViewportToSheet.cs
Original file line number Diff line number Diff line change
@@ -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<Reference> 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;
}
}
}
1 change: 1 addition & 0 deletions ReviTab/ReviTab.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationRibbon.cs" />
<Compile Include="Buttons Documentation\MoveViewportToSheet.cs" />
<Compile Include="Buttons Documentation\ExtractDetail.cs" />
<Compile Include="Buttons Documentation\MatchSectionViewCrop.cs" />
<Compile Include="Buttons Documentation\RhinoImport.cs" />
Expand Down

0 comments on commit 735470c

Please sign in to comment.