热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

RevitAPI“普通参数”和“类型属性参数”的区别

元素的参数分普通的属性参数和类型属性参数。参数的值可能是一个整数,一个字符串,也可能是一个元素对象。比如是一种材质。材质也分多种,管道有管道对齐的材质。using System;u
元素的参数分普通的属性参数和类型属性参数。
参数的值可能是一个整数,一个字符串,也可能是一个元素对象。比如是一种材质。
材质也分多种,管道有管道对齐的材质。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WinForm = System.Windows.Forms;

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;

using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;

using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Architecture;

using System.Xml;

namespace RevitCodes
{

    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    
public class cmdParameter : IExternalCommand
    {
        
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
        {
            UIApplication uiApp 
= commandData.Application;
            Document doc 
= uiApp.ActiveUIDocument.Document;
            Selection sel 
= uiApp.ActiveUIDocument.Selection;

            Transaction ts 
= new Transaction(doc, "http://revit.5d6d.com");
            ts.Start();
            
//选中的元素,这里选中一个管道Pipe
            Element elemPick = null;
            
foreach (Element elem in sel.Elements)
            {
                elemPick 
= elem;
                
break;
            }

            
//遍历元素的普通参数
            string strParameter = "";
            
foreach (Parameter p in elemPick.Parameters)
            {
                strParameter 
+= p.Definition.ParameterGroup + "," + p.Definition.Name + "," + p.AsValueString() + "\n";
            }
            TaskDialog.Show(
"parameter", strParameter);
            
//遍历元素的类型属性
            Pipe pipe = elemPick as Pipe;
            
foreach (Parameter p in pipe.PipeType.Parameters)
            {
                
if (p.Definition.Name == "材质")
                {
                    
//元素的参数值可能是一个元素,比如材质的参数值是一个Material元素
                    PipeMaterialType pipeMater = doc.get_Element(p.AsElementId()) as PipeMaterialType;
                    
//材质还分管道材质这里不能转化为Material
                    TaskDialog.Show("类型属性", pipeMater.Category.Name + "," + pipeMater.Name);
                }
            }
            
//系统包含的材质元素
            string strMaterial = "";
            Materials materials 
= doc.Settings.Materials;
            
foreach (Material ma in materials)
            {
                strMaterial 
+= ma.Name + "\n";
            }
            TaskDialog.Show(
"Material", strMaterial);

            ts.Commit();

            
return Result.Succeeded;
        }
        
//元素的参数,参数组,即属性面版中可以折叠的部分,这里读Pipe
        public Parameter FindParameter(Element element)
        {
            Parameter foundParameter 
= null;
            
int i = 0;
            
foreach (Parameter parameter in element.Parameters)
            {
                
//BuiltInParameterGroup.PG_MECHANICAL//机械
                
//BuiltInParameterGroup.PG_CONSTRAINTS//限制条件
                
//BuiltInParameterGroup.PG_GEOMETRY//尺寸标注
                
//BuiltInParameterGroup.PG_PHASING//阶段化
                
//BuiltInParameterGroup.PG_IDENTITY_DATA//标识数据
                
//BuiltInParameterGroup.PG_INSULATION//绝缘层
                if (BuiltInParameterGroup.PG_GEOMETRY == parameter.Definition.ParameterGroup)
                {
                    TaskDialog.Show(
"g", parameter.Definition.Name);
                    i 
+= 1;
                }
                Definition definition 
= parameter.Definition;//参数的基类
                
//过滤参数
                if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS &&
                        definition.ParameterType 
== ParameterType.Material)
                {
                    foundParameter 
= parameter;
                    
break;
                }
            }
            TaskDialog.Show(
"i", i + "");
            
return foundParameter;
        }
    }

}
from:http://revit.5d6d.com/thread-1324-1-1.html
推荐阅读
author-avatar
zifei84589
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有