示例#1
0
        public static void FindFloorslope(Floor floor, out double degree, out double thousand)
        {
            var    floorgeom = floor.get_Geometry(FloorTools.GetgeometryOptions());
            var    geomobj   = floorgeom.First <GeometryObject>();
            Solid  floorobj  = geomobj as Solid;
            double facearea  = 0;
            double cos_angle = 0;

            PlanarFace pf = null;

            foreach (Face face in floorobj.Faces)
            {
                pf = face as PlanarFace;
                if (pf.Area > facearea && pf.FaceNormal.Z >= 0)
                {
                    facearea  = pf.Area;
                    cos_angle = pf.FaceNormal.Z / Math.Sqrt(Math.Pow(pf.FaceNormal.X, 2) + Math.Pow(pf.FaceNormal.Y, 2) + Math.Pow(pf.FaceNormal.Z, 2));
                }
            }
            double angle_degree   = Math.Round(Math.Acos(cos_angle) / Math.PI * 180, 3);
            double angle_thousand = Math.Tan(Math.Acos(cos_angle)) * 1000;

            degree   = Math.Round(angle_degree, 4);
            thousand = Math.Round(angle_thousand, 3);
        }
示例#2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document   doc       = commandData.Application.ActiveUIDocument.Document;
            UIDocument uidoc     = commandData.Application.ActiveUIDocument;
            Selection  selection = uidoc.Selection;

            double angle_degree   = 0;
            double angle_thousand = 0;

            if (selection.GetElementIds().Count() != 1)
            {
                //selection.Dispose();

                var     reference = selection.PickObject(ObjectType.PointOnElement, "请选择楼板");
                Element elem      = doc.GetElement(reference);
                if (elem != null)
                {
                    FloorTools.FindFloorslope(elem as Floor, out angle_degree, out angle_thousand);
                    TaskDialog.Show("报告楼板坡度", "楼板角度为" + angle_degree.ToString() + "°" + "," + "坡度为" + angle_thousand.ToString() + "/1000");

                    return(Result.Succeeded);
                }
                else
                {
                    return(Result.Cancelled);
                }
            }
            else
            {
                ElementId id    = selection.GetElementIds().First <ElementId>();
                Element   elem1 = doc.GetElement(id);
                if (elem1 is Floor)
                {
                    FloorTools.FindFloorslope(elem1 as Floor, out angle_degree, out angle_thousand);
                    TaskDialog.Show("报告楼板坡度", "楼板角度为" + angle_degree.ToString() + "," + "坡度为" + angle_thousand.ToString());
                    return(Result.Succeeded);
                }
                else
                {
                    var     reference = selection.PickObject(ObjectType.Element, new FloorFaceFilter(doc), "请选择楼板");
                    Element elem2     = doc.GetElement(reference);
                    if (elem2 != null)
                    {
                        FloorTools.FindFloorslope(elem2 as Floor, out angle_degree, out angle_thousand);
                        TaskDialog.Show("报告楼板坡度", "楼板角度为" + angle_degree.ToString() + "," + "坡度为" + angle_thousand.ToString());
                        return(Result.Succeeded);
                    }
                    else
                    {
                        return(Result.Cancelled);
                    }
                }
            }
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(true);
            //Controllor controllor = new Controllor(new PersonForm());
            //Application.Run(controllor.pView);
        }