当前位置:网站首页>Revit secondary development - get the thickness / length / height of the beam

Revit secondary development - get the thickness / length / height of the beam

2022-07-07 22:22:00 Hey, hey, hey, hey, hey

Thickness of beam / length / Height cannot be obtained directly , It can be calculated according to geometric information .

 

        /// <summary>
        ///  Get beam thickness / wide / length 
        /// </summary>
        /// <param name="inst"></param>
        /// <returns></returns>
        public double GetBeamThick(FamilyInstance inst)
        {
            double dThick = 0;
            Line loc = (inst.Location as LocationCurve).Curve as Line;
            XYZ dir = loc.Direction;
            Options opts = new Options();
            GeometryElement gelem = inst.get_Geometry(opts);
            foreach (GeometryObject gobj in gelem)
            {
                if (gobj is GeometryInstance)
                {
                    GeometryInstance gins = gobj as GeometryInstance;
                    GeometryElement ge = gins.GetInstanceGeometry();
                    foreach (GeometryObject go in ge)
                    {
                        Solid solid = go as Solid;
                        if (solid != null && solid.Volume > 0)
                        {
                            foreach (Face face in solid.Faces)
                            {
                                XYZ faceDir = face.ComputeNormal(new UV());
                                if (faceDir.IsAlmostEqualTo(dir) || faceDir.IsAlmostEqualTo(-dir))
                                {
                                    BoundingBoxUV uvBox = face.GetBoundingBox();
                                    XYZ min = face.Evaluate(uvBox.Min);
                                    XYZ max = face.Evaluate(uvBox.Max);
                                    double height = Math.Abs(max.Z - min.Z);
                                    double length = max.DistanceTo(min);
                                    dThick = Math.Sqrt(length*length-height*height );
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (gobj is Solid)
                {
                    Solid solid = gobj as Solid;
                    if (solid != null && solid.Volume > 0)
                    {
                        foreach (Face face in solid.Faces)
                        {
                            XYZ faceDir = face.ComputeNormal(new UV());
                            if (faceDir.IsAlmostEqualTo(dir) || faceDir.IsAlmostEqualTo(-dir))
                            {
                                BoundingBoxUV uvBox = face.GetBoundingBox();
                                XYZ min = face.Evaluate(uvBox.Min);
                                XYZ max = face.Evaluate(uvBox.Max);
                                double height = Math.Abs(max.Z - min.Z);
                                double length = max.DistanceTo(min);
                                dThick = Math.Sqrt(length*length-height*height);
                                break;
                            }
                        }
                    }
                }
            }
            return dThick * 304.8;
        }

 

原网站

版权声明
本文为[Hey, hey, hey, hey, hey]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130606207190.html