关于Revit API修改元素参数的问题?
>ADN: DEVR3894
>ADN service level: Professional
>产品:Revit MEP 2012
>版本:2012
>语言:中文
>操作系统:window7 64bit
>联系电话:137xxxx1960
>问题标题:关于修改元素参数的问题?
>问题内容:
上次提问,关于遍历链接文档创建空间的问题。
最终解决办法是:在链接文档的时候选择“原点到原点”
失败的原因就是坐标系没有对正。
这次的问题如下:
我希望在风管连接弯头之前,设置好首选的弯头类型。
1.元素参数如果是int或者double可以直接修改。
如果是ElementId如何知道从哪里得到这些Id
2.如图所示,编辑风管类型。
![](https://images.cnblogs.com/cnblogs_com/greatverve/2012022901.jpg)
如何改变T形三通,接头,这样的参数的值。
参考代码:
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
UIApplication uiApp = cmdData.Application;
Document doc = uiDoc.Document;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(doc, "www");
ts.Start();
//找个风管类型
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Duct)).OfCategory(BuiltInCategory.OST_DuctCurves);
Duct duct = null;
foreach (Element el in collector)
{
duct = el as Duct;
break;
}
//找个弯头类型
FilteredElementCollector collectorFitting = new FilteredElementCollector(doc);
collectorFitting.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_DuctFitting);
FamilyInstance fitting = null;
foreach (Element el in collectorFitting)
{
fitting = el as FamilyInstance;
break;
}
//
foreach (Parameter p in duct.DuctType.Parameters)
{
if (p.Definition.Name == "首选连接类型")
{
p.Set(1);//p.StorageType为Intger所以用此法修改
}
if (p.Definition.Name == "接头")
{
p.Set(fitting.Category.Id);//p.StorageType为ElementId
}
}
ts.Commit();
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
UIApplication uiApp = cmdData.Application;
Document doc = uiDoc.Document;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(doc, "www");
ts.Start();
//找个风管类型
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Duct)).OfCategory(BuiltInCategory.OST_DuctCurves);
Duct duct = null;
foreach (Element el in collector)
{
duct = el as Duct;
break;
}
//找个弯头类型
FilteredElementCollector collectorFitting = new FilteredElementCollector(doc);
collectorFitting.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_DuctFitting);
FamilyInstance fitting = null;
foreach (Element el in collectorFitting)
{
fitting = el as FamilyInstance;
break;
}
//
foreach (Parameter p in duct.DuctType.Parameters)
{
if (p.Definition.Name == "首选连接类型")
{
p.Set(1);//p.StorageType为Intger所以用此法修改
}
if (p.Definition.Name == "接头")
{
p.Set(fitting.Category.Id);//p.StorageType为ElementId
}
}
ts.Commit();
return Result.Succeeded;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。