您的位置:首页 > 其它

Revit二次开发示例:DeleteDimensions

2014-03-17 17:01 429 查看
在本例中,创建一个命令,实现删除所选中的尺寸标注。

#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion

namespace DeleteDimensions
{
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(JournalingMode.NoCommandData)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
ElementSet selections = commandData.Application.ActiveUIDocument.Selection.Elements;
ElementSet dimsToDelete = new ElementSet();

if (0 == selections.Size)
{
message = "Please select dimensions";
return Result.Failed;
}

foreach (Element e in selections)
{
Dimension dimensionTemp = e as Dimension;
if (null != dimensionTemp && !dimensionTemp.Pinned)
{
dimsToDelete.Insert(dimensionTemp);
}
}

if (0 == dimsToDelete.Size)
{
message = "There are no unpinned dimensions currently selected";
return Result.Failed;
}

Transaction transation = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");

transation.Start();

foreach (Element e in dimsToDelete)
{
commandData.Application.ActiveUIDocument.Document.Delete(e.Id);
}
transation.Commit();

return Result.Succeeded;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: