Пример #1
0
        /// <summary>
        /// Get all 3D views in current document
        /// </summary>
        private void Get3DViews()
        {
            m_view3DList = new List <Autodesk.Revit.DB.Element>();
            FilteredElementCollector collector = new FilteredElementCollector(m_document);
            var query = from elem in collector.OfClass(typeof(View3D))
                        let viewElem = elem as View3D
                                       where null != viewElem && !viewElem.IsTemplate
                                       select elem;

            m_view3DList = query.ToList <Element>();
            if (m_view3DList.Count == 0)
            {
                //View3D view3D = m_document.Create.NewView3D(new Autodesk.Revit.DB.XYZ (0, 0, 1));
                IList <Element> viewFamilyTypes = new FilteredElementCollector(m_document).OfClass(typeof(ViewFamilyType)).ToElements();
                ElementId       View3DId        = new ElementId(-1);
                foreach (Element e in viewFamilyTypes)
                {
                    if (e.Name == "3D View")
                    {
                        View3DId = e.Id;
                    }
                }
                View3D            view3D            = View3D.CreateIsometric(m_document, View3DId);
                ViewOrientation3D viewOrientation3D = new ViewOrientation3D(new XYZ(1, 1, -1), new XYZ(0, 0, 1), new XYZ(0, 1, 0));
                view3D.SetOrientation(viewOrientation3D);
                view3D.SaveOrientation();
                m_view3DList.Add(view3D);
            }
        }
        /// <summary>
        /// Get geometry of family instances and show them in Revit views
        /// </summary>
        public void GetInstanceGeometry()
        {
            FilteredElementCollector instanceCollector = new FilteredElementCollector(RevitDoc);

            instanceCollector.OfClass(typeof(FamilyInstance));

            // create views by different names
            ElementId       View3DId = new ElementId(-1);
            IList <Element> elems    = new FilteredElementCollector(RevitDoc).OfClass(typeof(ViewFamilyType)).ToElements();

            foreach (Element e in elems)
            {
                ViewFamilyType v = e as ViewFamilyType;

                if (v != null && v.ViewFamily == ViewFamily.ThreeDimensional)
                {
                    View3DId = e.Id;
                    break;
                }
            }

            //View instanceView = RevitDoc.Create.NewView3D(new XYZ(1, 1, -1));
            View3D            instanceView = View3D.CreateIsometric(RevitDoc, View3DId);
            ViewOrientation3D instanceViewOrientation3D = new ViewOrientation3D(new XYZ(-30.8272352809007, -2.44391067967133, 18.1013736367246), new XYZ(0.577350269189626, 0.577350269189626, -0.577350269189626), new XYZ(0.408248290463863, 0.408248290463863, 0.816496580927726));

            instanceView.SetOrientation(instanceViewOrientation3D);
            instanceView.SaveOrientation();
            instanceView.Name = "InstanceGeometry";

            //View originalView = RevitDoc.Create.NewView3D(new XYZ(0, 1, -1));
            View3D            originalView = View3D.CreateIsometric(RevitDoc, View3DId);
            ViewOrientation3D originalViewOrientation3D = new ViewOrientation3D(new XYZ(-19.0249866627872, -5.09536632799455, 20.7528292850478), new XYZ(0, 0.707106781186547, -0.707106781186547), new XYZ(0, 0.707106781186548, 0.707106781186548));

            originalView.SetOrientation(originalViewOrientation3D);
            originalView.SaveOrientation();
            originalView.Name = "OriginalGeometry";

            //View transView = RevitDoc.Create.NewView3D(new XYZ(-1, 1, -1));
            View3D transView = View3D.CreateIsometric(RevitDoc, View3DId);
            //ViewOrientation3D transViewOrientation3D = new ViewOrientation3D(new XYZ(-7.22273804467383, -2.44391067967133, 18.1013736367246), new XYZ(-0.577350269189626, 0.577350269189626, -0.577350269189626), new XYZ(-0.408248290463863, 0.408248290463863, 0.816496580927726));
            ViewOrientation3D transViewOrientation3D = new ViewOrientation3D(new XYZ(-19.0249866627872, -5.09536632799455, 20.7528292850478), new XYZ(0, 0.707106781186547, -0.707106781186547), new XYZ(0, 0.707106781186548, 0.707106781186548));

            transView.SetOrientation(transViewOrientation3D);
            transView.SaveOrientation();
            transView.Name = "TransformedGeometry";

            foreach (FamilyInstance instance in instanceCollector)
            {
                GeometryElement instanceGeo  = instance.get_Geometry(m_options);
                GeometryElement computedGeo  = instance.GetOriginalGeometry(m_options);
                GeometryElement transformGeo = computedGeo.GetTransformed(instance.GetTransform());

                // show family instance geometry
                //foreach (GeometryObject obj in instanceGeo.Objects)
                IEnumerator <GeometryObject> Objects = instanceGeo.GetEnumerator();
                while (Objects.MoveNext())
                {
                    GeometryObject obj = Objects.Current;

                    if (obj is Solid)
                    {
                        Solid solid = obj as Solid;
                        PaintSolid(solid, instanceView);
                    }
                }

                // show geometry that is original geometry
                //foreach (GeometryObject obj in computedGeo.Objects)
                IEnumerator <GeometryObject> Objects1 = computedGeo.GetEnumerator();
                while (Objects1.MoveNext())
                {
                    GeometryObject obj = Objects1.Current;

                    if (obj is Solid)
                    {
                        Solid solid = obj as Solid;
                        PaintSolid(solid, originalView);
                    }
                }

                // show geometry that was transformed
                //foreach (GeometryObject obj in transformGeo.Objects)
                IEnumerator <GeometryObject> Objects2 = transformGeo.GetEnumerator();
                while (Objects2.MoveNext())
                {
                    GeometryObject obj = Objects2.Current;

                    if (obj is Solid)
                    {
                        Solid solid = obj as Solid;
                        PaintSolid(solid, transView);
                    }
                }
            }
            // remove original instances to view point results.
            RevitDoc.Delete(instanceCollector.ToElementIds());
        }
Пример #3
0
        public ImageExporter(Document doc)
        {
            ViewFamilyType viewFamilyType
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(ViewFamilyType))
                  .Cast <ViewFamilyType>()
                  .FirstOrDefault(x =>
                                  x.ViewFamily == ViewFamily.ThreeDimensional);

            Debug.Assert(null != viewFamilyType);

            View3D v = View3D.CreateIsometric(
                doc, viewFamilyType.Id);

            v.Name = "Isometric";

            Debug.Assert(null != v);

            int nViews = _view_data_to_export.Length;

            _views_to_export = new List <View>(nViews)
            {
                v
            };

            for (int i = 1; i < nViews; ++i)
            {
                v = View3D.CreateIsometric(
                    doc, viewFamilyType.Id);

                object[] d = _view_data_to_export[i];

                v.Name = d[0] as string;
                v.SetOrientation(GetOrientationFor(
                                     (int)(d[2]), (int)(d[3])));
                v.SaveOrientation();

                _views_to_export.Add(v);
            }

            foreach (View v2 in _views_to_export)
            {
                Parameter graphicDisplayOptions
                    = v2.get_Parameter(
                          BuiltInParameter.MODEL_GRAPHICS_STYLE);

                // Settings for best quality

                graphicDisplayOptions.Set(6);

                // Get categories to hide

                Categories cats = doc.Settings.Categories;

                foreach (BuiltInCategory bic in _categories_to_hide)
                {
                    Category cat = cats.get_Item(bic);

                    // OST_Cameras returns a null Category
                    // object in my model

                    if (null == cat)
                    {
                        Debug.Print("{0} returns null category.", bic);
                    }
                    else
                    {
                        v2.SetCategoryHidden(cat.Id, true);
                    }

                    // BuiltInCategory.OST_Cameras throws exception:
                    // Autodesk.Revit.Exceptions.ArgumentException
                    // Category cannot be hidden.
                    // Parameter name: categoryId
                    //ElementId id = new ElementId( bic );
                    //view3d.SetCategoryHidden( id, true );
                }
            }
        }