This is my first question here. I'm a beginner in revit api programming, so I'm sorry if my question is too lame or missoriented. Hope someone can help me. I´m triying to implement the Iscommand available method in this simple learning example and I can´t undestand why it is not working, I mean the command is still available to use under any scenario. Thanks in advance!
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;
}
}
}
}`