管道只能通过PipeType过滤出来类型属性,只能是系统族的类型属性。
管道实例过滤不能用族符号和族实例,要用Pipe
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Architecture;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Selection sel = uiApp.ActiveUIDocument.Selection;
Transaction ts = new Transaction(doc, "http://revit.5d6d.com");
ts.Start();
FilteredElementCollector collector = new FilteredElementCollector(doc);
//此法可以只过滤系统类型
collector.OfCategory(BuiltInCategory.OST_PipeCurves);
foreach (Element el in collector.ToElements())
{
PipeType pipeType = el as PipeType;//管道类型有专有类型
if (pipeType != null)
TaskDialog.Show("pipetype", pipeType.Name);
FamilySymbol symbol = el as FamilySymbol;//即不是族符号
if (symbol != null)
TaskDialog.Show("symbol", symbol.Name);
FamilyInstance fi = el as FamilyInstance;//也不是族实例
if(fi!=null)
TaskDialog.Show("fi", fi.Name);
Pipe pipe = el as Pipe;
if (pipe != null)
TaskDialog.Show("pipe", pipe.Name);
}
ts.Commit();
return Result.Succeeded;
}
}
}url:http://greatverve.cnb
logs.com/p/api-pipe-type.html