应用程序:ParameterUtils

Revit平台:所有平台

Revit版本:2011.0

首次发布于:8.1

编程语言:C

技能水平:初级

类别:参数

类型:ExternalCommand

主题:显示参数

概要:

本示例演示了如何获取Revit元素的参数。

类:

- Autodesk.Revit.DB.Element

- Autodesk.Revit.DB.Parameter

- Autodesk.Revit.DB.Document

项目文件:

Command.cs

这个文件包含了从IExternalCommand继承而来的Command类。它的功能是检索所选元素具有的所有参数,然后在表单的列表视图中显示它们。

 

PropertiesForm.cs

这个文件包含了一个Form类,它由确定和取消按钮以及一个列出所选元素参数信息的列表视图组成。

描述:

- 要获取所选元素集合,请使用Document.Selection.Elements

- 要获取元素具有的参数集合,请使用Element.Parameters

- 使用Parameter.StorageType获取参数存储类型,然后使用相应的函数(例如,如果存储类型是double,则使用AsDouble()函数)获取其值。

- 要使用元素ID检索元素,请使用Document.get_Element(ElementId id)

- 要获取元素的名称,请使用Element.Name

- ListView用于显示字符串数组,其中每个字符串代表单个参数信息。

说明:

1. 只选择一个元素,例如墙或地板等。(注:如果没有选择任何元素或选择了多个元素,命令将返回失败并给出错误消息)

2. 运行命令。

源代码

完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码

PropertiesForm.cs

//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


namespace Revit.SDK.Samples.ParameterUtils.CS
{
    partial class PropertiesForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.okButton = new System.Windows.Forms.Button();
            this.propertyListView = new System.Windows.Forms.ListView();
            this.SuspendLayout();
            // 
            // okButton
            // 
            this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.okButton.Location = new System.Drawing.Point(386, 315);
            this.okButton.Name = "okButton";
            this.okButton.Size = new System.Drawing.Size(75, 23);
            this.okButton.TabIndex = 0;
            this.okButton.Text = "&OK";
            this.okButton.UseVisualStyleBackColor = true;
            // 
            // propertyListView
            // 
            this.propertyListView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.propertyListView.FullRowSelect = true;
            this.propertyListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
            this.propertyListView.HideSelection = false;
            this.propertyListView.Location = new System.Drawing.Point(12, 12);
            this.propertyListView.MultiSelect = false;
            this.propertyListView.Name = "propertyListView";
            this.propertyListView.Size = new System.Drawing.Size(449, 297);
            this.propertyListView.TabIndex = 2;
            this.propertyListView.UseCompatibleStateImageBehavior = false;
            this.propertyListView.View = System.Windows.Forms.View.Details;
            // 
            // PropertiesForm
            // 
            this.AcceptButton = this.okButton;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.okButton;
            this.ClientSize = new System.Drawing.Size(473, 350);
            this.Controls.Add(this.propertyListView);
            this.Controls.Add(this.okButton);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "PropertiesForm";
            this.ShowInTaskbar = false;
            this.Text = "Properties";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button okButton;
        private System.Windows.Forms.ListView propertyListView;
    }
}