Revit获取单个元素族名称、类型、体积 源代码

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;
namespace Volume1
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // throw new NotImplementedException();
            UIDocument uidocument = commandData.Application.ActiveUIDocument;
            Document document = uidocument.Document;
            ICollection<ElementId> elementIds = uidocument.Selection.GetElementIds();
            Element element = uidocument.Document.GetElement(elementIds.First());
            ElementType elementType = document.GetElement(element.GetTypeId()) as ElementType;
            GeometryElement geometryElement = element.get_Geometry(new Options());
            double volume = 0;
            foreach (GeometryObject geomeObj in geometryElement)
            {
                if (geomeObj is Solid)
                {
                   Solid solid = geomeObj as Solid;
                    volume = solid.Volume * 0.3048 * 0.3048 * 0.3048;
                 
                }
            }
            string str = "元素族名称:" + elementType.FamilyName + "\n" + "元素类型:" + elementType.Name + "\n" + "体积为:" + volume.ToString("0.00");
            TaskDialog.Show("元素参数", str);
            return Result.Succeeded;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/star65806841/article/details/80037397