这是我在这里的第一个问题。我是 revit api 编程的初学者,所以如果我的问题太蹩脚或方向错误,我很抱歉。希望可以有人帮帮我。我正在尝试在这个简单的学习示例中实现 Iscommand 可用方法,但我无法理解它为什么不起作用,我的意思是该命令在任何情况下仍然可以使用。提前致谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Windows.Forms;
namespace PruebasAPI
{
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Automatic)]
class IExternalcommand_elements : IExternalCommand
{
public bool IsCommandAvailable(Autodesk.Revit.UI.UIApplication applicationData,
CategorySet selectedCategories)
{
//allow button click if there is no active selection
if (selectedCategories.IsEmpty)
return true;
//allow button click if there is at least one wall selected
foreach (Category c in selectedCategories)
{
if (c.Id.IntegerValue == (int)BuiltInCategory.OST_Walls)
return true;
}
return false;
}
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
try
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
//delete selected elements
ICollection<Autodesk.Revit.DB.ElementId> ids = doc.Delete(uidoc.Selection.Elements);
TaskDialog taskdialog = new TaskDialog("Revit");
taskdialog.MainContent =
("click yes to return succeded.Selected members will be deleted. \n" +
"click no to return failed.Selected members will not be deleted \n" +
"click cancel to return cancelled. Selected members will not be deleted.");
TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel;
taskdialog.CommonButtons = buttons;
TaskDialogResult taskdialogresult = taskdialog.Show();
if (taskdialogresult == TaskDialogResult.Yes)
{
return Result.Succeeded;
}
else if (taskdialogresult == TaskDialogResult.No)
{
elements = uidoc.Selection.Elements;
message = "failed to delete selection";
return Result.Failed;
}
else
{
return Result.Cancelled;
}
}
catch
{
message = "unespected dika";
return Result.Failed;
}
}
}
}`