예제 #1
0
 private void GetCameraViews()
 {
     try
     {
         var collector   = new FilteredElementCollector(ModelDoc);
         var threeDViews = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList();
         foreach (var view in threeDViews)
         {
             if (view.ViewType != ViewType.ThreeD)
             {
                 continue;
             }
             if (view.IsTemplate)
             {
                 continue;
             }
             if (view.IsPerspective)
             {
                 var viewInfo = new CameraViewInfo(view);
                 if (worksetIds.Count > 0)
                 {
                     viewInfo.GetWorksetVisibilities(view, worksetIds);
                 }
                 if (!CameraViews.ContainsKey(viewInfo.ViewId))
                 {
                     CameraViews.Add(viewInfo.ViewId, viewInfo);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to get camera views.\n" + ex.Message, "Get Camera Views", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
예제 #2
0
 public CameraViewInfo(CameraViewInfo vInfo)
 {
     ViewId              = vInfo.ViewId;
     ViewName            = vInfo.ViewName;
     LinkedViewId        = vInfo.LinkedViewId;
     Linked              = vInfo.Linked;
     ViewTemplateId      = vInfo.ViewTemplateId;
     PhaseId             = vInfo.PhaseId;
     WorksetVisibilities = vInfo.WorksetVisibilities;
     Orientation         = vInfo.Orientation;
     CropBox             = vInfo.CropBox;
     Display             = vInfo.Display;
     ViewParameters      = vInfo.ViewParameters;
     IsSelected          = vInfo.IsSelected;
 }
예제 #3
0
        private void DisplayCameraView(ModelInfo sModelInfo, ModelInfo rModelInfo)
        {
            try
            {
                List <CameraViewInfo> sourceViews    = sModelInfo.CameraViews.Values.ToList();
                List <CameraViewInfo> recipientViews = rModelInfo.CameraViews.Values.ToList();
                foreach (CameraViewInfo cvi in recipientViews)
                {
                    var foundMap = from sv in sourceViews where sv.ViewName == cvi.ViewName select sv;
                    if (foundMap.Count() > 0)
                    {
                        CameraViewInfo foundInfo = foundMap.First(); //sourceView

                        CameraViewInfo sourceInfo = new CameraViewInfo(foundInfo);
                        sourceInfo.LinkedViewId = cvi.ViewId;
                        sourceInfo.Linked       = true;
                        sModelInfo.CameraViews.Remove(sourceInfo.ViewId);
                        sModelInfo.CameraViews.Add(sourceInfo.ViewId, sourceInfo);

                        CameraViewInfo recipientInfo = new CameraViewInfo(cvi);
                        recipientInfo.LinkedViewId = sourceInfo.ViewId;
                        recipientInfo.Linked       = true;
                        rModelInfo.CameraViews.Remove(recipientInfo.ViewId);
                        rModelInfo.CameraViews.Add(recipientInfo.ViewId, recipientInfo);
                    }
                }

                dataGridSource.ItemsSource = null;
                sourceViews = sModelInfo.CameraViews.Values.OrderBy(o => o.ViewName).ToList();
                dataGridSource.ItemsSource = sourceViews;

                dataGridRecipient.ItemsSource = null;
                recipientViews = rModelInfo.CameraViews.Values.OrderBy(o => o.ViewName).ToList();
                dataGridRecipient.ItemsSource = recipientViews;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display the list of camera view.\n" + ex.Message, "Display Camera View", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        private bool DuplicateCameraView(ModelInfo sModel, ModelInfo rModel, CameraViewInfo cameraInfo, ViewFamilyType vFamilyType, out CameraViewInfo createdViewInfo)
        {
            bool duplicated = false;

            createdViewInfo = null;
            try
            {
                Document sourceDoc    = sModel.ModelDoc;
                Document recipientDoc = rModel.ModelDoc;

                using (Transaction trans = new Transaction(recipientDoc))
                {
                    trans.Start("Create Camera View");
                    try
                    {
                        View3D createdView = View3D.CreatePerspective(recipientDoc, vFamilyType.Id);
                        if (CanHaveViewName(rModel, cameraInfo.ViewName))
                        {
                            createdView.Name = cameraInfo.ViewName;
                        }
                        createdView.SetOrientation(cameraInfo.Orientation);
                        createdView.CropBoxActive      = cameraInfo.IsCropBoxOn;
                        createdView.CropBox            = cameraInfo.CropBox;
                        createdView.IsSectionBoxActive = cameraInfo.IsSectionBoxOn;
                        createdView.SetSectionBox(cameraInfo.SectionBox);
                        createdView.DisplayStyle = cameraInfo.Display;
                        //createdView.SetRenderingSettings(cameraInfo.Rendering);

                        foreach (string paramName in cameraInfo.ViewParameters.Keys)
                        {
                            Parameter sourceParam    = cameraInfo.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 (cameraInfo.ViewTemplateId != ElementId.InvalidElementId)
                        {
                            ElementId templateId = GetLinkedItem(sModel, rModel, MapType.ViewTemplate, cameraInfo.ViewTemplateId);
                            if (templateId != ElementId.InvalidElementId && createdView.IsValidViewTemplate(templateId))
                            {
                                createdView.ViewTemplateId = templateId;
                            }
                            else
                            {
                                MissingItem missingItem = new MissingItem(cameraInfo.ViewName, "View Template", "");
                                missingItems.Add(missingItem);
                            }
                        }

                        if (cameraInfo.PhaseId != ElementId.InvalidElementId)
                        {
                            ElementId phaseId = GetLinkedItem(sModel, rModel, MapType.Phase, cameraInfo.PhaseId);
                            if (phaseId != ElementId.InvalidElementId)
                            {
                                Parameter param = createdView.get_Parameter(BuiltInParameter.VIEW_PHASE);
                                if (null != param)
                                {
                                    param.Set(phaseId);
                                }
                            }
                            else
                            {
                                MissingItem missingItem = new MissingItem(cameraInfo.ViewName, "Phase", "");
                                missingItems.Add(missingItem);
                            }
                        }

                        if (viewConfig.ApplyWorksetVisibility && cameraInfo.WorksetVisibilities.Count > 0)
                        {
                            bool worksetFound = true;
                            foreach (WorksetId wsId in cameraInfo.WorksetVisibilities.Keys)
                            {
                                WorksetVisibility wsVisibility = cameraInfo.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(cameraInfo.ViewName, "Workset", "");
                                missingItems.Add(missingItem);
                            }
                        }

                        createdViewInfo = new CameraViewInfo(createdView);
                        createdViewInfo.LinkedViewId = cameraInfo.ViewId;
                        createdViewInfo.Linked       = true;
                        duplicated = true;
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.RollBack();
                        string message = ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to duplicate camera views.\n" + ex.Message, "Duplicate Camera Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(duplicated);
        }
예제 #6
0
        private bool DuplicateCameraViews(ModelInfo sModel, ModelInfo rModel)
        {
            bool duplicated = false;

            try
            {
                List <CameraViewInfo> cameraViews    = (List <CameraViewInfo>)dataGridSource.ItemsSource;
                ViewFamilyType        viewFamilyType = GetViewFamilyType(rModel.ModelDoc, selectedViewFamily);

                using (TransactionGroup tg = new TransactionGroup(rModel.ModelDoc))
                {
                    tg.Start("Duplicate Camera Views");
                    try
                    {
                        var selectedViews = from cView in cameraViews where cView.IsSelected && !cView.Linked select cView;
                        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 (CameraViewInfo viewInfo in selectedViews)
                            {
                                CameraViewInfo createdViewInfo = null;
                                bool           duplicatedView  = DuplicateCameraView(sModel, rModel, viewInfo, viewFamilyType, out createdViewInfo);
                                if (duplicatedView && null != createdViewInfo)
                                {
                                    rModel.CameraViews.Add(createdViewInfo.ViewId, createdViewInfo);

                                    CameraViewInfo sourceViewInfo = new CameraViewInfo(viewInfo);
                                    sourceViewInfo.Linked       = true;
                                    sourceViewInfo.LinkedViewId = createdViewInfo.ViewId;
                                    sourceViewInfo.IsSelected   = false;
                                    sModel.CameraViews.Remove(sourceViewInfo.ViewId);
                                    sModel.CameraViews.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 camera views.\n" + ex.Message, "Duplicate Camera Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(duplicated);
        }