Revit MEP API找到连接器连接的连接器
通过conn.AllRefs;可以找到与之连接的连接器。
url:http://greatverve.cnblogs.com/p/revit-mep-api-AllRefs.html
//连接器连接的连接器
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdConnected : 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;
Transaction ts = new Transaction(doc, "revit");
ts.Start();
Reference refDuct = sel.PickObject(ObjectType.Element, "duct");
Duct duct = doc.GetElement(refDuct) as Duct;
ConnectorSetIterator csi = duct.ConnectorManager.Connectors.ForwardIterator();
while (csi.MoveNext())
{
Connector conn = csi.Current as Connector;
if (conn.IsConnected == true)//是否有连接
{
ConnectorSet connectorSet = conn.AllRefs;//找到所有连接器连接的连接器
ConnectorSetIterator csiChild = connectorSet.ForwardIterator();
while (csiChild.MoveNext())
{
Connector connected = csiChild.Current as Connector;
if (null != connected && connected.Owner.UniqueId != conn.Owner.UniqueId)
{
// look for physical connections
if (connected.ConnectorType == ConnectorType.End ||
connected.ConnectorType == ConnectorType.Curve ||
connected.ConnectorType == ConnectorType.Physical)
{
//判断是不是管件
if (connected.Owner is FamilyInstance)
{
TaskDialog.Show("fitting", connected.Owner.Name);
}
}
}
}
}
}
ts.Commit();
return Result.Succeeded;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdConnected : 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;
Transaction ts = new Transaction(doc, "revit");
ts.Start();
Reference refDuct = sel.PickObject(ObjectType.Element, "duct");
Duct duct = doc.GetElement(refDuct) as Duct;
ConnectorSetIterator csi = duct.ConnectorManager.Connectors.ForwardIterator();
while (csi.MoveNext())
{
Connector conn = csi.Current as Connector;
if (conn.IsConnected == true)//是否有连接
{
ConnectorSet connectorSet = conn.AllRefs;//找到所有连接器连接的连接器
ConnectorSetIterator csiChild = connectorSet.ForwardIterator();
while (csiChild.MoveNext())
{
Connector connected = csiChild.Current as Connector;
if (null != connected && connected.Owner.UniqueId != conn.Owner.UniqueId)
{
// look for physical connections
if (connected.ConnectorType == ConnectorType.End ||
connected.ConnectorType == ConnectorType.Curve ||
connected.ConnectorType == ConnectorType.Physical)
{
//判断是不是管件
if (connected.Owner is FamilyInstance)
{
TaskDialog.Show("fitting", connected.Owner.Name);
}
}
}
}
}
}
ts.Commit();
return Result.Succeeded;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步