刚刚在我们ADN的全球博客里发布了一篇这篇文章。在这里给出同一个链接。
现在Revit没有开放直接可用的API从DuctType来获取管道类型的形状。本文给出了一个替代解决办法来获取。
思路是这样的: 从风管类型获取与风管类型关联的弯头族类型,然后打开这个弯头族,在从打开的族文档中获取连接件DuctConnector的截面形状。
这个事可以工作的。但是效率不是很高,因为需要打开族的文档(EditFamily),对于需要连读取多个风管类型的界面形状,需要一些等待的时间。
原文请参见:
http://adndevblog.typepad.com/aec/2013/03/how-to-get-the-duct-section-shape-for-duct-type-object.html
实现代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
[TransactionAttribute(TransactionMode.Manual)]
public class RevitCommand : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string messages,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Selection sel = app.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(
ObjectType.Element, "please pick a duct");
Duct duct = doc.GetElement(ref1) as Duct;
if(duct == null)
{
messages = "You didn't select a duct";
return Result.Failed;
}
DuctType ductType = duct.DuctType;
//Get the duct type's elbow parameter value.
Parameter param = ductType.get_Parameter(
BuiltInParameter.RBS_CURVETYPE_DEFAULT_ELBOW_PARAM);
FamilySymbol symbol =
doc.get_Element(param.AsElementId()) as FamilySymbol;
Family family = symbol.Family;
Document familyDoc = doc.EditFamily(family);
FilteredElementCollector collector =
new FilteredElementCollector(familyDoc);
collector.OfClass(typeof(ConnectorElement));
Element firstConnector = collector.FirstElement();
DuctConnector connector = firstConnector as DuctConnector;
TaskDialog.Show("Duct Section Shape", connector.Shape.ToString());
familyDoc.Close(false);
return Result.Succeeded ;
}
}