RME二次开发之“修改矩形风管为圆形风管”即实现“天圆地方”连接。

当两个矩形风管用弯头连接的时候,如果把其中一个修改成圆形风管。
就会自动创建天圆地方。所以这里的问题就转移到,怎样修改矩形风管为圆形风管。
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Automatic)]
public class ChangeDuctKind : IExternalCommand
{
    
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
        
try
        {
            UIDocument uidoc 
= commandData.Application.ActiveUIDocument;
            
//得到选择的对象
            Selection selection = uidoc.Selection;
            ElementSet collection 
= selection.Elements;

            
//遍历得到所有风管类型
            FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document);
            collector.OfClass(
typeof(DuctType));
            
//if (collector != null)
            
//    collector.OfCategory(BuiltInCategory.OST_Walls);
            IList<Element> list = collector.ToElements();

            DuctType dType 
= null;
            
for (int i = 0; i < list.Count; i++)
            {
                
if (list.ElementAt(i).Name == "T 形三通")//属于圆形风管
                    dType = list.ElementAt(i) as DuctType;
            }

            
if (0 == collection.Size)
            {
                TaskDialog.Show(
"Revit""You haven't selected any elements");
            }
            
else
            {
                
foreach (Element elem in collection)
                {
                    Duct duct 
= elem as Duct;
                    
if (duct != null)
                    {
                        duct.DuctType 
= dType;//通过修改DuctType可以修改DuctKind
                    }
                }
            }
        }
        
catch (Exception e)
        {
            messages 
= e.Message;
            
return Result.Failed;
        }
        
return Result.Succeeded;
    }
}
此法已过时,Revit2012可以直接使用NewEblowFitting()创建天圆地方连接。
from:http://revit.5d6d.com/thread-865-1-4.html
posted @ 2011-07-20 11:36  大气象  阅读(1797)  评论(1编辑  收藏  举报
http://www.tianqiweiqi.com