1. 程式人生 > >revit 二次開發 模型線讀取

revit 二次開發 模型線讀取

目前只能讀取模型線長度,閉合的區域讀不到面積

UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            //獲取選取的模型線集合
            IList<Reference> rList = uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element);
            //遍歷集合獲取長度
            Double cLengths = 0;
            Double clengthss = 0;
            foreach (Reference r in rList)
            {
                ModelCurve mcurve = doc.GetElement(r) as ModelCurve;//獲取模型線
                Curve geoCurve = mcurve.GeometryCurve;//獲取模型線屬性資訊
                Double clength = geoCurve.Length;//獲取模型線長度
                double cl = UnitUtils.Convert(clength, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS);//英尺轉換為毫米
                double cL = UnitUtils.Convert(clength, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS);//英尺轉米
                cLengths += cl;
                clengthss += cL;
            }
            TaskDialog.Show("所點選模型線長度", "長度為:" + cLengths.ToString() + "mm" + "\r" + clengthss.ToString() + "m");

            return Result.Succeeded;