Autodesk.Revit.DB.Architecture.TopographyEditScope是Revit API中的一个类,用于在特定的上下文环境中进行地形编辑。该类通常用于启动地形编辑操作,并在编辑完成后自动撤销对数据库的更改。
以下示例演示了如何使用TopographyEditScope将地形高度高于500英尺的点删除:
// 获取Revit文档
Document doc = commandData.Application.ActiveUIDocument.Document;
// 获取要编辑的地形
TopographySurface surface = null;
if (null != doc.ActiveView)
{
FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
surface = collector.OfClass(typeof(TopographySurface)).Cast<TopographySurface>().FirstOrDefault();
}
if (null != surface)
{
// 创建TopographyEditScope
using (TopographyEditScope editScope = new TopographyEditScope(doc, "Delete Points"))
{
editScope.Start(surface.Id);
// 遍历所有点
foreach (UV point in surface.GetPoints())
{
double elevation = surface.GetElevation(point);
if (elevation > 500)
{
surface.DeleteVertex(point);
}
}
// 结束TopographyEditScope
editScope.Commit(new TopographyEditScopeFinishOptions());
}
}
TopographyEditScope(Document, String)
bool IsActive
void Start(ElementId)
void Commit(TopographyEditScopeFinishOptions)
void Dispose()
using
语句块中使用TopographyEditScope对象,以确保及时处理所有资源。