Revit MEP二次开发之连接器Connector

连接器是mep的专有概念,相当于管类的内置几何参数。
比如一条风管,相当于一条线段,线段就有两个端点。
这两个端点就保存在连接器中。
其他可能有不止两个端点的概念。
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Manual)]
[Journaling(JournalingMode.NoCommandData)]
public   class  GetConnector : IExternalCommand
{
    
public  Result Execute(ExternalCommandData commandData,  ref   string  messages, ElementSet elements)
    {
        
try
        {
            
if  ( null   ==  commandData)
            {
                
throw   new  ArgumentNullException( " commandData " );
            }

            UIApplication uiApp 
=  commandData.Application;
            Document doc 
=  uiApp.ActiveUIDocument.Document;
            Selection sel 
=  uiApp.ActiveUIDocument.Selection;

            MessageBox.Show(
" 请选择一个风管 " );

            Reference refelem 
=  sel.PickObject(ObjectType.Element,  " 请选择一个风管 " );

            Duct duct 
=  refelem.Element  as  Duct;
            
if  (duct  ==   null )
            {
                
return  Result.Cancelled;
            }

            
// 取得对象连接器集合的方法
            ConnectorSetIterator csi  =  duct.ConnectorManager.Connectors.ForwardIterator();

            IList
< XYZ >  xyzList  =   new  List < XYZ > ();
            
while  (csi.MoveNext())
            {
                Connector conn 
=  csi.Current  as  Connector; // 遍历所有的连接器
                xyzList.Add(conn.Origin);
            }

            doc.Delete(duct);
// 删除风管
            
// NewLine(xyz1,xyz2,是线段还是直线);在原来的位置画一条直线直线,却不显示。
            uiApp.Application.Create.NewLine(xyzList.ElementAt( 0 ), xyzList.ElementAt( 1 ),  true );

            
// 在原来的位置创建一个Pipe
            FilteredElementCollector filterCollector  =   new  FilteredElementCollector(doc);
            filterCollector.OfClass(
typeof (PipeType));
            PipeType pipeType 
=  filterCollector.FirstElement()  as  PipeType;

            
if  ( null   !=  pipeType)
            {
                doc.Create.NewPipe(xyzList.ElementAt(
0 ), xyzList.ElementAt( 1 ), pipeType);
            }
        }
        
catch  (Exception e)
        {
            messages 
=  e.Message;
            
return  Result.Failed;
        }

        
return  Result.Succeeded;
    }
}
20110330更新
连接器的方向
/* 判断风管的流方向
 * 双向     FlowDirectionType.Bidirectional
 * 只进不出 FlowDirectionType.In
 * 只出不进 FlowDirectionType.Out
 
*/
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Automatic)]
public   class  theDirectionType : IExternalCommand
{
    
public  Result Execute(ExternalCommandData commandData,  ref   string  message, ElementSet elements)
    {
        UIApplication uiApp 
=  commandData.Application;
        Document doc 
=  uiApp.ActiveUIDocument.Document;
        Selection sel 
=  uiApp.ActiveUIDocument.Selection;

        Reference refelem 
=  sel.PickObject(ObjectType.Element,  " 请选择一个风管 " );
        Duct duct 
=  refelem.Element  as  Duct;

        ConnectorSetIterator csi 
=  duct.ConnectorManager.Connectors.ForwardIterator();
        
while  (csi.MoveNext())
        {
            Connector conn 
=  csi.Current  as  Connector;
            
if  (conn.Direction  ==  FlowDirectionType.Bidirectional)
            {
                MessageBox.Show(
" 双向 " );
            }
            
else   if  (conn.Direction  ==  FlowDirectionType.In)
            {
                MessageBox.Show(
" 只进不出 " );
            }
            
else   if  (conn.Direction  ==  FlowDirectionType.Out)
            {
                MessageBox.Show(
" 只出不进 " );
            }
        }

        
return  Result.Succeeded;
    }
}
end
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值