RME二次开发之“修改矩形风管为圆形风管”即实现“天圆地方”连接。
当两个矩形风管用弯头连接的时候,如果把其中一个修改成圆形风管。
就会自动创建天圆地方。所以这里的问题就转移到,怎样修改矩形风管为圆形风管。
from:http://revit.5d6d.com/thread-865-1-4.html
[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;
}
}
[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()创建天圆地方连接。 |
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。

浙公网安备 33010602011771号