private static ViewDrafting DuplicateDraftingViews(PreviewMap previewMap) { ViewDrafting viewDrafting = null; try { Document fromDoc = previewMap.SourceModelInfo.Doc; Document toDoc = previewMap.RecipientModelInfo.Doc; ViewDrafting sourceView = previewMap.SourceViewProperties.ViewDraftingObj; ICollection <ElementId> referenceCalloutIds = sourceView.GetReferenceCallouts(); CopyPasteOptions options = new CopyPasteOptions(); options.SetDuplicateTypeNamesHandler(new HideAndAcceptDuplicateTypeNamesHandler()); ICollection <ElementId> copiedIds = null; using (Transaction transaction = new Transaction(toDoc, "Duplicate Draftingviews")) { transaction.Start(); try { List <ElementId> viewIds = new List <ElementId>(); viewIds.Add(sourceView.Id); //view-specific item copiedIds = ElementTransformUtils.CopyElements(fromDoc, viewIds, toDoc, Transform.Identity, options); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetFailuresPreprocessor(new HidePasteDuplicateTypesPreprocessor()); transaction.Commit(failureOptions); } catch (Exception ex) { string message = ex.Message; transaction.RollBack(); } } if (null != copiedIds) { ElementId viewId = copiedIds.First(); ViewDrafting copiedView = toDoc.GetElement(viewId) as ViewDrafting; if (null != copiedView) { int numOfCopied = DuplicateDetailingAcrossViews(sourceView, copiedView); } if (referenceCalloutIds.Count > 0) { bool placedCallout = DuplicateReferenceCallouts(sourceView, copiedView); } viewDrafting = copiedView; } } catch (Exception ex) { errorMessage.AppendLine(previewMap.SourceViewProperties.ViewName + ": errors in duplicating drafting views.\n" + ex.Message); //MessageBox.Show("Failed to duplicate drafintg views.\n" + ex.Message, "Duplicate DraftingViews", MessageBoxButton.OK, MessageBoxImage.Warning); } return(viewDrafting); }
public void GetInfo() { try { docName = m_doc.Title; uniqueId = m_view.UniqueId; viewId = m_view.Id.IntegerValue; viewName = m_view.Name; viewTypeID = m_view.GetTypeId().IntegerValue; ViewFamilyType viewType = m_doc.GetElement(m_view.GetTypeId()) as ViewFamilyType; if (null != viewType) { viewTypeName = viewType.Name; } Parameter sheetNumberParam = m_view.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NUMBER); Parameter sheetNameParam = m_view.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NAME); if (null != sheetNumberParam && null != sheetNameParam) { if (!string.IsNullOrEmpty(sheetNumberParam.AsString()) && !string.IsNullOrEmpty(sheetNameParam.AsString())) { sheetNumber = sheetNumberParam.AsString(); sheetName = sheetNameParam.AsString(); isOnSheet = true; sheetObj = FindSheet(sheetNumber, sheetName); viewLocation = FindViewLocation(sheetObj); } } ICollection <ElementId> referenceCalloutIds = m_view.GetReferenceCallouts(); if (referenceCalloutIds.Count > 0) { foreach (ElementId eId in referenceCalloutIds) { Element callout = m_doc.GetElement(eId); if (null != callout) { Parameter param = callout.get_Parameter(BuiltInParameter.ID_PARAM); if (null != param) { ElementId referenceViewId = param.AsElementId(); ViewDrafting referenceView = m_doc.GetElement(referenceViewId) as ViewDrafting; if (null != referenceView) { ViewProperties vp = new ViewProperties(m_doc, referenceView); if (!dependantViews.ContainsKey(vp.ViewId)) { dependantViews.Add(vp.ViewId, vp); } } } } } } ICollection <ElementId> referenceSectionIds = m_view.GetReferenceSections(); if (referenceSectionIds.Count > 0) { foreach (ElementId eId in referenceSectionIds) { Element marker = m_doc.GetElement(eId); if (null != marker) { Parameter param = marker.get_Parameter(BuiltInParameter.ID_PARAM); if (null != param) { ElementId referenceViewId = param.AsElementId(); ViewDrafting referenceView = m_doc.GetElement(referenceViewId) as ViewDrafting; if (null != referenceView) { ViewProperties vp = new ViewProperties(m_doc, referenceView); if (!dependantViews.ContainsKey(vp.ViewId)) { dependantViews.Add(vp.ViewId, vp); } } } } } } } catch (Exception ex) { string message = ex.Message; } }
public static PreviewMap DuplicateView(PreviewMap previewMap, bool createSheet) { PreviewMap preview = previewMap; try { CopyPasteOptions options = new CopyPasteOptions(); options.SetDuplicateTypeNamesHandler(new HideAndAcceptDuplicateTypeNamesHandler()); Document toDoc = preview.RecipientModelInfo.Doc; List <ElementId> viewIds = new List <ElementId>(); using (TransactionGroup tg = new TransactionGroup(toDoc, "Duplicate across documents with detailing")) { tg.Start(); if (preview.IsEnabled) { ViewDrafting copiedView = null; if (null != preview.SourceViewProperties.LinkedView) //already exist in recipient model { ViewDrafting sourceView = previewMap.SourceViewProperties.ViewDraftingObj; ICollection <ElementId> referenceCalloutIds = sourceView.GetReferenceCallouts(); ElementId viewId = new ElementId(preview.SourceViewProperties.LinkedView.ViewId); using (Transaction trans = new Transaction(preview.RecipientModelInfo.Doc, "Delete Existing Contents")) { trans.Start(); try { FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions(); failOpt.SetFailuresPreprocessor(new WarningMessagePreprocessor()); trans.SetFailureHandlingOptions(failOpt); FilteredElementCollector collector = new FilteredElementCollector(preview.RecipientModelInfo.Doc, viewId); collector.WherePasses(new ElementCategoryFilter(ElementId.InvalidElementId, true)); ICollection <ElementId> toDelete = collector.ToElementIds(); ICollection <ElementId> deletedIds = preview.RecipientModelInfo.Doc.Delete(toDelete); trans.Commit(); } catch (Exception ex) { string message = ex.Message; trans.RollBack(); } } copiedView = preview.RecipientModelInfo.Doc.GetElement(viewId) as ViewDrafting; if (null != copiedView) { int numOfCopied = DuplicateDetailingAcrossViews(preview.SourceViewProperties.ViewDraftingObj, copiedView); } if (referenceCalloutIds.Count > 0) { bool placedCallout = DuplicateReferenceCallouts(sourceView, copiedView); } if (createSheet) { //delete existing viewport ElementClassFilter filter = new ElementClassFilter(typeof(Viewport)); FilteredElementCollector collector = new FilteredElementCollector(preview.RecipientModelInfo.Doc); List <Viewport> viewports = collector.WherePasses(filter).Cast <Viewport>().ToList <Viewport>(); var query = from element in viewports where element.ViewId == viewId select element; if (query.Count() > 0) { Viewport viewport = query.First(); using (Transaction trans = new Transaction(preview.RecipientModelInfo.Doc, "Delete exisitng viewport")) { trans.Start(); try { FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions(); failOpt.SetFailuresPreprocessor(new WarningMessagePreprocessor()); trans.SetFailureHandlingOptions(failOpt); preview.RecipientModelInfo.Doc.Delete(viewport.Id); trans.Commit(); } catch (Exception ex) { string message = ex.Message; trans.RollBack(); } } } if (preview.SourceViewProperties.IsOnSheet && null != preview.SourceViewProperties.SheetObj) { ViewSheet copiedSheet = DuplicateSheet(preview); if (null != copiedView && null != copiedSheet) { if (Viewport.CanAddViewToSheet(preview.RecipientModelInfo.Doc, copiedSheet.Id, copiedView.Id)) { Viewport recipientViewport = DuplicateViewPort(preview, copiedSheet, copiedView); } } } } } else { if (preview.SourceViewProperties.IsOnSheet && createSheet) { ViewSheet copiedSheet = DuplicateSheet(preview); copiedView = DuplicateDraftingViews(preview); if (null != copiedSheet && null != copiedView) { if (Viewport.CanAddViewToSheet(preview.RecipientModelInfo.Doc, copiedSheet.Id, copiedView.Id)) { Viewport viewport = DuplicateViewPort(preview, copiedSheet, copiedView); } } } else { copiedView = DuplicateDraftingViews(preview); } } preview = UpdatePreviewMap(preview, copiedView); } tg.Assimilate(); } } catch (Exception ex) { errorMessage.AppendLine(previewMap.SourceViewProperties.ViewName + ": errors in duplicating detailing across views\n" + ex.Message); //MessageBox.Show("Failed to duplicate drafiting views.\n" + ex.Message, "Duplicate Drafting Views", MessageBoxButton.OK, MessageBoxImage.Warning); } return(preview); }