[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd20120604 : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = cmdData.Application.Application;
Selection sel = uiDoc.Selection;
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
collector.OfClass(typeof(Opening)).OfCategory(BuiltInCategory.OST_SWallRectOpening);
//wallId 618627
var wallOpenings = from c in collector where ((Opening)c).Host.Id == new ElementId(618627) select c;
foreach (Element el in wallOpenings.ToList())
{
Opening opening = el as Opening;
if (opening.IsRectBoundary)
{
//opening.BoundaryRect;
//opening.BoundaryCurves;
}
}
WinFormTools.MsgBox(wallOpenings.Count().ToString());
return Result.Succeeded;
}
}
问题:
通过Document.Create.NewOpening(wall, xyz1, xyz2); 可在墙上开洞。
假如下次执行同样的操作revit自身会报错,没有可剪切的墙体。
请问:怎样判断那个位置已经开洞?
答:
1. 你可以用Opening类为条件,过滤出Opening对象,再根据Linq 查询,找出在一个给定墙上的Opening对象。 使用条件: Opening.Host == givenWallId.
这样就可以获得墙上所有的洞口。
2. 然后可以从Opening.IsRectBoundary 判断洞口是否为矩形。矩形洞口的两个对角点坐标可以从Opening.BoundingRect 获得。也可以获得矩形的四个边Opening.BoundaryCurves.
3. 既然获得洞口尺寸和位置,你就可以判断你的目标洞口与原有洞口的关系。