private void DisplayPlanView(ModelInfo sModelInfo, ModelInfo rModelInfo, ViewType selectedType) { try { var sViews = from sView in sModelInfo.PlanViews.Values where sView.PlanViewType == selectedType select sView; var rViews = from rView in rModelInfo.PlanViews.Values where rView.PlanViewType == selectedType select rView; if (sViews.Count() > 0 && rViews.Count() > 0) { List <PlanViewInfo> sourceViews = sViews.ToList(); List <PlanViewInfo> recipientViews = rViews.ToList(); foreach (PlanViewInfo pvi in recipientViews) { var foundMap = from rv in sourceViews where rv.ViewName == pvi.ViewName select rv; if (foundMap.Count() > 0) { PlanViewInfo foundInfo = foundMap.First(); PlanViewInfo sourceInfo = new PlanViewInfo(foundInfo); sourceInfo.LinkedViewId = pvi.ViewId; sourceInfo.Linked = true; sModelInfo.PlanViews.Remove(sourceInfo.ViewId); sModelInfo.PlanViews.Add(sourceInfo.ViewId, sourceInfo); PlanViewInfo recipientInfo = new PlanViewInfo(pvi); recipientInfo.LinkedViewId = sourceInfo.ViewId; recipientInfo.Linked = true; rModelInfo.PlanViews.Remove(recipientInfo.ViewId); rModelInfo.PlanViews.Add(recipientInfo.ViewId, recipientInfo); } } } dataGridSource.ItemsSource = null; sViews = from sView in sModelInfo.PlanViews.Values where sView.PlanViewType == selectedType select sView; if (sViews.Count() > 0) { List <PlanViewInfo> sourceViews = sViews.OrderBy(o => o.ViewName).ToList(); dataGridSource.ItemsSource = sourceViews; } dataGridRecipient.ItemsSource = null; rViews = from rView in rModelInfo.PlanViews.Values where rView.PlanViewType == selectedType select rView; if (rViews.Count() > 0) { List <PlanViewInfo> recipientViews = rViews.OrderBy(o => o.ViewName).ToList(); dataGridRecipient.ItemsSource = recipientViews; } } catch (Exception ex) { MessageBox.Show("Failed to display plan views.\n" + ex.Message, "Display Plan Views", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public PlanViewInfo(PlanViewInfo info) { ViewId = info.ViewId; ViewName = info.ViewName; PlanViewType = info.PlanViewType; LinkedViewId = info.LinkedViewId; Linked = info.Linked; LevelId = info.LevelId; LevelName = info.LevelName; ViewTemplateId = info.ViewTemplateId; ScopeBoxId = info.ScopeBoxId; PhaseId = info.PhaseId; AreaSchemeId = info.AreaSchemeId; IsCropBoxOn = info.IsCropBoxOn; CropBox = info.CropBox; Display = info.Display; ViewParameters = info.ViewParameters; IsSelected = info.IsSelected; }
private void buttonNone_Click(object sender, RoutedEventArgs e) { try { if (selectedViewType == ViewType.ThreeD) { List <CameraViewInfo> cameraViews = (List <CameraViewInfo>)dataGridSource.ItemsSource; for (int i = cameraViews.Count - 1; i > -1; i--) { CameraViewInfo cameraView = cameraViews[i]; cameraView.IsSelected = false; cameraViews.RemoveAt(i); cameraViews.Insert(i, cameraView); } dataGridSource.ItemsSource = null; dataGridSource.ItemsSource = cameraViews; } else { List <PlanViewInfo> planViews = (List <PlanViewInfo>)dataGridSource.ItemsSource; for (int i = planViews.Count - 1; i > -1; i--) { PlanViewInfo planView = planViews[i]; planView.IsSelected = false; planViews.RemoveAt(i); planViews.Insert(i, planView); } dataGridSource.ItemsSource = null; dataGridSource.ItemsSource = planViews; } } catch (Exception ex) { MessageBox.Show("Failed to uncheck all items.\n" + ex.Message, "Uncheck All", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void GetPlanViews() { try { var collector = new FilteredElementCollector(ModelDoc); var viewPlans = collector.OfClass(typeof(ViewPlan)).ToElements().Cast <ViewPlan>().ToList(); foreach (var pView in viewPlans) { if (pView.IsTemplate) { continue; } var parentParam = pView.get_Parameter(BuiltInParameter.SECTION_PARENT_VIEW_NAME); if (null != parentParam) { if (parentParam.HasValue) { continue; } } if (!PlanViews.ContainsKey(pView.Id.IntegerValue)) { var pvi = new PlanViewInfo(pView); if (worksetIds.Count > 0) { pvi.GetWorksetVisibilities(pView, worksetIds); } PlanViews.Add(pvi.ViewId, pvi); } } } catch (Exception ex) { MessageBox.Show("Failed to get plan views.\n" + ex.Message, "Get Plan Views", MessageBoxButton.OK, MessageBoxImage.Warning); } }
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); }
private bool DuplicatePlanViews(ModelInfo sModel, ModelInfo rModel) { bool duplicated = false; try { List <PlanViewInfo> planViews = (List <PlanViewInfo>)dataGridSource.ItemsSource; ViewFamilyType viewFamilyType = GetViewFamilyType(rModel.ModelDoc, selectedViewFamily); using (TransactionGroup tg = new TransactionGroup(rModel.ModelDoc)) { tg.Start("Duplicate Plan Views"); try { var selectedViews = from pView in planViews where pView.IsSelected && !pView.Linked select pView; if (selectedViews.Count() > 0) { missingItems = new List <MissingItem>(); progressBar.Value = 0; progressBar.Maximum = selectedViews.Count(); UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue); double count = 0; foreach (PlanViewInfo viewInfo in selectedViews) { PlanViewInfo createdViewInfo = null; bool duplicatedView = DuplicatePlanView(sModel, rModel, viewInfo, viewFamilyType, out createdViewInfo); if (duplicatedView && null != createdViewInfo) { rModel.PlanViews.Add(createdViewInfo.ViewId, createdViewInfo); PlanViewInfo sourceViewInfo = new PlanViewInfo(viewInfo); sourceViewInfo.Linked = true; sourceViewInfo.LinkedViewId = createdViewInfo.ViewId; sourceViewInfo.IsSelected = false; sModel.PlanViews.Remove(sourceViewInfo.ViewId); sModel.PlanViews.Add(sourceViewInfo.ViewId, sourceViewInfo); } count++; Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, count }); } if (missingItems.Count > 0) { NotificationWindow notificationWindow = new NotificationWindow(missingItems); notificationWindow.Show(); } } tg.Assimilate(); } catch (Exception ex) { tg.RollBack(); MessageBox.Show("Failed to duplicate camera views.\n" + ex.Message, "Duplicate Camera Views", MessageBoxButton.OK, MessageBoxImage.Warning); } } modelDictionary.Remove(rModel.ModelId); modelDictionary.Add(rModel.ModelId, rModel); modelDictionary.Remove(sModel.ModelId); modelDictionary.Add(sModel.ModelId, sModel); int sourceSelectedIndex = comboBoxSource.SelectedIndex; int recipientSelectedIndex = comboBoxRecipient.SelectedIndex; List <ModelInfo> models = modelDictionary.Values.OrderBy(o => o.ModelName).ToList(); comboBoxSource.ItemsSource = null; comboBoxSource.ItemsSource = models; comboBoxSource.DisplayMemberPath = "ModelName"; comboBoxSource.SelectedIndex = sourceSelectedIndex; comboBoxRecipient.ItemsSource = null; comboBoxRecipient.ItemsSource = models; comboBoxRecipient.DisplayMemberPath = "ModelName"; comboBoxRecipient.SelectedIndex = recipientSelectedIndex; } catch (Exception ex) { MessageBox.Show("Failed to duplicate plan views.\n" + ex.Message, "Duplicate Plan Views", MessageBoxButton.OK, MessageBoxImage.Warning); } return(duplicated); }