revit二次开发(获取墙的边长和面的面积)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace _2018._7._23练习
{
    [Transaction(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;//获取活动文档

            Reference ref1 = uidoc.Selection.PickObject(ObjectType.Element, "选择一个族实例");
            Element elem = doc.GetElement(ref1);
            Wall aWall = elem as Wall;

            //Wall aWall = doc.GetElement(new ElementId(336263)) as Wall;

            //创建几何选项
            Options opt = new Options();
            opt.ComputeReferences = true;
            //Options.ComputeReferences必须为true,否是拿到的几何体的Reference都将是null
            opt.DetailLevel = ViewDetailLevel.Fine;
            GeometryElement geometryElement = aWall.get_Geometry(opt);//墙转换为几何元素

            double FaceArea = 0;
            double EdgeLength = 0;

            foreach (GeometryObject geomObj in geometryElement)//获取到几何元素的边和面
            {
                Solid geomSolid = geomObj as Solid;
                if (null != geomSolid)
                {
                    foreach (Face geoFace in geomSolid.Faces)
                    {
                        //得到墙面
                        if (geoFace is PlanarFace)
                        {
                            FaceArea += geoFace.Area;
                        }
                    }

                    foreach (Edge geoEdge in geomSolid.Edges)
                    {
                        EdgeLength += geoEdge.ApproximateLength;
                        //得到墙边
                    }
                }
            }
            TaskDialog.Show("Revit", "墙边长一共:" + EdgeLength.ToString() + "\n" + "墙面积一共:" + FaceArea.ToString());

            return Result.Succeeded;
        }
    }
}
 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值