Revit 二次开发 图元与参数

学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=3

本章内容

  • 元素基础
  • 如何获取元素
  • 元素与元素类型
  • 元素的属性与重要方法
  • 元素参数概念与实例

元素基础

如何获取元素

元素与元素类型

元素与元素类型

元素的几个重要的属性包括

元素的重要方法有

元素参数概念与实例

参数的四种类型

元素参数概念与实例

功能:读取元素参数

  • 读取选中元素的参数,并且显示在TaskDialog上
  • 把元素的类型的参数信息显示出来
  • 并且获取元素的族名称
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using System.Windows.Forms;

namespace RevitDevTV
{
    /// <summary>
    /// 获取元素属性
    /// </summary>
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class GetParameter : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document revitDoc = uiDoc.Document;
            var eleList = uiDoc.Selection.GetElementIds().ToList();
            Element selElem = uiDoc.Document.GetElement(eleList[0]);
            ElementType type = revitDoc.GetElement(selElem.GetTypeId()) as ElementType;
            string str = "元素族名称:"+type.FamilyName+"
"+"元素类型:"+type.Name;
            TaskDialog.Show("元素参数",str);
            return Result.Succeeded;
        }
    }
}

原文地址:https://www.cnblogs.com/chenyanbin/p/13280407.html