Revit 二次开发之“参数”
start
end
//遍历全部参数
[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;
}
}
[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
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。