private bool DuplicatePlanView(ModelInfo sModel, ModelInfo rModel, PlanViewInfo planInfo, ViewFamilyType vFamilyType, out PlanViewInfo createdPlanInfo) { bool duplicated = false; createdPlanInfo = null; try { Document sourceDoc = sModel.ModelDoc; Document recipientDoc = rModel.ModelDoc; using (Transaction trans = new Transaction(recipientDoc)) { trans.Start("Create Plan View"); try { ViewPlan createdView = null; ElementId levelId = GetLinkedItem(sModel, rModel, MapType.Level, planInfo.LevelId); if (levelId != ElementId.InvalidElementId) { if (planInfo.PlanViewType == ViewType.AreaPlan) { ElementId areaSchemeId = GetLinkedItem(sModel, rModel, MapType.AreaScheme, planInfo.AreaSchemeId); if (areaSchemeId != ElementId.InvalidElementId) { createdView = ViewPlan.CreateAreaPlan(recipientDoc, areaSchemeId, levelId); } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Area Scheme", ""); missingItems.Add(missingItem); } } else { createdView = ViewPlan.Create(recipientDoc, vFamilyType.Id, levelId); } if (null != createdView) { if (CanHaveViewName(rModel, planInfo.ViewName)) { createdView.Name = planInfo.ViewName; } createdView.CropBoxActive = planInfo.IsCropBoxOn; createdView.CropBox = planInfo.CropBox; createdView.DisplayStyle = planInfo.Display; foreach (string paramName in planInfo.ViewParameters.Keys) { Parameter sourceParam = planInfo.ViewParameters[paramName]; Parameter recipientParam = createdView.LookupParameter(paramName); if (parametersToSkip.Contains(sourceParam.Id.IntegerValue)) { continue; } if (null != recipientParam && sourceParam.HasValue) { if (!recipientParam.IsReadOnly) { switch (sourceParam.StorageType) { case StorageType.Double: try { recipientParam.Set(sourceParam.AsDouble()); } catch { } break; case StorageType.ElementId: /*try { recipientParam.Set(sourceParam.AsElementId()); } * catch { }*/ break; case StorageType.Integer: try { recipientParam.Set(sourceParam.AsInteger()); } catch { } break; case StorageType.String: try { recipientParam.Set(sourceParam.AsString()); } catch { } break; } } } } if (planInfo.ViewTemplateId != ElementId.InvalidElementId) { ElementId templateId = GetLinkedItem(sModel, rModel, MapType.ViewTemplate, planInfo.ViewTemplateId); if (templateId != ElementId.InvalidElementId && createdView.IsValidViewTemplate(templateId)) { createdView.ViewTemplateId = templateId; } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "View Template", ""); missingItems.Add(missingItem); } } if (planInfo.ScopeBoxId != ElementId.InvalidElementId) { ElementId scopeboxId = GetLinkedItem(sModel, rModel, MapType.ScopeBox, planInfo.ScopeBoxId); if (scopeboxId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP); if (null != param) { param.Set(scopeboxId); } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Scope Box", ""); missingItems.Add(missingItem); } } if (planInfo.PhaseId != ElementId.InvalidElementId) { ElementId phaseId = GetLinkedItem(sModel, rModel, MapType.Phase, planInfo.PhaseId); if (phaseId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEW_PHASE); if (null != param) { param.Set(phaseId); } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Phase", ""); missingItems.Add(missingItem); } } if (viewConfig.ApplyWorksetVisibility && planInfo.WorksetVisibilities.Count > 0) { bool worksetFound = true; foreach (WorksetId wsId in planInfo.WorksetVisibilities.Keys) { WorksetVisibility wsVisibility = planInfo.WorksetVisibilities[wsId]; WorksetId worksetId = GetLinkedWorkset(sModel, rModel, wsId); if (worksetId != WorksetId.InvalidWorksetId) { createdView.SetWorksetVisibility(worksetId, wsVisibility); } else { worksetFound = false; } } if (!worksetFound) { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Workset", ""); missingItems.Add(missingItem); } } createdPlanInfo = new PlanViewInfo(createdView); createdPlanInfo.LinkedViewId = planInfo.ViewId; createdPlanInfo.Linked = true; duplicated = true; } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Level", planInfo.LevelName); missingItems.Add(missingItem); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); string message = ex.Message; } } } catch (Exception ex) { MessageBox.Show(planInfo.ViewName + ": Failed to duplicate a plan view.\n" + ex.Message, "Duplicate Plan View", MessageBoxButton.OK, MessageBoxImage.Warning); } return(duplicated); }