private static View3D createView3D(string prefix, BoundedViewCreator boundedViewCreator, int demandViewScale, OverrideGraphicSettings modelElementsOgs)
        {
            string _fullViewName = boundedViewCreator.GetViewName(prefix, "FP");
            View3D _view3D       = boundedViewCreator.CreateView3D(demandViewScale, _fullViewName);

            _view3D.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
            _view3D.SetCategoryHidden(new ElementId(BuiltInCategory.OST_SectionBox), true);
            _view3D.SetCategoryHidden(new ElementId(BuiltInCategory.OST_Levels), true);
            _view3D.SetCategoryHidden(new ElementId(BuiltInCategory.OST_Floors), true);
            _view3D.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_StructuralColumns), modelElementsOgs);
            _view3D.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_StructuralFraming), modelElementsOgs);
            _view3D.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Walls), modelElementsOgs);
            _view3D.SetOrientation(new ViewOrientation3D(_view3D.Origin, new XYZ(0, 1, 0), new XYZ(0, 0, -1)));
            _view3D.AreAnalyticalModelCategoriesHidden = true;
            return(_view3D);
        }
Ejemplo n.º 2
0
        public static View3D Create3DView(Document doc)
        {
            View3D view = null;

            try
            {
                using (Transaction t = new Transaction(doc, "Create view"))
                {
                    t.Start();
                    //Find a 3D view type
                    var collector       = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));
                    var viewFamilyTypes = from elem in collector
                                          let vftype = elem as ViewFamilyType
                                                       where vftype.ViewFamily == ViewFamily.ThreeDimensional
                                                       select vftype;
                    // Create a new View3D
                    if (viewFamilyTypes.Count() == 0)
                    {
                        return(null);
                    }
                    view = View3D.CreateIsometric(doc, viewFamilyTypes.First().Id);

                    if (view.CanModifyViewDiscipline())
                    {
                        view.Discipline = ViewDiscipline.Coordination;
                    }
                    if (view.CanModifyDetailLevel())
                    {
                        view.DetailLevel = ViewDetailLevel.Fine;
                    }
                    if (view.CanModifyDisplayStyle())
                    {
                        view.DisplayStyle = DisplayStyle.Realistic;
                    }

                    // show all categories
                    foreach (Category cat in doc.Settings.Categories)
                    {
                        if (view.GetCategoryHidden(cat.Id))
                        {
                            view.SetCategoryHidden(cat.Id, false);
                        }
                    }
                    // hide annotations
                    view.AreAnnotationCategoriesHidden = true;

                    // disable the crop box or section box
                    view.CropBoxActive      = false;
                    view.CropBoxVisible     = false;
                    view.IsSectionBoxActive = false;

                    t.Commit();
                }
                return(view);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
 // Token: 0x060000B6 RID: 182 RVA: 0x0000C1E0 File Offset: 0x0000A3E0
 private void buttonShowPatterns_Click(object sender, EventArgs e)
 {
     try
     {
         this.m_AllViews.FindPatterns = true;
         Autodesk.Revit.ApplicationServices.Application application = this.p_commandData.Application.Application;
         Document document = this.p_commandData.Application.ActiveUIDocument.Document;
         FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
         ICollection <Element>    collection = filteredElementCollector.OfClass(typeof(View3D)).ToElements();
         View3D view3D = null;
         FilteredElementCollector filteredElementCollector2 = new FilteredElementCollector(document);
         ICollection <Element>    collection2 = filteredElementCollector2.OfClass(typeof(View3D)).ToElements();
         FilteredElementCollector filteredElementCollector3 = new FilteredElementCollector(document);
         ICollection <Element>    collection3 = filteredElementCollector3.OfClass(typeof(FamilySymbol)).ToElements();
         FilteredElementCollector filteredElementCollector4 = new FilteredElementCollector(document);
         ICollection <Element>    collection4 = filteredElementCollector4.OfClass(typeof(FamilySymbol)).ToElements();
         FilteredElementCollector filteredElementCollector5 = new FilteredElementCollector(document);
         ICollection <Element>    collection5 = filteredElementCollector5.OfClass(typeof(FamilyInstance)).ToElements();
         List <string>            list        = new List <string>();
         MessageBoxIcon           icon        = MessageBoxIcon.Exclamation;
         MessageBoxButtons        buttons     = MessageBoxButtons.OK;
         string caption  = "ef | Export To Unity";
         int    num      = 1;
         bool   @checked = this.radioButtonSingleObject.Checked;
         if (@checked)
         {
             num = 1;
         }
         bool checked2 = this.radioButtonByTypes.Checked;
         if (checked2)
         {
             num = 5;
         }
         bool checked3 = this.radioButtonMaterialsFast.Checked;
         if (checked3)
         {
             num = 6;
         }
         bool flag  = false;
         bool flag2 = document.ActiveView.ViewType != ViewType.ThreeD;
         if (flag2)
         {
             MessageBox.Show("The active view must be a 3D view type.");
             base.Close();
         }
         bool flag3 = document.ActiveView.ViewType == ViewType.ThreeD & document.ActiveView.IsTemplate;
         if (flag3)
         {
             MessageBox.Show("The active view is a template view and is not exportable.");
             flag = true;
             base.Close();
         }
         bool flag4 = document.ActiveView.ViewType == ViewType.ThreeD & !document.ActiveView.IsTemplate;
         if (flag4)
         {
             view3D = (document.ActiveView as View3D);
         }
         bool checked4 = this.checkBoxStartVU.Checked;
         if (checked4)
         {
         }
         Transaction transaction = new Transaction(document);
         transaction.Start("HideAnnotations");
         foreach (object obj in document.Settings.Categories)
         {
             Category category = (Category)obj;
             bool     flag5    = category.get_AllowsVisibilityControl(view3D);
             if (flag5)
             {
                 bool flag6 = category.CategoryType != CategoryType.Model;
                 if (flag6)
                 {
                     view3D.SetCategoryHidden(category.Id, true);
                 }
             }
         }
         transaction.Commit();
         int  num2  = 500000;
         int  num3  = 2000000;
         int  num4  = num3 * 2;
         bool flag7 = !this.checkBoxMaxVertices.Checked;
         if (flag7)
         {
             bool flag8 = !flag;
             if (flag8)
             {
                 bool flag9 = view3D != null;
                 if (flag9)
                 {
                     CheckExportContext checkExportContext = new CheckExportContext(document, this.m_AllViews);
                     new CustomExporter(document, checkExportContext)
                     {
                         IncludeGeometricObjects = false,
                         ShouldStopOnError       = false
                     }.Export(view3D);
                     this.m_AllViews.GroupingOptions = 0;
                     bool checked5 = this.radioButtonSingleObject.Checked;
                     if (checked5)
                     {
                         this.m_AllViews.GroupingOptions = 3;
                     }
                     bool checked6 = this.radioButtonByTypes.Checked;
                     if (checked6)
                     {
                         this.m_AllViews.GroupingOptions = 5;
                     }
                     bool checked7 = this.radioButtonMaterialsFast.Checked;
                     if (checked7)
                     {
                         this.m_AllViews.GroupingOptions = 6;
                     }
                     bool flag10 = checkExportContext.TotalNBofPoints > num2;
                     if (flag10)
                     {
                         DialogResult dialogResult = MessageBox.Show("Cette vue contient " + checkExportContext.TotalNBofPoints.ToString() + " vertices.\nVoulez-vous vraiment continuer?", "Avertissement", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                         bool         flag11       = dialogResult == DialogResult.No;
                         if (flag11)
                         {
                             flag = true;
                         }
                     }
                     bool flag12 = checkExportContext.TotalNBofPoints > num4;
                     if (flag12)
                     {
                         MessageBox.Show(string.Concat(new string[]
                         {
                             "This 3D View contains ",
                             checkExportContext.TotalNBofPoints.ToString(),
                             " Vertices.\nMax Vertices per Export: ",
                             num4.ToString(),
                             "."
                         }), caption, buttons, icon);
                         flag = true;
                     }
                 }
             }
         }
         bool flag13 = flag;
         if (flag13)
         {
             base.Close();
         }
         bool flag14 = application.VersionNumber.Contains("2019") | application.VersionNumber.Contains("2020");
         if (flag14)
         {
             bool flag15 = !this.checkBoxMaxVertices.Checked;
             if (flag15)
             {
                 bool flag16 = view3D != null & !flag;
                 if (flag16)
                 {
                     this.context = new CheckExportContext(document, this.m_AllViews);
                     CustomExporter customExporter = new CustomExporter(document, this.context);
                     customExporter.IncludeGeometricObjects = false;
                     customExporter.ShouldStopOnError       = false;
                     try
                     {
                         this.m_AllViews.ExportSubCategories = false;
                         bool flag17 = num == 1 | num == 5 | num == 6;
                         if (flag17)
                         {
                             int num5 = 1000;
                             FilteredElementCollector filteredElementCollector6 = new FilteredElementCollector(document, view3D.Id);
                             ICollection <ElementId>  collection6 = filteredElementCollector6.ToElementIds();
                             ICollection <ElementId>  collection7 = filteredElementCollector6.ToElementIds();
                             collection7.Clear();
                             List <int> list2  = new List <int>();
                             List <int> list3  = new List <int>();
                             List <int> list4  = new List <int>();
                             bool       flag18 = false;
                             foreach (ElementId elementId in collection6)
                             {
                                 bool    flag19  = false;
                                 Element element = document.GetElement(elementId);
                                 bool    flag20  = element != null;
                                 if (flag20)
                                 {
                                     bool flag21 = element.Category != null;
                                     if (flag21)
                                     {
                                         bool flag22 = element.Category.CategoryType == CategoryType.Model;
                                         if (flag22)
                                         {
                                             flag19 = true;
                                         }
                                         bool flag23 = element.Category.Id.IntegerValue == -2001340;
                                         if (flag23)
                                         {
                                             flag18 = true;
                                         }
                                         bool flag24 = element.Category.Id.IntegerValue == -2001352;
                                         if (flag24)
                                         {
                                             flag18 = true;
                                         }
                                     }
                                     bool flag25 = element.GetTypeId() != null;
                                     if (flag25)
                                     {
                                         int  integerValue = element.GetTypeId().IntegerValue;
                                         bool flag26       = flag19 & !flag18;
                                         if (flag26)
                                         {
                                             GeometryElement geometryElement = element.get_Geometry(new Options
                                             {
                                                 ComputeReferences = true
                                             });
                                             bool flag27 = geometryElement != null;
                                             if (flag27)
                                             {
                                                 foreach (GeometryObject geometryObject in geometryElement)
                                                 {
                                                     bool flag28 = geometryObject is Solid;
                                                     if (flag28)
                                                     {
                                                         Solid solid  = geometryObject as Solid;
                                                         bool  flag29 = null != solid;
                                                         if (flag29)
                                                         {
                                                             bool flag30 = solid.Faces.Size > 0;
                                                             if (flag30)
                                                             {
                                                                 flag18 = true;
                                                                 break;
                                                             }
                                                         }
                                                     }
                                                     GeometryInstance geometryInstance = geometryObject as GeometryInstance;
                                                     bool             flag31           = null != geometryInstance;
                                                     if (flag31)
                                                     {
                                                         foreach (GeometryObject geometryObject2 in geometryInstance.SymbolGeometry)
                                                         {
                                                             Solid solid2 = geometryObject2 as Solid;
                                                             bool  flag32 = null != solid2;
                                                             if (flag32)
                                                             {
                                                                 bool flag33 = solid2.Faces.Size > 0;
                                                                 if (flag33)
                                                                 {
                                                                     flag18 = true;
                                                                     break;
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         bool flag34 = !list2.Contains(integerValue) && flag18;
                                         if (flag34)
                                         {
                                             list2.Add(integerValue);
                                         }
                                     }
                                 }
                                 flag18 = false;
                             }
                             for (int i = 0; i < list2.Count; i++)
                             {
                                 int  item   = list2[i];
                                 int  num6   = 0;
                                 bool flag35 = num6 <= num5;
                                 if (flag35)
                                 {
                                     list4.Add(item);
                                 }
                                 bool flag36 = num6 > num5;
                                 if (flag36)
                                 {
                                     list3.Add(item);
                                 }
                             }
                             bool flag37 = list4.Count > 0;
                             if (flag37)
                             {
                                 bool flag38 = false;
                                 foreach (ElementId elementId2 in collection6)
                                 {
                                     Element element2 = document.GetElement(elementId2);
                                     bool    flag39   = element2 != null;
                                     if (flag39)
                                     {
                                         int  integerValue2 = element2.GetTypeId().IntegerValue;
                                         bool flag40        = !list4.Contains(integerValue2);
                                         if (flag40)
                                         {
                                             bool flag41 = element2.Category != null;
                                             if (flag41)
                                             {
                                                 bool flag42 = element2.Category.Id.IntegerValue == -2001340;
                                                 if (flag42)
                                                 {
                                                     flag38 = true;
                                                 }
                                             }
                                             bool flag43 = !flag18;
                                             if (flag43)
                                             {
                                                 GeometryElement geometryElement2 = element2.get_Geometry(new Options
                                                 {
                                                     ComputeReferences = true
                                                 });
                                                 bool flag44 = geometryElement2 != null;
                                                 if (flag44)
                                                 {
                                                     foreach (GeometryObject geometryObject3 in geometryElement2)
                                                     {
                                                         bool flag45 = geometryObject3 is Solid;
                                                         if (flag45)
                                                         {
                                                             Solid solid3 = geometryObject3 as Solid;
                                                             bool  flag46 = null != solid3;
                                                             if (flag46)
                                                             {
                                                                 bool flag47 = solid3.Faces.Size > 0;
                                                                 if (flag47)
                                                                 {
                                                                     flag38 = true;
                                                                     break;
                                                                 }
                                                             }
                                                         }
                                                         GeometryInstance geometryInstance2 = geometryObject3 as GeometryInstance;
                                                         bool             flag48            = null != geometryInstance2;
                                                         if (flag48)
                                                         {
                                                             foreach (GeometryObject geometryObject4 in geometryInstance2.SymbolGeometry)
                                                             {
                                                                 Solid solid4 = geometryObject4 as Solid;
                                                                 bool  flag49 = null != solid4;
                                                                 if (flag49)
                                                                 {
                                                                     bool flag50 = solid4.Faces.Size > 0;
                                                                     if (flag50)
                                                                     {
                                                                         flag38 = true;
                                                                         break;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                             bool flag51 = flag38;
                                             if (flag51)
                                             {
                                                 bool flag52 = element2.CanBeHidden(view3D);
                                                 if (flag52)
                                                 {
                                                     collection7.Add(elementId2);
                                                 }
                                             }
                                         }
                                     }
                                     flag38 = false;
                                 }
                                 Transaction transaction2 = new Transaction(document);
                                 transaction2.Start("TempHideType");
                                 bool flag53 = collection7.Count > 0;
                                 if (flag53)
                                 {
                                     view3D.HideElements(collection7);
                                 }
                                 transaction2.Commit();
                                 customExporter.Export(view3D);
                                 Transaction transaction3 = new Transaction(document);
                                 transaction3.Start("TempUnhideType");
                                 bool flag54 = collection7.Count > 0;
                                 if (flag54)
                                 {
                                     view3D.UnhideElements(collection7);
                                 }
                                 transaction3.Commit();
                                 collection7.Clear();
                             }
                             bool flag55 = list3.Count > 0;
                             if (flag55)
                             {
                                 foreach (int num7 in list3)
                                 {
                                     bool flag56 = false;
                                     bool flag57 = num7 != -1;
                                     if (flag57)
                                     {
                                         foreach (ElementId elementId3 in collection6)
                                         {
                                             Element element3 = document.GetElement(elementId3);
                                             bool    flag58   = element3 != null;
                                             if (flag58)
                                             {
                                                 int  integerValue3 = element3.GetTypeId().IntegerValue;
                                                 bool flag59        = num7 != integerValue3;
                                                 if (flag59)
                                                 {
                                                     bool flag60 = element3.Category != null;
                                                     if (flag60)
                                                     {
                                                         bool flag61 = element3.Category.Id.IntegerValue == -2001340;
                                                         if (flag61)
                                                         {
                                                             flag56 = true;
                                                         }
                                                     }
                                                     bool flag62 = !flag56;
                                                     if (flag62)
                                                     {
                                                         GeometryElement geometryElement3 = element3.get_Geometry(new Options
                                                         {
                                                             ComputeReferences = true
                                                         });
                                                         bool flag63 = geometryElement3 != null;
                                                         if (flag63)
                                                         {
                                                             foreach (GeometryObject geometryObject5 in geometryElement3)
                                                             {
                                                                 bool flag64 = geometryObject5 is Solid;
                                                                 if (flag64)
                                                                 {
                                                                     Solid solid5 = geometryObject5 as Solid;
                                                                     bool  flag65 = null != solid5;
                                                                     if (flag65)
                                                                     {
                                                                         bool flag66 = solid5.Faces.Size > 0;
                                                                         if (flag66)
                                                                         {
                                                                             flag56 = true;
                                                                             break;
                                                                         }
                                                                     }
                                                                 }
                                                                 GeometryInstance geometryInstance3 = geometryObject5 as GeometryInstance;
                                                                 bool             flag67            = null != geometryInstance3;
                                                                 if (flag67)
                                                                 {
                                                                     foreach (GeometryObject geometryObject6 in geometryInstance3.SymbolGeometry)
                                                                     {
                                                                         Solid solid6 = geometryObject6 as Solid;
                                                                         bool  flag68 = null != solid6;
                                                                         if (flag68)
                                                                         {
                                                                             bool flag69 = solid6.Faces.Size > 0;
                                                                             if (flag69)
                                                                             {
                                                                                 flag56 = true;
                                                                                 break;
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     bool flag70 = flag56;
                                                     if (flag70)
                                                     {
                                                         bool flag71 = element3.CanBeHidden(view3D);
                                                         if (flag71)
                                                         {
                                                             collection7.Add(elementId3);
                                                         }
                                                     }
                                                 }
                                             }
                                             flag56 = false;
                                         }
                                         Transaction transaction4 = new Transaction(document);
                                         transaction4.Start("TempHideType");
                                         bool flag72 = collection7.Count > 0;
                                         if (flag72)
                                         {
                                             view3D.HideElements(collection7);
                                         }
                                         transaction4.Commit();
                                         customExporter.Export(view3D);
                                         Transaction transaction5 = new Transaction(document);
                                         transaction5.Start("TempUnhideType");
                                         bool flag73 = collection7.Count > 0;
                                         if (flag73)
                                         {
                                             view3D.UnhideElements(collection7);
                                         }
                                         transaction5.Commit();
                                         collection7.Clear();
                                     }
                                 }
                             }
                         }
                     }
                     catch (ExternalApplicationException ex)
                     {
                         Debug.Print("ExternalApplicationException " + ex.Message);
                     }
                     bool flag74 = !flag;
                     if (flag74)
                     {
                         foreach (int num8 in this.context.ListMaterialID)
                         {
                             bool flag75 = num8 != ElementId.InvalidElementId.IntegerValue & !num8.ToString().Contains("-") & num8.ToString() != "-1";
                             if (flag75)
                             {
                                 ElementId elementId4 = new ElementId(num8);
                                 Material  material   = document.GetElement(elementId4) as Material;
                                 bool      flag76     = material != null;
                                 if (flag76)
                                 {
                                     FillPatternElement fillPatternElement = document.GetElement(material.SurfaceForegroundPatternId) as FillPatternElement;
                                     bool flag77 = fillPatternElement != null;
                                     if (flag77)
                                     {
                                         bool flag78 = !list.Contains(fillPatternElement.Name);
                                         if (flag78)
                                         {
                                             list.Add(fillPatternElement.Name);
                                             this.h_MatIDPatID.Add(material.Id.IntegerValue, fillPatternElement.Id.IntegerValue);
                                             this.key_MatIDPatID = this.h_MatIDPatID.Keys;
                                         }
                                     }
                                 }
                             }
                         }
                         bool flag79 = list != null;
                         if (flag79)
                         {
                             bool flag80 = list.Count > 0;
                             if (flag80)
                             {
                                 this.listBoxPatterns.DataSource = list;
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex2)
     {
         MessageBox.Show(ex2.Message);
     }
 }
Ejemplo n.º 4
0
        private OrthogonalCamera GetOrthogonalCamera(Dictionary <int, ElementProperties> elementDictionary, string imagePath)
        {
            OrthogonalCamera orthoCamera = new OrthogonalCamera();

            try
            {
                BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
                boundingBox.Enabled = true;
                for (int i = 0; i < 3; i++)
                {
                    boundingBox.set_MinEnabled(i, true);
                    boundingBox.set_MaxEnabled(i, true);
                    boundingBox.set_BoundEnabled(0, i, true);
                    boundingBox.set_BoundEnabled(1, i, true);
                }

                BoundingBoxXYZ tempBoundingBox = elementDictionary.First().Value.RevitElement.get_BoundingBox(null);
                tempBoundingBox.Enabled = true;

                double maxX = tempBoundingBox.Max.X;
                double maxY = tempBoundingBox.Max.Y;
                double maxZ = tempBoundingBox.Max.Z;
                double minX = tempBoundingBox.Min.X;
                double minY = tempBoundingBox.Min.Y;
                double minZ = tempBoundingBox.Min.Z;

                List <ElementId>           elementIds = new List <ElementId>();
                Dictionary <int, Category> categories = new Dictionary <int, Category>();
                foreach (ElementProperties ep in elementDictionary.Values)
                {
                    Element element = ep.RevitElement;
                    if (null != element)
                    {
                        try
                        {
                            if (!categories.ContainsKey(element.Category.Id.IntegerValue))
                            {
                                categories.Add(element.Category.Id.IntegerValue, element.Category);
                            }
                            BoundingBoxXYZ bbBox = element.get_BoundingBox(null);
                            bbBox.Enabled = true;
                            elementIds.Add(element.Id);
                            if (null != boundingBox)
                            {
                                if (bbBox.Max.X > maxX)
                                {
                                    maxX = bbBox.Max.X;
                                }
                                if (bbBox.Max.Y > maxY)
                                {
                                    maxY = bbBox.Max.Y;
                                }
                                if (bbBox.Max.Z > maxZ)
                                {
                                    maxZ = bbBox.Max.Z;
                                }
                                if (bbBox.Min.X < minX)
                                {
                                    minX = bbBox.Min.X;
                                }
                                if (bbBox.Min.Y < minY)
                                {
                                    minY = bbBox.Min.Y;
                                }
                                if (bbBox.Min.Z < minZ)
                                {
                                    minZ = bbBox.Min.Z;
                                }
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }

                XYZ xyzMax = new XYZ(maxX, maxY, maxZ);
                XYZ xyzMin = new XYZ(minX, minY, minZ);

                boundingBox.set_Bounds(0, xyzMin);
                boundingBox.set_Bounds(1, xyzMax);


                ViewFamilyType           view3dFamilyType = null;
                FilteredElementCollector collector        = new FilteredElementCollector(m_doc);
                List <Element>           elements         = collector.OfClass(typeof(ViewFamilyType)).ToElements().ToList();
                foreach (Element element in elements)
                {
                    ViewFamilyType viewfamilytype = element as ViewFamilyType;
                    if (viewfamilytype.ViewFamily == ViewFamily.ThreeDimensional)
                    {
                        view3dFamilyType = viewfamilytype; break;
                    }
                }

                if (null != view3dFamilyType)
                {
                    using (TransactionGroup transGroup = new TransactionGroup(m_doc))
                    {
                        transGroup.Start("Start Creating View 3D");
                        using (Transaction trans = new Transaction(m_doc))
                        {
                            trans.Start("Create View");

                            View3D view3d = View3D.CreateIsometric(m_doc, view3dFamilyType.Id);
                            view3d.SetSectionBox(boundingBox);
                            view3d.GetSectionBox().Enabled = true;
                            view3d.DetailLevel = ViewDetailLevel.Fine;

                            foreach (Category category in categories.Values)
                            {
                                if (category.get_AllowsVisibilityControl(view3d))
                                {
#if RELEASE2017 || RELEASE2018
                                    view3d.SetCategoryHidden(category.Id, false);
#else
                                    view3d.SetVisibility(category, true);
#endif
                                }
                            }

                            view3d.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set(4);

                            //m_app.ActiveUIDocument.ActiveView = view3d;
                            //m_app.ActiveUIDocument.RefreshActiveView();

                            XYZ   eyePostion = view3d.GetOrientation().EyePosition;
                            Point viewPoint  = new Point();
                            viewPoint.X = eyePostion.X; viewPoint.Y = eyePostion.Y; viewPoint.Z = eyePostion.Z;
                            orthoCamera.CameraViewPoint = viewPoint;

                            XYZ       forwardDirection = view3d.GetOrientation().ForwardDirection;
                            Direction fDirection       = new Direction();
                            fDirection.X = forwardDirection.X; fDirection.Y = forwardDirection.Y; fDirection.Z = forwardDirection.Z;
                            orthoCamera.CameraDirection = fDirection;

                            XYZ       upDirection = view3d.GetOrientation().UpDirection;
                            Direction uDirection  = new Direction();
                            uDirection.X = upDirection.X; uDirection.Y = upDirection.Y; uDirection.Z = upDirection.Z;
                            orthoCamera.CameraUpVector = uDirection;

                            orthoCamera.ViewToWorldScale = view3d.Scale;
                            m_app.ActiveUIDocument.RefreshActiveView();
                            trans.Commit();

                            trans.Start("Export Image");
                            //create snapshot.png
                            ImageExportOptions option = new ImageExportOptions();
                            option.HLRandWFViewsFileType = ImageFileType.PNG;
                            option.ImageResolution       = ImageResolution.DPI_300;
                            option.ShouldCreateWebSite   = false;
                            option.ExportRange           = ExportRange.SetOfViews;
                            option.FilePath = imagePath;
                            List <ElementId> viewIds = new List <ElementId>();
                            viewIds.Add(view3d.Id);
                            option.SetViewsAndSheets(viewIds);

                            if (ImageExportOptions.IsValidFileName(option.FilePath))
                            {
                                m_doc.ExportImage(option);
                            }
                            trans.Commit();
                        }
                        transGroup.RollBack();
                    }

                    if (File.Exists(imagePath))
                    {
                        File.Delete(imagePath);
                    }
                    string[] fileNames = Directory.GetFiles(Path.GetDirectoryName(imagePath), "snapshot*");
                    foreach (string fName in fileNames)
                    {
                        if (Path.GetExtension(fName) == ".png" || Path.GetExtension(fName) == ".jpg")
                        {
                            File.Move(fName, imagePath);
                            if (File.Exists(fName))
                            {
                                File.Delete(fName);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get the orthogonal camera.\n" + ex.Message, "Get Orthogonal Camera", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(orthoCamera);
        }