Revit 二次开发之“参数”

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
posted @ 2011-04-01 10:26  大气象  阅读(2630)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com