Revit 二次开发之“参数”

本文介绍如何使用Revit API获取与修改建筑元素参数,包括遍历所有参数及通过特定标识获取参数值,并演示了如何修改参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

start
//遍历全部参数
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class GetAllParameterValues : IExternalCommand
{
    
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
        UIApplication uiApp 
= commandData.Application;
        Autodesk.Revit.ApplicationServices.Application app 
= uiApp.Application;
        Document doc 
= uiApp.ActiveUIDocument.Document;

        Selection sel 
= uiApp.ActiveUIDocument.Selection;
        sel.StatusbarTip 
= "Please select an element";
        sel.PickOne();
        Element elemPick 
= null;

        
foreach (Element elem in sel.Elements)
        {
            elemPick 
= elem;
            
break;
        }

        
string strParamInfo = null;
        
foreach (Parameter param in elemPick.Parameters)
        {
            
if (param.AsValueString() != null)
                strParamInfo 
+= param.Definition.Name + " value is:" + param.AsValueString() + "\n";
            
else
                strParamInfo 
+= param.Definition.Name + " value is:" + param.AsString() + "\n";
        }

        MessageBox.Show(strParamInfo);

        
return Result.Succeeded;
    }
}

//获得指定参数
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Automatic)]
//修改需要用此模式
public class GetSpecificParameterValue : IExternalCommand
{
    
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
        UIApplication uiApp 
= commandData.Application;
        Autodesk.Revit.ApplicationServices.Application app 
= uiApp.Application;
        Document doc 
= uiApp.ActiveUIDocument.Document;

        Selection sel 
= uiApp.ActiveUIDocument.Selection;
        sel.StatusbarTip 
= "Please select an window";
        sel.PickOne();
        Element elemPick 
= null;

        
foreach (Element elem in sel.Elements)
        {
            
if (elem is FamilyInstance)
            {
                elemPick 
= elem;
                
break;
            }
        }

        
if (elemPick != null)
        {
            
string strParamInfo = null;
            
//用BuiltInParameter来访问参数,与国家语言无关
            Parameter param = elemPick.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM);
            strParamInfo 
+= param.Definition.Name + " value is:" + param.AsValueString() + "\n";

            
//修改参数的值
            param.Set(3.6);

            
//使用名称来访问
            param = elemPick.get_Parameter("底高度");
            strParamInfo 
+= param.Definition.Name + " value is :" + param.AsValueString() + "\n";
            MessageBox.Show(strParamInfo);
        }

        
return Result.Succeeded;
    }
}

end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值