private void TraverseGeometryInstance( GeometryInstance geomInst )
        {
            GeometryElement instGeomElem = geomInst.GetSymbolGeometry();
              foreach( GeometryObject instGeomObj in instGeomElem )
              {
            if( instGeomObj is Solid )
            {
              WriteSolid( (Solid) instGeomObj );
            }
            else if( instGeomObj is Curve )
            {
              Curve curve = (Curve) instGeomObj;
              Transaction createCurve = new Transaction( m_doc, "Create curve" );
              createCurve.Start();
              m_doc.Create.NewDetailCurve( m_targetView, curve );
              createCurve.Commit();

              if( curve.Reference != null )
              {
            m_writer.WriteLine( "Geometry curve - " + curve.Reference.ConvertToStableRepresentation( m_doc ) );
            m_referencePlaneReferences.Add( curve );
              }
              else
            m_writer.WriteLine( "Geometry curve - but reference is null" );
            }

            else
            {
              m_writer.WriteLine( "Something else - " + instGeomObj.GetType().Name );
            }
              }
        }
        public void GetSolidsFromSymbol(FamilyInstance familyInstance, ref List <Solid> solids)
        {
            Options option = new Options();

            option.ComputeReferences        = true;
            option.IncludeNonVisibleObjects = true;
            option.DetailLevel = ViewDetailLevel.Undefined;
            if (familyInstance != null)
            {
                GeometryElement geoElement = familyInstance.get_Geometry(option);
                foreach (GeometryObject geoObject in geoElement)
                {
                    GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance;
                    if (null != instance)
                    {
                        Transform       transform = familyInstance.GetTransform();
                        GeometryElement instanTVDCEGeometryElement = instance.GetSymbolGeometry(transform);
                        foreach (GeometryObject instObj in instanTVDCEGeometryElement)
                        {
                            // Try to find solid
                            Solid solid = instObj as Solid;
                            if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size)
                            {
                                continue;
                            }
                            if (!solids.Contains(solid))
                            {
                                solids.Add(solid);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public static Curve GetCurveminfamily(FamilyInstance familyInstance)
        {
            IList <Curve> alllines  = new List <Curve>();
            Curve         curvesmin = null;
            Options       option    = new Options();

            option.ComputeReferences        = true;
            option.IncludeNonVisibleObjects = false;
            if (familyInstance != null)
            {
                GeometryElement geoElement = familyInstance.get_Geometry(option);
                foreach (GeometryObject geoObject in geoElement)
                {
                    GeometryInstance instance = geoObject as GeometryInstance;
                    if (null != instance)
                    {
                        GeometryElement instanceGeometryElement = instance.GetSymbolGeometry();
                        foreach (GeometryObject o in instanceGeometryElement)
                        {
                            Line curve = o as Line;
                            if (curve != null)
                            {
                                alllines.Add(curve);
                            }
                        }
                        var membercurvmax = alllines.OrderByDescending(x => x.Length).LastOrDefault();
                        curvesmin = membercurvmax;
                    }
                }
            }
            return(curvesmin);
        }
示例#4
0
        public static Polygon GetPolygonFromFaceFamilyInstance(FamilyInstance fi)
        {
            GeometryElement geoElem = fi.get_Geometry(new Options {
                ComputeReferences = true
            });
            List <Curve> cs = new List <Curve>();

            foreach (GeometryObject geoObj in geoElem)
            {
                GeometryInstance geoIns = geoObj as GeometryInstance;
                if (geoIns == null)
                {
                    continue;
                }
                Transform tf = geoIns.Transform;
                foreach (GeometryObject geoSymObj in geoIns.GetSymbolGeometry())
                {
                    Curve c = geoSymObj as Line;
                    if (c != null)
                    {
                        cs.Add(GeomUtil.TransformCurve(c, tf));
                    }
                }
            }
            if (cs.Count < 3)
            {
                throw new Exception("Incorrect input curve!");
            }
            return(new Polygon(cs));
        }
        private void TraverseGeometryInstance(GeometryInstance geomInst)
        {
            GeometryElement instGeomElem = geomInst.GetSymbolGeometry();

            foreach (GeometryObject instGeomObj in instGeomElem)
            {
                if (instGeomObj is Solid)
                {
                    WriteSolid((Solid)instGeomObj);
                }
                else if (instGeomObj is Curve)
                {
                    Curve       curve       = (Curve)instGeomObj;
                    Transaction createCurve = new Transaction(m_doc, "Create curve");
                    createCurve.Start();
                    m_doc.Create.NewDetailCurve(m_targetView, curve);
                    createCurve.Commit();

                    if (curve.Reference != null)
                    {
                        m_writer.WriteLine("Geometry curve - " + curve.Reference.ConvertToStableRepresentation(m_doc));
                        m_referencePlaneReferences.Add(curve);
                    }
                    else
                    {
                        m_writer.WriteLine("Geometry curve - but reference is null");
                    }
                }

                else
                {
                    m_writer.WriteLine("Something else - " + instGeomObj.GetType().Name);
                }
            }
        }
示例#6
0
        public static IList <Edge> AllEdgesBySymbol(this FamilyInstance familyInstance)
        {
            Options options = new Options();

            options.ComputeReferences = true;
            string       name     = familyInstance.Name;
            IList <Edge> edgeList = new List <Edge>();

            foreach (GeometryObject geometryObject1 in familyInstance.get_Geometry(options))
            {
                GeometryInstance geometryInstance = geometryObject1 as GeometryInstance;
                if (null != geometryInstance)
                {
                    foreach (GeometryObject geometryObject2 in geometryInstance.GetSymbolGeometry())
                    {
                        Solid solid = geometryObject2 as Solid;
                        if (!(null == solid) && solid.Faces.Size != 0 && solid.Edges.Size != 0)
                        {
                            foreach (Edge edge in solid.Edges)
                            {
                                if (edge != null)
                                {
                                    edgeList.Add(edge);
                                }
                            }
                        }
                    }
                }
            }
            return(edgeList);
        }
示例#7
0
        public static void GetSolidsOfwall(FamilyInstance familyInstance, ref List <Solid> solids)
        {
            Options options = new Options();

            options.ComputeReferences        = true;
            options.IncludeNonVisibleObjects = true;
            options.DetailLevel = ViewDetailLevel.Undefined;
            string          name            = familyInstance.Name;
            GeometryElement geometryElement = familyInstance.get_Geometry(options);
            bool            flag            = geometryElement == null;

            foreach (GeometryObject geometryObject in geometryElement)
            {
                GeometryInstance geometryInstance = geometryObject as GeometryInstance;
                bool             flag2            = null != geometryInstance;
                if (flag2)
                {
                    GeometryElement symbolGeometry = geometryInstance.GetSymbolGeometry();
                    foreach (GeometryObject geometryObject2 in symbolGeometry)
                    {
                        Solid solid = geometryObject2 as Solid;
                        bool  flag3 = null == solid || solid.Faces.Size == 0 || solid.Edges.Size == 0;
                        if (!flag3)
                        {
                            solids.Add(solid);
                        }
                    }
                }
            }
        }
示例#8
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIDocument uidoc = commandData.Application
                               .ActiveUIDocument;

            Options options = new Options();

            options.ComputeReferences = true;

            GeometryElement geomElement
                = uidoc.Selection.PickObject(
                      ObjectType.Element)
                  .Element.get_Geometry(options);

            int edgeCount = 0;

            foreach (GeometryObject geomObj
                     in geomElement.Objects)
            {
                if (geomObj is GeometryInstance)
                {
                    GeometryInstance inst = geomObj
                                            as GeometryInstance;

                    if (inst != null)
                    {
                        GeometryElement geomElem
                            = inst.GetSymbolGeometry();

                        foreach (Object o in geomElem.Objects)
                        {
                            Solid solid = o as Solid;
                            if (solid != null)
                            {
                                foreach (Face face in solid.Faces)
                                {
                                    foreach (EdgeArray edgeArray
                                             in face.EdgeLoops)
                                    {
                                        edgeCount += edgeArray.Size;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            TaskDialog.Show("Revit", "Edges: "
                            + edgeCount.ToString());

            return(Result.Succeeded);
        }
示例#9
0
        /// <summary>
        /// Obsolete, since a single element may contain
        /// more than one solid that really needs
        /// exporting, e.g. the fireplace in
        /// rac_basic_sample_project.rvt.
        /// Replaced by the ExportSolids + ExportSolid
        /// methods.
        /// Retrieve the first non-empty solid found for
        /// the given element. In case it is a family
        /// instance, it may have its own non-empty solid,
        /// in which case we use that.
        /// Otherwise we search the symbol geometry.
        /// If we use the symbol geometry, we might have
        /// to keep track of the instance transform to map
        /// it to the actual instance project location.
        /// Instead, we ask for transformed geometry to be
        /// returned, so the resulting solid is already in
        /// place.
        /// </summary>
        Solid GetSolid(Element e, Options opt)
        {
            Solid solid = null;

            GeometryElement geo = e.get_Geometry(opt);

            if (null != geo)
            {
                if (e is FamilyInstance)
                {
                    geo = geo.GetTransformed(
                        Transform.Identity);
                }

                GeometryInstance inst = null;
                //Transform t = Transform.Identity;

                // Some columns have no solids, and we have to
                // retrieve the geometry from the symbol;
                // others do have solids on the instance itself
                // and no contents in the instance geometry
                // (e.g. in rst_basic_sample_project.rvt).

                foreach (GeometryObject obj in geo)
                {
                    solid = obj as Solid;

                    if (null != solid &&
                        0 < solid.Faces.Size)
                    {
                        break;
                    }

                    inst = obj as GeometryInstance;
                }

                if (null == solid && null != inst)
                {
                    geo = inst.GetSymbolGeometry();
                    //t = inst.Transform;

                    foreach (GeometryObject obj in geo)
                    {
                        solid = obj as Solid;

                        if (null != solid &&
                            0 < solid.Faces.Size)
                        {
                            break;
                        }
                    }
                }
            }
            return(solid);
        }
示例#10
0
        /// <summary>
        /// Collects all solids and meshes within all nested levels of a given GeometryElement.
        /// </summary>
        /// <remarks>
        /// This is a private helper method for the GetSolidMeshGeometry type collection methods.
        /// </remarks>
        /// <param name="geomElem">
        /// The GeometryElement we are collecting solids and meshes from.
        /// </param>
        /// <param name="trf">
        /// The initial Transform applied on the GeometryElement.
        /// </param>
        /// <param name="solidMeshCapsule">
        /// The SolidMeshGeometryInfo object that contains the lists of collected solids and meshes.
        /// </param>
        private static void CollectSolidMeshGeometry(GeometryElement geomElem, Transform trf, SolidMeshGeometryInfo solidMeshCapsule)
        {
            if (geomElem == null)
            {
                return;
            }
            GeometryElement currGeomElem = geomElem;
            Transform       localTrf     = trf;

            if (localTrf == null)
            {
                localTrf = Transform.Identity;
            }
            else if (!localTrf.IsIdentity)
            {
                currGeomElem = geomElem.GetTransformed(localTrf);
                // The geometry element created by "GetTransformed" is a copy which will have its own allocated
                // membership - this needs to be stored and disposed of (see AllocatedGeometryObjectCache
                // for details)
                ExporterCacheManager.AllocatedGeometryObjectCache.AddGeometryObject(currGeomElem);
            }
            // iterate through the GeometryObjects contained in the GeometryElement
            foreach (GeometryObject geomObj in currGeomElem)
            {
                Solid solid = geomObj as Solid;
                if (solid != null && solid.Faces.Size > 0 && solid.Volume > 0.0)
                {
                    solidMeshCapsule.AddSolid(solid);
                }
                else
                {
                    Mesh mesh = geomObj as Mesh;
                    if (mesh != null)
                    {
                        solidMeshCapsule.AddMesh(mesh);
                    }
                    else
                    {
                        // if the current geomObj is castable as a GeometryInstance, then we perform the same collection on its symbol geometry
                        GeometryInstance inst = geomObj as GeometryInstance;
                        if (inst != null)
                        {
                            GeometryElement instanceSymbol = inst.GetSymbolGeometry();
                            if (instanceSymbol != null)
                            {
                                Transform instanceTransform = localTrf.Multiply(inst.Transform);
                                CollectSolidMeshGeometry(instanceSymbol, instanceTransform, solidMeshCapsule);
                            }
                        }
                    }
                }
            }
        }
示例#11
0
        int ExportSolids(
            IJtFaceEmitter emitter,
            Element e,
            Options opt,
            Color color,
            int shininess,
            int transparency)
        {
            int             nSolids = 0;
            GeometryElement geo     = e.get_Geometry(opt);

            Solid solid;

            if (null != geo)
            {
                Document doc = e.Document;

                if (e is FamilyInstance)
                {
                    geo = geo.GetTransformed(Transform.Identity);
                }

                GeometryInstance inst = null;
                foreach (GeometryObject obj in geo)
                {
                    solid = obj as Solid;

                    if (null != solid && 0 < solid.Faces.Size && ExportSolid(emitter, doc, solid, color, shininess, transparency))
                    {
                        ++nSolids;
                    }

                    inst = obj as GeometryInstance;
                }

                if (0 == nSolids && null != inst)
                {
                    geo = inst.GetSymbolGeometry();

                    foreach (GeometryObject obj in geo)
                    {
                        solid = obj as Solid;

                        if (null != solid && 0 < solid.Faces.Size && ExportSolid(emitter, doc, solid, color, shininess, transparency))
                        {
                            ++nSolids;
                        }
                    }
                }
            }
            return(nSolids);
        }
示例#12
0
        /// <summary>
        /// Recursively add vertices of all solids found
        /// in the given geometry to the vertex lookup.
        /// Untested!
        /// </summary>
        static void AddVertices(
            Dictionary <XYZ, int> vertexLookup,
            Transform t,
            GeometryElement geo)
        {
            if (null == geo)
            {
                Debug.Assert(null != geo, "null GeometryElement");
                throw new System.ArgumentException("null GeometryElement");
            }

            foreach (GeometryObject obj in geo)
            {
                Solid solid = obj as Solid;

                if (null != solid)
                {
                    if (0 < solid.Faces.Size)
                    {
                        AddVertices(vertexLookup, t, solid);
                    }
                }
                else
                {
                    GeometryInstance inst = obj as GeometryInstance;

                    if (null != inst)
                    {
                        //GeometryElement geoi = inst.GetInstanceGeometry();
                        GeometryElement geos = inst.GetSymbolGeometry();

                        //Debug.Assert( null == geoi || null == geos,
                        //  "expected either symbol or instance geometry, not both" );

                        Debug.Assert(null != inst.Transform,
                                     "null inst.Transform");

                        //Debug.Assert( null != inst.GetSymbolGeometry(),
                        //  "null inst.GetSymbolGeometry" );

                        if (null != geos)
                        {
                            AddVertices(vertexLookup,
                                        inst.Transform.Multiply(t),
                                        geos);
                        }
                    }
                }
            }
        }
示例#13
0
        /// <summary>
        /// Retrieve the first non-empty solid found for
        /// the given element. In case the element is a
        /// family instance, it may have its own non-empty
        /// solid, in which case we use that. Otherwise we
        /// search the symbol geometry. If we use the
        /// symbol geometry, we have to keep track of the
        /// instance transform to map it to the actual
        /// instance project location.
        /// </summary>
        static Solid GetSolid2(Element e, Options opt)
        {
            GeometryElement geo = e.get_Geometry(opt);

            Dictionary <XYZ, int> a
                = new Dictionary <XYZ, int>(
                      new XyzEqualityComparer());

            Solid            solid = null;
            GeometryInstance inst  = null;
            Transform        t     = Transform.Identity;

            // Some family elements have no own solids, so we
            // retrieve the geometry from the symbol instead;
            // others do have own solids on the instance itself
            // and no contents in the instance geometry
            // (e.g. in rst_basic_sample_project.rvt).

            foreach (GeometryObject obj in geo)
            {
                solid = obj as Solid;

                if (null != solid &&
                    0 < solid.Faces.Size)
                {
                    break;
                }

                inst = obj as GeometryInstance;
            }

            if (null == solid && null != inst)
            {
                geo = inst.GetSymbolGeometry();
                t   = inst.Transform;

                foreach (GeometryObject obj in geo)
                {
                    solid = obj as Solid;

                    if (null != solid &&
                        0 < solid.Faces.Size)
                    {
                        break;
                    }
                }
            }
            return(solid);
        }
示例#14
0
        public Reference GetReferenceOfFamilyInstance(FamilyInstance instance, SpecialReferenceType ReferenceType)
        {
            Reference indexReference = null;
            int       index          = (int)ReferenceType;
            Options   geomOptions    = new Options();

            geomOptions.ComputeReferences        = true;
            geomOptions.DetailLevel              = ViewDetailLevel.Medium;
            geomOptions.IncludeNonVisibleObjects = true;
            GeometryElement geoElement = instance.get_Geometry(geomOptions);

            foreach (GeometryObject obj in geoElement)
            {
                if (obj is GeometryInstance)
                {
                    GeometryInstance geoInstance = obj as GeometryInstance;
                    if (geoInstance != null)
                    {
                        GeometryElement geoSymbol       = geoInstance.GetSymbolGeometry();
                        string          sampleStableRef = null;
                        if (geoSymbol != null)
                        {
                            foreach (GeometryObject geomObj in geoSymbol)
                            {
                                if (geomObj is Solid)
                                {
                                    Solid solid = geomObj as Solid;
                                    if (solid.Faces.Size > 0)
                                    {
                                        Face face = solid.Faces.get_Item(0);
                                        sampleStableRef = face.Reference.ConvertToStableRepresentation(doc);
                                        break;
                                    }
                                }
                            }
                        }
                        if (sampleStableRef != null)
                        {
                            string[] refTokens       = sampleStableRef.Split(new char[] { ':' });
                            string   customStableRef = refTokens[0] + ':' + refTokens[1] + ':' + refTokens[2] + ':' +
                                                       refTokens[3] + ':' + index.ToString();
                            indexReference = Reference.ParseFromStableRepresentation(doc, customStableRef);
                        }
                        break;
                    }
                }
            }
            return(indexReference);
        }
示例#15
0
        /// <summary>
        /// Retrieve the non-empty solids found for
        /// the given element. In case the element is a
        /// family instance, it may have its own non-empty
        /// solids, in which case we use those. Otherwise,
        /// we search the symbol geometry. If we use the
        /// symbol geometry, we have to keep track of the
        /// instance transform to map it backto the actual
        /// instance project location.
        /// </summary>
        public static List <Solid> GetSolids(
            Element e,
            Options opt,
            out Transform t)
        {
            GeometryElement geo = e.get_Geometry(opt);

            List <Solid>     solids = new List <Solid>();
            GeometryInstance inst   = null;

            t = Transform.Identity;

            // Some columns have no solids, and we have to
            // retrieve the geometry from the symbol;
            // others do have solids on the instance itself
            // and no contents in the instance geometry
            // (e.g. in rst_basic_sample_project.rvt).

            foreach (GeometryObject obj in geo)
            {
                Solid solid = obj as Solid;

                if (null != solid && 0 < solid.Faces.Size)
                {
                    solids.Add(solid);
                }

                inst = obj as GeometryInstance;
            }

            if (solids.Count == 0 && null != inst)
            {
                geo = inst.GetSymbolGeometry();
                t   = inst.Transform;

                foreach (GeometryObject obj in geo)
                {
                    Solid solid = obj as Solid;

                    if (null != solid && 0 < solid.Faces.Size)
                    {
                        solids.Add(solid);
                    }
                }
            }
            return(solids);
        }
示例#16
0
        private Reference FindTopMostReference(Element e)
        {
            Reference ret = null;

            Options opt = _doc.Application.Create.NewGeometryOptions();

            opt.ComputeReferences = true;

            GeometryElement geo = e.get_Geometry(opt);

            foreach (GeometryObject obj in geo)
            {
                GeometryInstance inst = obj as GeometryInstance;

                if (inst != null)
                {
                    geo = inst.GetSymbolGeometry();
                    break;
                }
            }

            Solid solid = geo.OfType <Solid>().First <Solid>(sol => null != sol);

            double z = double.MinValue;

            foreach (Face f in solid.Faces)
            {
                BoundingBoxUV b        = f.GetBoundingBox();
                UV            p        = b.Min;
                UV            q        = b.Max;
                UV            midparam = p + 0.5 * (q - p);
                XYZ           midpoint = f.Evaluate(midparam);
                XYZ           normal   = f.ComputeNormal(midparam);

                if (PointsUpwards(normal))
                {
                    if (midpoint.Z > z)
                    {
                        z   = midpoint.Z;
                        ret = f.Reference;
                    }
                }
            }
            return(ret);
        }
示例#17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <param name="opt"></param>
        /// <returns></returns>
        Solid GetSolid(Element e, Options opt)
        {
            Solid solid = null;
            // access solid geometry of element
            GeometryElement geo = e.get_Geometry(opt);

            if (null != geo)
            {
                if (e is FamilyInstance)
                {
                    geo = geo.GetTransformed(Transform.Identity);
                }

                GeometryInstance inst = null;
                // iterate through multiple geometry objects
                foreach (GeometryObject obj in geo)
                {
                    solid = obj as Solid;
                    // if there is a solid with faces stop here
                    if (null != solid && 0 < solid.Faces.Size)
                    {
                        break;
                    }
                    // otherwise assign variable inst
                    inst = obj as GeometryInstance;
                }
                // if there is an instance def but no solid check the symbol
                if (null == solid && null != inst)
                {
                    geo = inst.GetSymbolGeometry();
                    // iterate through geometry of symbol
                    foreach (GeometryObject obj in geo)
                    {
                        solid = obj as Solid;
                        // if there is a solid with faces stop here
                        if (null != solid && 0 < solid.Faces.Size)
                        {
                            break;
                        }
                    }
                }
            }
            return(solid);
        }
示例#18
0
        void f(UIDocument uidoc)
        {
            Options options = new Options();

            options.ComputeReferences = true;

            GeometryElement geomElement = uidoc.Selection
                                          .PickObject(ObjectType.Element)
                                          .Element.get_Geometry(options);

            int ctr = 0;

            foreach (GeometryObject geomObj
                     in geomElement.Objects)
            {
                if (geomObj is Solid)
                {
                    FaceArray faces = (( Solid )geomObj).Faces;
                    ctr += faces.Size;
                }

                if (geomObj is GeometryInstance)
                {
                    GeometryInstance inst = geomObj
                                            as GeometryInstance;

                    if (inst != null)
                    {
                        GeometryElement geomElem
                            = inst.GetSymbolGeometry();

                        foreach (Object o in geomElem.Objects)
                        {
                            Solid solid = o as Solid;
                            if (solid != null)
                            {
                                ctr += solid.Faces.Size;
                            }
                        }
                    }
                }
            }
            TaskDialog.Show("Revit", "Faces: " + ctr);
        }
示例#19
0
        public static List <Line> LinesGeometry(this Element element, Document doc)
        {
            var     lines  = new List <Line>();
            Options option = new Options();

            if (element.Document.ActiveView != null)
            {
                option.View = element.Document.ActiveView;
                option.IncludeNonVisibleObjects = true;
            }
            var geoEle = element.get_Geometry(option);

            if (geoEle == null)
            {
                return(lines);
            }
            foreach (GeometryObject geometryObject in geoEle)
            {
                GeometryInstance geometryInstance = geometryObject as GeometryInstance;
                bool             flag2            = null != geometryInstance;
                if (flag2)
                {
                    GeometryElement symbolGeometry = geometryInstance.GetSymbolGeometry();
                    foreach (GeometryObject geometryObject2 in symbolGeometry)
                    {
                        Line line  = geometryObject2 as Line;
                        bool flag3 = null == line;
                        if (!flag3)
                        {
                            lines.Add(line);
                        }
                    }
                }
            }
            foreach (GeometryObject geometryObject in geoEle)
            {
                if (geometryObject is Line)
                {
                    lines.Add(geometryObject as Line);
                }
            }
            return(lines);
        }
示例#20
0
        /// <summary>
        /// Retrieve the first curve found for
        /// the given element. In case the element is a
        /// family instance, it may have its own non-empty
        /// solid, in which case we use that. Otherwise we
        /// search the symbol geometry. If we use the
        /// symbol geometry, we have to keep track of the
        /// instance transform to map it to the actual
        /// instance project location.
        /// </summary>
        private Curve GetCurve(Element e, Options opt)
        {
            GeometryElement geo = e.get_Geometry(opt);

            Curve            curve = null;
            GeometryInstance inst  = null;
            Transform        t     = Transform.Identity;

            // Some columns have no solids, and we have to
            // retrieve the geometry from the symbol;
            // others do have solids on the instance itself
            // and no contents in the instance geometry
            // (e.g. in rst_basic_sample_project.rvt).

            foreach (GeometryObject obj in geo)
            {
                curve = obj as Curve;

                if (null != curve)
                {
                    break;
                }

                inst = obj as GeometryInstance;
            }

            if (null == curve && null != inst)
            {
                geo = inst.GetSymbolGeometry();
                t   = inst.Transform;

                foreach (GeometryObject obj in geo)
                {
                    curve = obj as Curve;

                    if (null != curve)
                    {
                        break;
                    }
                }
            }
            return(curve);
        }
示例#21
0
        /// <summary>
        /// 获取FamilyInstance的Edges
        /// </summary>
        public static List <Face> Faces(FamilyInstance familyInstance, View _view)
        {
            Options options = new Options();

            options.View = _view;
            options.ComputeReferences = true;
            GeometryInstance geometryInstance = familyInstance.get_Geometry(options).First() as GeometryInstance;
            GeometryElement  geometryElement  = geometryInstance.GetSymbolGeometry();

            foreach (var item in geometryElement)
            {
                if (item is Solid)
                {
                    Solid solid = item as Solid;
                    return(ToIEnumerable(solid.Faces).ToList());
                }
            }
            return(new List <Face>());
        }
示例#22
0
        public static Curve GetCurvemaxfamily(FamilyInstance familyInstance)
        {
            List <Curve> alllines  = new List <Curve>();
            Curve        curvesmax = null;
            Options      option    = new Options();

            option.ComputeReferences        = true;
            option.IncludeNonVisibleObjects = false;
            if (familyInstance != null)
            {
                GeometryElement geoElement = familyInstance.get_Geometry(option);
                foreach (GeometryObject geoObject in geoElement)
                {
                    GeometryInstance instance = geoObject as GeometryInstance;
                    if (null != instance)
                    {
                        GeometryElement instanceGeometryElement = instance.GetSymbolGeometry();
                        foreach (GeometryObject o in instanceGeometryElement)
                        {
                            try
                            {
                                Solid solid = o as Solid;
                                if (solid != null)
                                {
                                    foreach (Edge item in solid.Edges)
                                    {
                                        alllines.Add(item.AsCurve());
                                    }
                                }
                            }
                            catch
                            {
                                Line line = o as Line;
                                alllines.Add(line as Curve);
                            }
                        }
                        curvesmax = Findcurvemax(alllines);
                    }
                }
            }
            return(curvesmax);
        }
示例#23
0
        public Dictionary <string, List <Face> > GetTypeFace(FamilyInstance familyInstance)
        {
            Dictionary <string, List <Face> > dic = new Dictionary <string, List <Face> >();
            Options option = new Options();

            option.ComputeReferences        = true;
            option.IncludeNonVisibleObjects = false;
            if (familyInstance != null)
            {
                GeometryElement geoElement = familyInstance.get_Geometry(option);
                foreach (GeometryObject geoObject in geoElement)
                {
                    GeometryInstance instance = geoObject as GeometryInstance;
                    if (null != instance)
                    {
                        GeometryElement instanceGeometryElement = instance.GetSymbolGeometry();
                        foreach (GeometryObject o in instanceGeometryElement)
                        {
                            Solid solid = o as Solid;
                            if (solid != null)
                            {
                                FaceArray kl = solid.Faces;
                                foreach (var i in kl)
                                {
                                    if (dic.ContainsKey(i.GetType().Name))
                                    {
                                        dic[i.GetType().Name].Add(i as Face);
                                    }
                                    else
                                    {
                                        dic.Add(i.GetType().Name, new List <Face> {
                                            i as Face
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(dic);
        }
示例#24
0
        private void ExportGeometryObject(GeometryObject geometryObject)
        {
            if (geometryObject.Equals(null))
            {
                return;
            }
            if (geometryObject.Visibility.Equals(Visibility.Invisible))
            {
                return;
            }
            if (documentStack.Peek().GetElement(geometryObject.GraphicsStyleId) is GraphicsStyle graphicsStyle && graphicsStyle.Name.Contains("Light Source"))
            {
                return;
            }
            GeometryInstance geometryInstance = geometryObject as GeometryInstance;

            if (geometryInstance != null)
            {
                transformationStack.Push(transformationStack.Peek().Multiply(geometryInstance.Transform));
                GeometryElement symbolGeometry = geometryInstance.GetSymbolGeometry();
                if (symbolGeometry != null)
                {
                    foreach (GeometryObject current in symbolGeometry)
                    {
                        if (current != null)
                        {
                            ExportGeometryObject(current);
                        }
                    }
                }
                transformationStack.Pop();
                return;
            }
            Solid solid = geometryObject as Solid;

            if (solid != null)
            {
                ExportSolid2(solid);
                return;
            }
        }
        PlanarFace FindPlanarFaces(FamilyInstance familyInstance)
        {
            List <PlanarFace> list   = new List <PlanarFace>();
            Options           option = new Options();

            option.ComputeReferences        = true;
            option.IncludeNonVisibleObjects = false;
            if (familyInstance != null)
            {
                GeometryElement geoElement = familyInstance.get_Geometry(option);
                foreach (GeometryObject geoObject in geoElement)
                {
                    GeometryInstance instance = geoObject as GeometryInstance;
                    if (null != instance)
                    {
                        GeometryElement instanceGeometryElement = instance.GetSymbolGeometry();
                        foreach (GeometryObject o in instanceGeometryElement)
                        {
                            Solid solid = o as Solid;
                            if (solid != null)
                            {
                                FaceArray kl = solid.Faces;
                                foreach (var i in kl)
                                {
                                    if (i.GetType().Name.Contains("Planar"))
                                    {
                                        list.Add(i as PlanarFace);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            SortPlanarFace(list);
            PlanarFace face = list.Last();

            return(face);
        }
示例#26
0
        /// <summary>
        /// 获取FamilyInstance的Edges
        /// </summary>
        public static List <Face> Faces(this FamilyInstance familyInstance, View _view)
        {
            Options options = new Options();

            options.View = _view;
            options.ComputeReferences = true;
            GeometryInstance geometryInstance = familyInstance.get_Geometry(options).First() as GeometryInstance;
            // 这里需要明确参照几何的来源
            // 使用symbolGeometry是族类型的几何引用
            GeometryElement geometryElement = geometryInstance.GetSymbolGeometry();

            // 使用instanceGeometry是族实例的几何信息,但是无法提取reference
            //GeometryElement geometryElement = geometryInstance.GetInstanceGeometry();
            foreach (var item in geometryElement)
            {
                if (item is Solid)
                {
                    Solid solid = geometryElement.First() as Solid;
                    return(solid.Faces.ToIEnumerable().ToList());
                }
            }
            return(new List <Face>());
        }
示例#27
0
        /// <summary>
        /// Get geometry of one level of a potentially multi-story stair, ramp, or railing.
        /// </summary>
        /// <param name="geomElement">The original geometry.</param>
        /// <returns>The geometry element.</returns>
        /// <remarks>This routine may not work properly for railings created before 2006.  If you get
        /// poor representations from such railings, please upgrade the railings if possible.</remarks>
        public static GeometryElement GetOneLevelGeometryElement(GeometryElement geomElement)
        {
            if (geomElement == null)
            {
                return(null);
            }

            foreach (GeometryObject geomObject in geomElement)
            {
                if (!(geomObject is GeometryInstance))
                {
                    continue;
                }
                GeometryInstance geomInstance = geomObject as GeometryInstance;
                if (!MathUtil.IsAlmostZero(geomInstance.Transform.Origin.Z))
                {
                    continue;
                }
                Element baseSymbol = geomInstance.Symbol;
                if (!(baseSymbol is ElementType))
                {
                    continue;
                }
                GeometryElement symbolGeomElement = geomInstance.GetSymbolGeometry();

                // For railings created before 2006, the GeometryElement could be null.  In this case, we will use
                // a more general technique of getting geometry below, which will unfortanately result in worse
                // representations.  If this is a concern, please upgrade the railings to any format since 2006.
                if (symbolGeomElement != null)
                {
                    return(symbolGeomElement);
                }
            }

            return(geomElement);
        }
示例#28
0
        /// <summary>
        /// Export all non-empty solids found for
        /// the given element. Family instances may have
        /// their own non-empty solids, in which case
        /// those are used, otherwise the symbol geometry.
        /// The symbol geometry could keep track of the
        /// instance transform to map it to the actual
        /// project location. Instead, we ask for
        /// transformed geometry to be returned, so the
        /// resulting solids are already in place.
        /// </summary>
        int ExportSolids(
            IJtFaceEmitter emitter,
            Element e,
            Options opt,
            Color color,
            int transparency)
        {
            int nSolids = 0;

            GeometryElement geo = e.get_Geometry(opt);

            Solid solid;

            if (null != geo)
            {
                Document doc = e.Document;

                if (e is FamilyInstance)
                {
                    geo = geo.GetTransformed(Transform.Identity);
                }

                GeometryInstance inst = null;
                //Transform t = Transform.Identity;

                // Some columns have no solids, and we have to
                // retrieve the geometry from the symbol;
                // others do have solids on the instance itself
                // and no contents in the instance geometry
                // (e.g. in rst_basic_sample_project.rvt).

                foreach (GeometryObject obj in geo)
                {
                    solid = obj as Solid;

                    if (null != solid &&
                        0 < solid.Faces.Size &&
                        ExportSolid(emitter, doc, e, solid,
                                    color, transparency))
                    {
                        ++nSolids;
                    }

                    inst = obj as GeometryInstance;
                }

                if (0 == nSolids && null != inst)
                {
                    geo = inst.GetSymbolGeometry();
                    //t = inst.Transform;

                    foreach (GeometryObject obj in geo)
                    {
                        solid = obj as Solid;

                        if (null != solid &&
                            0 < solid.Faces.Size &&
                            ExportSolid(emitter, doc, e, solid,
                                        color, transparency))
                        {
                            ++nSolids;
                        }
                    }
                }
            }
            return(nSolids);
        }
        public static Reference GetSpecialFamilyReference(
            FamilyInstance inst,
            SpecialReferenceType refType)
        {
            Reference indexRef = null;

            int idx = (int)refType;

            if (inst != null)
            {
                Document dbDoc = inst.Document;

                Options geomOptions = dbDoc.Application.Create
                                      .NewGeometryOptions();

                if (geomOptions != null)
                {
                    geomOptions.ComputeReferences        = true;
                    geomOptions.DetailLevel              = ViewDetailLevel.Undefined;
                    geomOptions.IncludeNonVisibleObjects = true;
                }

                GeometryElement gElement = inst.get_Geometry(
                    geomOptions);

                GeometryInstance gInst = gElement.First()
                                         as GeometryInstance;

                String sampleStableRef = null;

                if (gInst != null)
                {
                    GeometryElement gSymbol = gInst
                                              .GetSymbolGeometry();

                    if (gSymbol != null)
                    {
                        foreach (GeometryObject geomObj in gSymbol)
                        {
                            if (geomObj is Solid)
                            {
                                Solid solid = geomObj as Solid;

                                if (solid.Faces.Size > 0)
                                {
                                    Face face = solid.Faces.get_Item(0);

                                    sampleStableRef = face.Reference
                                                      .ConvertToStableRepresentation(
                                        dbDoc);

                                    break;
                                }
                            }
                            else if (geomObj is Curve)
                            {
                                Curve curve = geomObj as Curve;

                                sampleStableRef = curve.Reference
                                                  .ConvertToStableRepresentation(dbDoc);

                                break;
                            }
                            else if (geomObj is Point)
                            {
                                Point point = geomObj as Point;

                                sampleStableRef = point.Reference
                                                  .ConvertToStableRepresentation(dbDoc);

                                break;
                            }
                        }
                    }

                    if (sampleStableRef != null)
                    {
                        String[] refTokens = sampleStableRef.Split(
                            new char[] { ':' });

                        String customStableRef = refTokens[0] + ":"
                                                 + refTokens[1] + ":" + refTokens[2] + ":"
                                                 + refTokens[3] + ":" + idx.ToString();

                        indexRef = Reference
                                   .ParseFromStableRepresentation(
                            dbDoc, customStableRef);

                        GeometryObject geoObj = inst
                                                .GetGeometryObjectFromReference(
                            indexRef);

                        if (geoObj != null)
                        {
                            String finalToken = "";

                            if (geoObj is Edge)
                            {
                                finalToken = ":LINEAR";
                            }

                            if (geoObj is Face)
                            {
                                finalToken = ":SURFACE";
                            }

                            customStableRef += finalToken;

                            indexRef = Reference
                                       .ParseFromStableRepresentation(
                                dbDoc, customStableRef);
                        }
                        else
                        {
                            indexRef = null;
                        }
                    }
                }
                else
                {
                    throw new Exception("No Symbol Geometry found...");
                }
            }
            return(indexRef);
        }
        /// <summary>
        /// Return a reference to the topmost face of the given element.
        /// </summary>
        private Reference FindTopMostReference(Element e)
        {
            Reference ret = null;
            Document  doc = e.Document;

            #region Revit 2012
#if _2012
            using (SubTransaction t = new SubTransaction(doc))
            {
                t.Start();

                // Create temporary 3D view

                //View3D view3D = doc.Create.NewView3D( // 2012
                //  viewDirection ); // 2012

                ViewFamilyType vft
                    = new FilteredElementCollector(doc)
                      .OfClass(typeof(ViewFamilyType))
                      .Cast <ViewFamilyType>()
                      .FirstOrDefault <ViewFamilyType>(x =>
                                                       ViewFamily.ThreeDimensional == x.ViewFamily);

                Debug.Assert(null != vft,
                             "expected to find a valid 3D view family type");

                View3D view = View3D.CreateIsometric(doc, vft.Id); // 2013

                XYZ eyePosition      = XYZ.BasisZ;
                XYZ upDirection      = XYZ.BasisY;
                XYZ forwardDirection = -XYZ.BasisZ;

                view.SetOrientation(new ViewOrientation3D(
                                        eyePosition, upDirection, forwardDirection));

                XYZ viewDirection = -XYZ.BasisZ;

                BoundingBoxXYZ bb = e.get_BoundingBox(view);

                XYZ max = bb.Max;

                XYZ minAtMaxElevation = Create.NewXYZ(
                    bb.Min.X, bb.Min.Y, max.Z);

                XYZ centerOfTopOfBox = 0.5
                                       * (minAtMaxElevation + max);

                centerOfTopOfBox += 10 * XYZ.BasisZ;

                // Cast a ray through the model
                // to find the topmost surface

#if DEBUG
                //ReferenceArray references
                //  = doc.FindReferencesByDirection(
                //    centerOfTopOfBox, viewDirection, view3D ); // 2011

                IList <ReferenceWithContext> references
                    = doc.FindReferencesWithContextByDirection(
                          centerOfTopOfBox, viewDirection, view); // 2012

                double closest = double.PositiveInfinity;

                //foreach( Reference r in references )
                //{
                //  // 'Autodesk.Revit.DB.Reference.Element' is
                //  // obsolete: Property will be removed. Use
                //  // Document.GetElement(Reference) instead.
                //  //Element re = r.Element; // 2011

                //  Element re = doc.GetElement( r ); // 2012

                //  if( re.Id.IntegerValue == e.Id.IntegerValue
                //    && r.ProximityParameter < closest )
                //  {
                //    ret = r;
                //    closest = r.ProximityParameter;
                //  }
                //}

                foreach (ReferenceWithContext r in references)
                {
                    Element re = doc.GetElement(
                        r.GetReference()); // 2012

                    if (re.Id.IntegerValue == e.Id.IntegerValue &&
                        r.Proximity < closest)
                    {
                        ret     = r.GetReference();
                        closest = r.Proximity;
                    }
                }

                string stable_reference = null == ret ? null
          : ret.ConvertToStableRepresentation(doc);
#endif // DEBUG

                ReferenceIntersector ri
                    = new ReferenceIntersector(
                          e.Id, FindReferenceTarget.Element, view);

                ReferenceWithContext r2 = ri.FindNearest(
                    centerOfTopOfBox, viewDirection);

                if (null == r2)
                {
                    Debug.Print("ReferenceIntersector.FindNearest returned null!");
                }
                else
                {
                    ret = r2.GetReference();

                    Debug.Assert(stable_reference.Equals(ret
                                                         .ConvertToStableRepresentation(doc)),
                                 "expected same reference from "
                                 + "FindReferencesWithContextByDirection and "
                                 + "ReferenceIntersector");
                }
                t.RollBack();
            }
#endif // _2012
            #endregion // Revit 2012

            Options opt = doc.Application.Create
                          .NewGeometryOptions();

            opt.ComputeReferences = true;

            GeometryElement geo = e.get_Geometry(opt);

            foreach (GeometryObject obj in geo)
            {
                GeometryInstance inst = obj as GeometryInstance;

                if (null != inst)
                {
                    geo = inst.GetSymbolGeometry();
                    break;
                }
            }

            Solid solid = geo.OfType <Solid>()
                          .First <Solid>(sol => null != sol);

            double z = double.MinValue;

            foreach (Face f in solid.Faces)
            {
                BoundingBoxUV b        = f.GetBoundingBox();
                UV            p        = b.Min;
                UV            q        = b.Max;
                UV            midparam = p + 0.5 * (q - p);
                XYZ           midpoint = f.Evaluate(midparam);
                XYZ           normal   = f.ComputeNormal(midparam);

                if (Util.PointsUpwards(normal))
                {
                    if (midpoint.Z > z)
                    {
                        z   = midpoint.Z;
                        ret = f.Reference;
                    }
                }
            }
            return(ret);
        }
示例#31
0
        public Message Execute(Document doc, Message msg)
        {
            JObject msgData   = JObject.Parse(msg.Data);
            string  elementId = msgData["Id"].ToString();

            FamilySymbol family = doc.GetElement(new ElementId(Int32.Parse(elementId))) as FamilySymbol;

            GeometryElement geometry = family.get_Geometry(new Options());

            if (geometry == null)
            {
                return(new Message
                {
                    Type = "EMPTY",
                    Data = $"No geometry found for family: {family.Name} ({family.Id})"
                });
            }

            byte[] file_bytes = GeometryToOBJ(doc, geometry);

            try
            {
                System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
                s.Start();

                List <Task> uploadTasks = new List <Task>();

                LMAStudio.StreamVR.Common.Models.Family dto = _converter.ConvertToDTO(family).ToObject <LMAStudio.StreamVR.Common.Models.Family>();

                uploadTasks.Add(Task.Run(() => UploadOBJ(dto, file_bytes)));

                IEnumerable <FamilyInstance> instances = new FilteredElementCollector(doc).
                                                         OfClass(typeof(FamilyInstance)).
                                                         Select(f => f as FamilyInstance).
                                                         Where(f => f.Symbol.Id == family.Id);

                // Get all different variants
                Dictionary <int, FamilyInstance> variants = new Dictionary <int, FamilyInstance>();
                foreach (var f in instances)
                {
                    var info = f.GetOrderedParameters().Where(p => p.Definition.ParameterGroup == BuiltInParameterGroup.PG_GEOMETRY);
                    Dictionary <string, string> infoDict = new Dictionary <string, string>();
                    foreach (var i in info)
                    {
                        infoDict[i.Definition.Name] = i.AsValueString();
                    }
                    int hash = JsonConvert.SerializeObject(infoDict).GetHashCode();
                    variants[hash] = f;
                }

                _log($"{family.Name} has {instances.Count()} varaints");

                // Upload each distinct variant
                foreach (var kv in variants)
                {
                    GeometryElement  variantGeometry = kv.Value.get_Geometry(new Options());
                    GeometryInstance variantInstance = variantGeometry.Where(
                        g => (g as Solid) == null || (g as Solid).Faces.Size == 0
                        ).FirstOrDefault() as GeometryInstance;
                    if (variantInstance == null)
                    {
                        _log($"INSTANCE GEOMETRY NULL FOR: {kv.Value.Name}");
                        continue;
                    }
                    GeometryElement variantInstanceGeometry = variantInstance.GetSymbolGeometry();
                    if (variantInstanceGeometry != null)
                    {
                        byte[] variantFileBytes = GeometryToOBJ(doc, variantInstanceGeometry);
                        uploadTasks.Add(Task.Run(() => UploadOBJVariant(dto.FamilyId, kv.Key.ToString(), variantFileBytes)));
                    }
                }

                Task.WaitAll(uploadTasks.ToArray());

                _log($"Upload time for {instances.Count() + 1} models: {s.ElapsedMilliseconds}ms");
                s.Stop();

                return(new Message
                {
                    Type = "OBJ",
                    Data = dto.FamilyId
                });
            }
            catch (Exception e)
            {
                return(new Message
                {
                    Type = "ERROR",
                    Data = $"Error: {family.Name} ({family.Id}) {e.ToString()}"
                });
            }
        }