//duplicates the view naming it as given, duplicate will be in same location public bool DuplicateViewByName(string viewName, string newViewName, ViewDuplicateOption duplicateOption) { //get the view we will duplicate first View v = GetView(viewName); if (v != null) //make sure there is indeed a view { using (Transaction t = new Transaction(doc)) //duplicate the view { t.Start("Duplicating view."); ElementId id = v.Duplicate(duplicateOption); View tempView = doc.GetElement(id) as View; tempView.Name = newViewName;//rename the view to the new name t.Commit(); } return(true); } else { if (debugMode) { ShowMessageBox("Warning!", "ID_TaskDialog_Warning", "Unable to duplicate view '" + viewName + "'.", TaskDialogIcon.TaskDialogIconWarning, TaskDialogCommonButtons.Close); } return(false); } }
//视图复制 public void viewduplicate_duplicate(UIApplication uiapp, ViewDuplicateOption Duplicate) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Autodesk.Revit.DB.View activeView = doc.ActiveView; //让用户选择哪几个PLOT视图需要复制生成 if (CMD.selectedViewNames.Count() <= 0)//判断是否选择不存在INTF视图的PLOT视图 { TaskDialog.Show("Revit2020", "未选择任何视图"); } else { using (Transaction trans = new Transaction(doc)) { trans.Start("view_duplicate"); if (CMD.changStr == "_actiView") { Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, activeView.Id, Duplicate);//复制PLOT视图为指定字段视图 } else if (CMD.changStr == "_work") { ICollection <ElementId> selPlotViewIds = getSelPlotViewIds(doc, CMD.selectedViewNames, CMD.workViewIds); foreach (ElementId eleId in selPlotViewIds) { Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, eleId, Duplicate);//复制PLOT视图为指定字段视图 } } else if (CMD.changStr == "_plot") { ICollection <ElementId> selPlotViewIds = getSelPlotViewIds(doc, CMD.selectedViewNames, CMD.plotViewIds); foreach (ElementId eleId in selPlotViewIds) { Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, eleId, Duplicate);//复制PLOT视图为指定字段视图 } } else if (CMD.changStr == "_INTF") { ICollection <ElementId> selPlotViewIds = getSelPlotViewIds(doc, CMD.selectedViewNames, CMD.INTFViewIds); foreach (ElementId eleId in selPlotViewIds) { Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, eleId, Duplicate);//复制PLOT视图为指定字段视图 } } trans.Commit(); } showSuccess(" !"); CMD.selectedViewNames = new List <string>(); //避免选项会被累计的问题 CMD.selectedViewNames = new List <string>(); //避免选项会被累计的问题 //所有视图列表需要设置尾部更新-窗口列表更新 CMD.GetViews_All(doc);//获取视图列表合辑 } }//main
/// <summary> /// Identifies if this view can be duplicated with specified viewDuplicateOption /// </summary> /// <param name="viewDuplicateOption">Enter View Duplicate Option: 0 = Duplicate. 1 = AsDependent. 2 = WithDetailing.</param> /// <returns></returns> public Boolean CanViewBeDuplicated(int viewDuplicateOption = 0) { ViewDuplicateOption Option = 0; switch (viewDuplicateOption) { case 0: Option = ViewDuplicateOption.Duplicate; break; case 1: Option = ViewDuplicateOption.AsDependent; break; case 2: Option = ViewDuplicateOption.WithDetailing; break; default: throw new ArgumentException(Properties.Resources.ViewDuplicateOptionOutofRange); } return(InternalView.CanViewBeDuplicated(Option)); }
public void AddViewsToSheet(List <View> views, ElementId viewPortTypeId, bool isDuplicate, ViewDuplicateOption viewDuplicateOption) { foreach (var v in views) { var view = v; if (isDuplicate) { try { if (view.ViewType == ViewType.Schedule) { var viewid = v.Duplicate(ViewDuplicateOption.Duplicate); view = Doc.GetElement(viewid) as View; } else { var viewid = v.Duplicate(viewDuplicateOption); view = Doc.GetElement(viewid) as View; } } catch { var viewid = v.Duplicate(ViewDuplicateOption.Duplicate); view = Doc.GetElement(viewid) as View; } } try { var viewname = view.Name; if (view.ViewType != ViewType.Schedule) { var point = _data.Sel.PickPoint("Pick a Point to Place View:" + viewname); var vp = Viewport.Create(Doc, Doc.ActiveView.Id, view.Id, point); vp.ChangeTypeId(viewPortTypeId); } else { var point = _data.Sel.PickPoint("Pick a Point to Place View:" + viewname); ScheduleSheetInstance.Create(Doc, Doc.ActiveView.Id, view.Id, point); } } catch { TaskDialog.Show("Iven EXT:", v.Name + " only can added in one Sheet."); } } }
private static List <Autodesk.Revit.DB.Element> DuplicateViewport(Sheet oldSheet, Sheet newSheet, ViewDuplicateOption viewDuplicateOption, string prefix, string suffix) { var Viewports = oldSheet.Viewports.ToList(); List <Revit.Elements.Views.View> viewList = new List <View>(); List <Autodesk.Revit.DB.Element> elements = new List <Autodesk.Revit.DB.Element>(); List <Autodesk.DesignScript.Geometry.Point> locationList = new List <Autodesk.DesignScript.Geometry.Point>(); foreach (var viewport in Viewports) { if (viewport.View.InternalView.CanViewBeDuplicated(viewDuplicateOption)) { var newViewName = prefix + viewport.View.Name + suffix; if (!CheckUniqueViewName(newViewName)) { throw new ArgumentException(String.Format(Properties.Resources.ViewNameExists, newViewName)); } var newViewId = viewport.View.InternalView.Duplicate(viewDuplicateOption); var newView = (Document.GetElement(newViewId) as Autodesk.Revit.DB.View).ToDSType(false) as View; var param = newView.InternalView.get_Parameter(BuiltInParameter.VIEW_NAME); param.Set(prefix + viewport.View.Name + suffix); viewList.Add(newView); elements.Add(newView.InternalElement); } else { throw new Exception(String.Format(Properties.Resources.ViewCantBeDuplicated, viewport.View.Name)); } locationList.Add(viewport.BoxCenter); } newSheet.DuplicateViews = viewList; if (viewList.Count() == locationList.Count() && viewList.Any()) { for (int i = 0; i < viewList.Count(); i++) { ElementId sheetId = newSheet.InternalView.Id; ElementId viewId = viewList[i].InternalView.Id; XYZ viewLocation = Revit.GeometryConversion.GeometryPrimitiveConverter.ToRevitType(locationList[i]); if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(Document, sheetId, viewId)) { throw new InvalidOperationException(Properties.Resources.ViewAlreadyPlacedOnSheet); } Autodesk.Revit.DB.Viewport.Create(Document, sheetId, viewId, viewLocation); } } return(elements); }
/// <summary> /// Duplicates A Sheet. /// </summary> /// <param name="sheet">The Sheet to be Duplicated.</param> /// <param name="duplicateWithContents">Set to true that Duplicate sheet with contents</param> /// <param name="duplicateWithView">Set to true that Duplicate sheet with views.</param> /// <param name="viewDuplicateOption">Enter View Duplicate Option: 0 = Duplicate. 1 = AsDependent. 2 = WithDetailing.</param> /// <param name="prefix"></param> /// <param name="suffix">When prefix and suffix are both empty, suffix will set a default value - " - Copy".</param> /// <returns></returns> public static Sheet DuplicateSheet(Sheet sheet, bool duplicateWithContents = false, bool duplicateWithView = false, int viewDuplicateOption = 0, string prefix = "", string suffix = "") { if (sheet == null) { throw new ArgumentNullException(nameof(sheet)); } ViewDuplicateOption Option = 0; switch (viewDuplicateOption) { case 0: Option = ViewDuplicateOption.Duplicate; break; case 1: Option = ViewDuplicateOption.AsDependent; break; case 2: Option = ViewDuplicateOption.WithDetailing; break; default: throw new ArgumentException(Properties.Resources.ViewDuplicateOptionOutofRange); } if (String.IsNullOrEmpty(prefix) && String.IsNullOrEmpty(suffix)) { suffix = " - Copy"; } Sheet newSheet = null; try { RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument); var oldElements = ElementBinder.GetElementsFromTrace <Autodesk.Revit.DB.Element>(Document); List <ElementId> elementIds = new List <ElementId>(); var newSheetNumber = prefix + sheet.SheetNumber + suffix; var newSheetName = sheet.SheetName; List <Autodesk.Revit.DB.Element> TraceElements = new List <Autodesk.Revit.DB.Element>(); if (oldElements != null) { foreach (var element in oldElements) { elementIds.Add(element.Id); if (element is ViewSheet) { var oldSheet = (element as ViewSheet).ToDSType(false) as Sheet; if (oldSheet.SheetNumber.Equals(newSheetNumber)) { if ((duplicateWithView && oldElements.Count() > 1) || (!duplicateWithView && oldElements.Count() == 1)) { newSheet = oldSheet; TraceElements.AddRange(oldElements); } if (newSheet != null) { if (duplicateWithContents) { DuplicateSheetAnnotations(sheet, newSheet); } else { DeleteSheetAnnotations(newSheet); } } } } } if (newSheet == null) { Autodesk.Revit.UI.UIDocument uIDocument = new Autodesk.Revit.UI.UIDocument(Document); var openedViews = uIDocument.GetOpenUIViews().ToList(); var shouldClosedViews = openedViews.FindAll(x => elementIds.Contains(x.ViewId)); if (shouldClosedViews.Count > 0) { foreach (var v in shouldClosedViews) { if (uIDocument.GetOpenUIViews().ToList().Count() > 1) { v.Close(); } else { throw new InvalidOperationException(string.Format(Properties.Resources.CantCloseLastOpenView, v.ToString())); } } } Document.Delete(elementIds); } } if (newSheet == null && TraceElements.Count == 0) { // Create a new Sheet with different SheetNumber var titleBlockElement = sheet.TitleBlock.First() as FamilyInstance; FamilySymbol TitleBlock = titleBlockElement.InternalFamilyInstance.Symbol; FamilyType titleBlockFamilyType = ElementWrapper.Wrap(TitleBlock, true); if (!CheckUniqueSheetNumber(newSheetNumber)) { throw new ArgumentException(String.Format(Properties.Resources.SheetNumberExists, newSheetNumber)); } var viewSheet = Autodesk.Revit.DB.ViewSheet.Create(Document, TitleBlock.Id); newSheet = new Sheet(viewSheet); newSheet.InternalSetSheetName(newSheetName); newSheet.InternalSetSheetNumber(newSheetNumber); TraceElements.Add(newSheet.InternalElement); // Copy Annotation Elements from sheet to new sheet by ElementTransformUtils.CopyElements if (duplicateWithContents) { DuplicateSheetAnnotations(sheet, newSheet); } if (duplicateWithView) { // Copy ScheduleSheetInstance except RevisionSchedule from sheet to new sheet by ElementTransformUtils.CopyElements DuplicateScheduleSheetInstance(sheet, newSheet); // Duplicate Viewport in sheet and place on new sheet TraceElements.AddRange(DuplicateViewport(sheet, newSheet, Option, prefix, suffix)); } } ElementBinder.SetElementsForTrace(TraceElements); RevitServices.Transactions.TransactionManager.Instance.TransactionTaskDone(); } catch (Exception e) { if (newSheet != null) { newSheet.Dispose(); } throw e; } return(newSheet); }
/// <summary> /// Duplicates A view. /// </summary> /// <param name="view">The View to be Duplicated</param> /// <param name="viewDuplicateOption">Enter View Duplicate Option: Duplicate, AsDependent or WithDetailing.</param> /// <param name="prefix"></param> /// <param name="suffix"></param> /// <returns></returns> public static Revit.Elements.Views.View DuplicateView(View view, string viewDuplicateOption = "Duplicate", string prefix = "", string suffix = "") { View newView = null; if (view == null) { throw new ArgumentNullException(nameof(view)); } if (view is Sheet) { throw new ArgumentException(Properties.Resources.DuplicateViewCantApplySheet); } ViewDuplicateOption Option = (ViewDuplicateOption)Enum.Parse(typeof(ViewDuplicateOption), viewDuplicateOption); try { RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument); var viewElement = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.View>(Document); int count = 0; string newViewName = ""; if (!String.IsNullOrEmpty(prefix) || !String.IsNullOrEmpty(suffix)) { newViewName = prefix + view.Name + suffix; } Autodesk.Revit.UI.UIDocument uIDocument = new Autodesk.Revit.UI.UIDocument(Document); var openedViews = uIDocument.GetOpenUIViews().ToList(); if (viewElement != null) { count++; var oldViewName = viewElement.Name; if (oldViewName.Equals(newViewName)) { newView = viewElement.ToDSType(false) as View; } else { count--; } } if (count == 0) { if (!CheckUniqueViewName(newViewName)) { throw new ArgumentException(String.Format(Properties.Resources.ViewNameExists, newViewName)); } if (view.InternalView.CanViewBeDuplicated(Option)) { var viewID = view.InternalView.Duplicate(Option); var viewEle = Document.GetElement(viewID) as Autodesk.Revit.DB.View; newView = ElementWrapper.ToDSType(viewEle, false) as View; } else { throw new Exception(String.Format(Properties.Resources.ViewCantBeDuplicated, view.Name)); } if (!String.IsNullOrEmpty(newViewName)) { var param = newView.InternalView.get_Parameter(BuiltInParameter.VIEW_NAME); param.Set(newViewName); } if (viewElement != null) { var shouldClosedViews = openedViews.FindAll(x => viewElement.Id == x.ViewId); if (shouldClosedViews.Count > 0) { foreach (var v in shouldClosedViews) { if (uIDocument.GetOpenUIViews().ToList().Count() > 1) { v.Close(); } else { throw new InvalidOperationException(string.Format(Properties.Resources.CantCloseLastOpenView, viewElement.ToString())); } } } } } ElementBinder.CleanupAndSetElementForTrace(Document, newView.InternalElement); RevitServices.Transactions.TransactionManager.Instance.TransactionTaskDone(); } catch (Exception e) { //if (e is Autodesk.Revit.Exceptions.InvalidOperationException) // throw e; if (newView != null) { newView.Dispose(); } throw e; } return(newView); }
/// <summary> /// Identifies if this view can be duplicated with specified viewDuplicateOption /// </summary> /// <param name="viewDuplicateOption">Enter View Duplicate Option: Duplicate, AsDependent or WithDetailing.</param> /// <returns></returns> public Boolean CanViewBeDuplicated(string viewDuplicateOption = "Duplicate") { ViewDuplicateOption Option = (ViewDuplicateOption)Enum.Parse(typeof(ViewDuplicateOption), viewDuplicateOption); return(InternalView.CanViewBeDuplicated(Option)); }
private void BtnDuplicate_Click(object sender, EventArgs e) { // reset viewport counter Ana_NoOfViewports = 0; // get number of copies int copies = Convert.ToInt32(NumOfCopies.Value); // set Dependent views Duplicate Option ViewDuplicateOption dependentOption = ViewDuplicateOption.AsDependent; if (CbxDependent.Checked != true) { dependentOption = ViewDuplicateOption.WithDetailing; } // is there at least one item selected? if (LsvSheets.CheckedItems.Count == 0) { UI.Info.Form_Info1.infoMsgMain = "Select"; UI.Info.Form_Info1.infoMsgBody = "Select one sheet to continue."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } // proceed with duplication else { executionTime.Start(); // start execution time counter // collect selected sheets, for multiple selection List <string> selSheetsTxt = new List <string>(); List <ViewSheet> allViewSheets = Data.Helpers.GetViewSheets(m_doc); foreach (ListViewItem lv in LsvSheets.CheckedItems) { selSheetsTxt.Add(lv.SubItems[0].Text); } List <ViewSheet> selViewSheets = Data.Helpers.GetSelectedSheets(allViewSheets, selSheetsTxt); // currently multiple selection is not allowed, so take just one item ViewSheet sourceSheet = selViewSheets.First(); Ana_SheetNumber = sourceSheet.SheetNumber; Ana_SheetName = sourceSheet.Name; Ana_NoOfCopies = copies; DuplicateSheets(m_doc, sourceSheet, copies, dependentOption); transactionMade = true; // to trigger stopwatch stop in other methods executionTime.Stop(); // stop execution time counter ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); #region show Results Form resultHead = "Results"; resultMain = string.Format("You have made {0} copies of:{1}{1}'{2}'", copies, Environment.NewLine, sourceSheet.Name); resultBody = string.Format("NOTE: A suffix 'DupX' has been added to the view names.{0}" + "Please, rename the views appropriately.", Environment.NewLine); ; using (UI.Info.Form_Results thisForm = new Info.Form_Results()) { thisForm.ShowDialog(); if (thisForm.DialogResult == DialogResult.No) { useTime.Stop(); UseTimeElapseS = useTime.Elapsed.Seconds.ToString(); Utilities.GetAnalyticsCSV(m_doc, m_app); Data.Helpers.DuplicateSheetsAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfCopies, Ana_NoOfViewports, Ana_SheetNumber, Ana_SheetName); DialogResult = DialogResult.OK; } if (thisForm.DialogResult == DialogResult.Yes) { LoadSheets(); // get analytics data useTime.Stop(); UseTimeElapseS = useTime.Elapsed.Seconds.ToString(); Utilities.GetAnalyticsCSV(m_doc, m_app); Data.Helpers.DuplicateSheetsAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfCopies, Ana_NoOfViewports, Ana_SheetNumber, Ana_SheetName); useTime.Restart(); // reset use time and start time counter again } } #endregion } }
/// <summary> /// Duplicates the input sheet a number of times. It allows for ViewDuplicateOption for dependent views. /// </summary> /// <param name="m_doc"></param> /// <param name="sourceSheet"></param> /// <param name="copies"></param> /// <param name="dependentOption"></param> private void DuplicateSheets(Document m_doc, ViewSheet sourceSheet, int copies, ViewDuplicateOption dependentOption) { // get Title Block FamilyInstance titleBlock = new FilteredElementCollector(m_doc) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_TitleBlocks) .Cast <FamilyInstance>() .First(q => q.OwnerViewId == sourceSheet.Id); using (TransactionGroup tg = new TransactionGroup(m_doc, "Duplicate Sheet")) { tg.Start(); for (int i = 0; i < copies; i++) { // create unique sheet number string uniqueSheetNumber = Data.Helpers.CreateUniqueSheetNumber(m_doc, sourceSheet); using (Transaction t = new Transaction(m_doc, "Duplicate Sheet")) { t.Start(); // create new SHEET, new NUMBER and new NAME ViewSheet newSheet = ViewSheet.Create(m_doc, titleBlock.GetTypeId()); newSheet.SheetNumber = uniqueSheetNumber; newSheet.Name = sourceSheet.Name; #region Loop through viewports (except schedules) because GetAllPlacedViews() does not return Schedules foreach (ElementId eid in sourceSheet.GetAllPlacedViews()) { // get view element Autodesk.Revit.DB.View sourceView = m_doc.GetElement(eid) as Autodesk.Revit.DB.View; Autodesk.Revit.DB.View newView = null; // declare newView variable // DUPLICATE views // if view element is legend newView is equal to sourceView if (sourceView.ViewType == ViewType.Legend) { newView = sourceView; } else // for non-legend views { if (sourceView.GetPrimaryViewId() == ElementId.InvalidElementId) // if parent view { ElementId newViewId = sourceView.Duplicate(ViewDuplicateOption.WithDetailing); newView = m_doc.GetElement(newViewId) as Autodesk.Revit.DB.View; newView.Name = Data.Helpers.CreateUniqueViewName(m_doc, sourceView); //newView.ChangeTypeId(sourceTypeId); } else // if dependent view { ElementId newViewId = sourceView.Duplicate(dependentOption); newView = m_doc.GetElement(newViewId) as Autodesk.Revit.DB.View; newView.Name = Data.Helpers.CreateUniqueViewName(m_doc, sourceView); //newView.ChangeTypeId(sourceTypeId); } } // CREATE viewport and MOVE it foreach (Viewport vp in new FilteredElementCollector(m_doc).OfClass(typeof(Viewport))) { if (vp.SheetId == sourceSheet.Id && vp.ViewId == sourceView.Id) { XYZ sourceCenter = vp.GetBoxCenter(); ElementId sourceTypeId = vp.GetTypeId(); Viewport newViewport = Viewport.Create(m_doc, newSheet.Id, newView.Id, XYZ.Zero); newViewport.ChangeTypeId(sourceTypeId); Ana_NoOfViewports += 1; // add 1 to the viewport counter XYZ newCenter = newViewport.GetBoxCenter(); ElementTransformUtils.MoveElement(m_doc, newViewport.Id, new XYZ( sourceCenter.X - newCenter.X, sourceCenter.Y - newCenter.Y, 0)); } } } #endregion #region Loop through schedules foreach (ScheduleSheetInstance si in (new FilteredElementCollector(m_doc).OfClass(typeof(ScheduleSheetInstance)))) { if (si.OwnerViewId == sourceSheet.Id) { if (!si.IsTitleblockRevisionSchedule) { foreach (ViewSchedule viewSchedule in new FilteredElementCollector(m_doc).OfClass(typeof(ViewSchedule))) { if (si.ScheduleId == viewSchedule.Id) { XYZ sourceCenter = si.Point; ScheduleSheetInstance newSSheetInstance = ScheduleSheetInstance.Create(m_doc, newSheet.Id, viewSchedule.Id, XYZ.Zero); XYZ newCenter = newSSheetInstance.Point; ElementTransformUtils.MoveElement(m_doc, newSSheetInstance.Id, new XYZ( sourceCenter.X - newCenter.X, sourceCenter.Y - newCenter.Y, 0)); } } } } } #endregion t.Commit(); } } tg.Assimilate(); } }
public static void BatchDuplicateViews(Document curDoc) { int counter = 0; //open form using (frmDupViews curForm = new frmDupViews(curDoc)) { //show form curForm.ShowDialog(); if (curForm.DialogResult == System.Windows.Forms.DialogResult.Cancel) { //Result.Cancelled return; } else { if (curForm.getSelectedViews().Count > 0) { //get selected view and view type List <clsView> viewList = curForm.getSelectedViews(); //create transaction using (Transaction curTrans = new Transaction(curDoc, "Current Transaction")) { if (curTrans.Start() == TransactionStatus.Started) { //loop through view list and dup views foreach (clsView tmpView in viewList) { //get view from view name and view type View curView = getViewByNameAndType(curDoc, tmpView.viewType, tmpView.viewName); //duplicate view if (curView != null) { //set duplication settings based on user selection ViewDuplicateOption dupOptions = default(ViewDuplicateOption); switch (curForm.getDuplicateType()) { case "duplicate": dupOptions = ViewDuplicateOption.Duplicate; break; case "detailing": dupOptions = ViewDuplicateOption.WithDetailing; break; case "dependent": dupOptions = ViewDuplicateOption.AsDependent; break; } //loop through dup count and duplicate views for (int i = 1; i <= curForm.getNumDupes(); i++) { //duplicate view try { curView.Duplicate(dupOptions); counter = counter + 1; } catch (Exception ex) { TaskDialog.Show("Error", "Could not duplicate view."); throw; } } } } } //commit changes curTrans.Commit(); } //alert user TaskDialog.Show("Complete", "Created " + counter + " view duplicates."); } else { //no views to duplicate TaskDialog.Show("Error", "Please select views to duplicate."); return; } } } }
}//main //以下为各种method---------------------------------------- //复制视图 public Autodesk.Revit.DB.View CreateDependentCopy(Document doc, ElementId eleId, ViewDuplicateOption Duplicate) { Autodesk.Revit.DB.View vie = doc.GetElement(eleId) as Autodesk.Revit.DB.View; Autodesk.Revit.DB.View dependView = null; ElementId newViewId = null; if (vie.CanViewBeDuplicated(Duplicate)) { newViewId = vie.Duplicate(Duplicate); dependView = doc.GetElement(newViewId) as Autodesk.Revit.DB.View; return(dependView); } else { TaskDialog.Show("Wrong", vie.Name + "视图不可以被复制"); return(dependView); } }