Revit 二次开发之“在两个机械设备之间创建风管”

在项目浏览器中,族->机械设备->M_VAV机组->尺寸 2 - 150mm 入口
创建一个族实例,再添加一个弯头,选中这两个设备。
//在两个机械设备之间添加风管
public Duct CreateDuctBetweenConnectors(UIDocument uiDocument)
{
    Connector connector1 
= null, connector2 = null;
    ConnectorSetIterator csi 
= null;
    ElementSet selection 
= uiDocument.Selection.Elements;
    
foreach (Element e in selection)
    {
        
if (e is FamilyInstance)
        {
            FamilyInstance fi 
= e as FamilyInstance;
            Family family 
= fi.Symbol.Family;
            
if (family.FamilyCategory.Name == "机械设备")
            {
                csi 
= fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
                
while (csi.MoveNext())
                {
                    Connector conn 
= csi.Current as Connector;
                    
//找到出风口且是送风系统
                    if (conn.Direction == FlowDirectionType.Out && conn.DuctSystemType == DuctSystemType.SupplyAir)
                    {
                        connector1 
= conn;
                        
break;
                    }
                }
            }
        }
    }
    
foreach (Element e in selection)
    {
        
if (e is FamilyInstance)
        {
            FamilyInstance fi 
= e as FamilyInstance;
            Family family 
= fi.Symbol.Family;
            
if (family.FamilyCategory.Name != "机械设备")
            {
                csi 
= fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
                
while (csi.MoveNext())
                {
                    
if (null == connector2)
                    {
                        Connector conn 
= csi.Current as Connector;
                        
//判断是不是在一条平行线上
                        if (Math.Abs(conn.Origin.Y - connector1.Origin.Y) < 0.001)
                        {
                            connector2 
= conn;
                            
break;
                        }
                    }
                }
            }
        }
    }
    Duct duct 
= null;
    
if (null != connector1 && null != connector2)
    {
        FilteredElementCollector collector 
= new FilteredElementCollector(uiDocument.Document);
        collector.OfClass(
typeof(DuctType));
        
//随便找个风管类型,矩形风管,半径弯头/接头
        var query = from element in collector
                    
where element.Name.Contains("弯头"== true
                    select element;
        DuctType ductType 
= collector.Cast<DuctType>().First<DuctType>();
        
if (null != ductType)
        {
            duct 
= uiDocument.Document.Create.NewDuct(connector1, connector2, ductType);
        }
    }
    
return duct;
}
fromhttp://revit.5d6d.com/thread-857-1-4.html
posted @ 2011-07-13 11:43  大气象  阅读(1536)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com