[Revit二次开发]-读取族参数

概要:

 1.读取在Revit中选中的元素参数,并且显示在TaskDialog上。

2.把元素的类型的参数信息显示出来;

3.并且获取元素的族名称。

实现代码:

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

namespace ClassLibrary8
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument; //激活用户文档
            Document revitDoc = uiDoc.Document; //获取Revit文档进行元素处理
            var elemList = uiDoc.Selection.GetElementIds().ToList();//获得用户在Revit中选中的元素的集合

            System.Collections.IList list = elemList;
            for (int i1 = 0; i1 < list.Count; i1++)  //遍历选中的每一个元素
            {
                Element selElem = uiDoc.Document.GetElement(elemList[i1]);//通过Id获得document中的元素
                ElementType type = revitDoc.GetElement(selElem.GetTypeId()) as ElementType; //获取元素类型
                string str = "元素名称:" + type.FamilyName + "\n" + "元素类型:" + type.Name;
                TaskDialog.Show("元素参数", str);  
            }

            return Result.Succeeded;
        }
    }
}

效果:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值