|
Revit 的自带功能以及API的功能都只能在墙上开矩形洞口。有许多的时候需要在墙上开圆形洞口。比如为暖气管道,开圆形洞口。那么有什么办法可以实现呢?
我们有一个变通的办法,就是在墙上插入一个圆形的Generic Model族实例,这个族只有一个Opening cut,放在墙上后,效果上讲与洞口一模一样,因为窗户本身并没有添加任何对象。 在Revit architecture自带族中就有一个这个族,可以直接使用。在我的win7系统中,该族位于这个目录下: C:\ProgramData\Autodesk\RAC 2012\Libraries\US Imperial\Windows\Opening.rfa
编程时,只要向墙上插入这个Generic Model实例即可(调用NewFamilyInstance 函数)。也可修改圆形窗户的半径,达到修改洞口大小。
请看下面代码演示如何创建洞口。请修改你的洞口的插入位置,以及合适的Generic Model 类型名称。
-
- [csharp] view plaincopy
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.Linq;
-
- using Autodesk.Revit .DB;
- using Autodesk.Revit.UI;
- using Autodesk.Revit.UI.Selection;
- using Autodesk.Revit .ApplicationServices;
- using Autodesk.Revit.Attributes ;
-
-
-
- [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
- public class RevitCommand : IExternalCommand
- {
- public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
- {
- UIApplication app = commandData.Application;
- Document doc = app.ActiveUIDocument.Document;
- //获取一个圆形洞口类型
- FilteredElementCollector collector = new FilteredElementCollector(doc);
- collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_GenericModel);
-
- var types = from elem in collector
- where elem.Name.Equals("JoeTest")
- select elem;
- Element elemtype = types.First();
- FamilySymbol symbol = elemtype as FamilySymbol;
-
- //获得墙
- Selection sel = app.ActiveUIDocument.Selection;
- Reference ref1 = sel.PickObject(ObjectType.Element, "please pick a wall");
- Wall wall = doc.GetElement(ref1) as Wall;
- if (wall != null)
- {
-
- Transaction trans = new Transaction(doc, "ExComm");
- trans.Start();
-
- XYZ insertPt = new XYZ(-9.04985104228567, 21.6724350178627, 2.93498579446767); //请按照你的坐标,修改这里的坐标
- FamilyInstance instance = doc.Create.NewFamilyInstance(insertPt, symbol, wall, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
- trans.Commit();
- }
- return Result.Succeeded ;
- }
- }
复制代码 作者:叶雄进文章来源:http://blog.csdn.net/joexiongjin/article/category/782739
|
|