public void CreateViewports(SheetCopierSheet sheet) { Dictionary <ElementId, XYZ> viewPorts = GetViewportDictionary(sheet.SourceSheet, doc); foreach (SheetCopierViewOnSheet view in sheet.ViewsOnSheet) { XYZ sourceViewPortCentre = null; if (!viewPorts.TryGetValue(view.OldId, out sourceViewPortCentre)) { SCaddinsApp.WindowManager.ShowMessageBox("SCopy", "Error..."); continue; } switch (view.CreationMode) { case ViewPortPlacementMode.Copy: DuplicateViewOntoSheet(view, sheet, sourceViewPortCentre); break; case ViewPortPlacementMode.New: PlaceNewViewOnSheet(view, sheet, sourceViewPortCentre); break; case ViewPortPlacementMode.Legend: PlaceViewPortOnSheet(sheet.DestinationSheet, view.OldView.Id, sourceViewPortCentre); break; } } }
// this is where the action happens public bool CreateAndPopulateNewSheet(SheetCopierSheet sheet, StringBuilder summary) { if (sheet == null) { return(false); } // turn on hidden revisions foreach (Revision rev in hiddenRevisionClouds) { try { rev.Visibility = RevisionVisibility.CloudAndTagVisible; } catch (Autodesk.Revit.Exceptions.ArgumentOutOfRangeException ex) { SCaddinsApp.WindowManager.ShowMessageBox(ex.Message); } } sheet.DestinationSheet = AddEmptySheetToDocument( sheet.Number, sheet.Title, sheet.SheetCategory); if (sheet.DestinationSheet != null) { Debug.WriteLine(sheet.Number + " added to document."); CreateViewports(sheet); } else { Debug.WriteLine(sheet.Number + " Could not be added added to document."); return(false); } try { CopyElementsBetweenSheets(sheet); } catch (InvalidOperationException e) { Debug.WriteLine(e.Message); } foreach (Revision rev in hiddenRevisionClouds) { rev.Visibility = RevisionVisibility.Hidden; } var oldNumber = sheet.SourceSheet.SheetNumber; var msg = " Sheet: " + oldNumber + " copied to: " + sheet.Number; if (summary != null) { summary.Append(msg + Environment.NewLine); } return(true); }
public void PlaceNewViewOnSheet( SheetCopierViewOnSheet view, SheetCopierSheet sheet, XYZ sourceViewCentre) { Level level = null; levels.TryGetValue(view.AssociatedLevelName, out level); if (level != null) { using (ViewPlan vp = ViewPlan.Create(doc, floorPlanViewFamilyTypeId, level.Id)) { vp.CropBox = view.OldView.CropBox; vp.CropBoxActive = view.OldView.CropBoxActive; vp.CropBoxVisible = view.OldView.CropBoxVisible; TryAssignViewTemplate(vp, view.ViewTemplateName); PlaceViewPortOnSheet(sheet.DestinationSheet, vp.Id, sourceViewCentre); } } level.Dispose(); }
public void CopyElementsBetweenSheets(SheetCopierSheet sheet) { IList <ElementId> list = new List <ElementId>(); using (var collector = new FilteredElementCollector(doc)) { collector.OwnedByView(sheet.SourceSheet.Id); foreach (Element e in collector) { if (!(e is Viewport)) { if (e is CurveElement) { continue; } if (e.IsValidObject && e.ViewSpecific) { list.Add(e.Id); } } } } if (list.Count > 0) { Transform transform; CopyPasteOptions options; ElementTransformUtils.CopyElements( sheet.SourceSheet, list, sheet.DestinationSheet, transform = new Transform(ElementTransformUtils.GetTransformFromViewToView(sheet.SourceSheet, sheet.DestinationSheet)), options = new CopyPasteOptions()); DeleteRevisionClouds(sheet.DestinationSheet.Id, doc); options.Dispose(); transform.Dispose(); } }
public void DuplicateViewOntoSheet( SheetCopierViewOnSheet view, SheetCopierSheet sheet, XYZ sourceViewCentre) { var d = view.DuplicateWithDetailing ? ViewDuplicateOption.WithDetailing : ViewDuplicateOption.Duplicate; ElementId destViewId = ElementId.InvalidElementId; if (view.OldView.CanViewBeDuplicated(d)) { try { destViewId = view.OldView.Duplicate(d); } catch (Autodesk.Revit.Exceptions.ArgumentOutOfRangeException arx) { SCaddinsApp.WindowManager.ShowMessageBox(arx.Message); } catch (Autodesk.Revit.Exceptions.InvalidOperationException iox) { SCaddinsApp.WindowManager.ShowMessageBox(iox.Message); } } else { SCaddinsApp.WindowManager.ShowMessageBox("WARNING: CanViewBeDuplicated is returning false for view: " + view.OldView.Name); return; } if (destViewId == ElementId.InvalidElementId) { SCaddinsApp.WindowManager.ShowMessageBox("WARNING: could not create copy of view: " + view.OldView.Name); //// sometimes view.Duplicate seems to fail if the duplicate option is set to ViewDuplicateOption.WithDetailing //// try again with option set to ViewDuplicateOption.Duplicate if (d == ViewDuplicateOption.WithDetailing) { SCaddinsApp.WindowManager.ShowMessageBox("Attempting to create view without detailing..." + view.OldView.Name); view.DuplicateWithDetailing = false; DuplicateViewOntoSheet(view, sheet, sourceViewCentre); } return; } DeleteRevisionClouds(destViewId, doc); var elem = doc.GetElement(destViewId); if (elem == null) { return; } var v = elem as View; string newName = sheet.GetNewViewName(view.OldView.Id); if (newName != null) { v.Name = newName; } else { SCaddinsApp.WindowManager.ShowMessageBox("ERROR", "New view name could not be set to: " + newName); } TryAssignViewTemplate(v, view.ViewTemplateName); PlaceViewPortOnSheet(sheet.DestinationSheet, destViewId, sourceViewCentre); }