2012-04-01 30 views
1

これは私の最初の質問です。私はRevit APIプログラミングの初心者なので、私の質問があまりにも不自由であるかミスリエンティであるのならごめんなさい。誰かが私を助けることを願っています。私はこの単純な学習の例でIscommand利用可能なメソッドを実装することを試行しています。なぜそれがうまくいかないのか、なぜそれがうまくいかないのでしょうか。コマンドがまだどのシナリオでも利用可能であることを意味します。前もって感謝します!"IscommandAvailable"を動作させることはできません

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; 
     } 
    } 
} 

} `

答えて

2

IsCommandAvailableは、あなたのコマンドクラスであってはなりません。実際には、IExternalCommandAvailabilityを実装するクラスを記述する必要があります。ここではAPIガイドからの例です:

public class SampleAccessibilityCheck : IExternalCommandAvailability 
{ 
    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; 
    } 
} 

次に、あなたのような、タグAvailabilityClassName中にあなたアドインマニフェストファイル内のこのクラス名を指定することができます:あなたはリボン上のボタンを使用している場合

<AvailabilityClassName>MyNamespace.SampleAccessibilityCheck</AvailabilityClassName> 

PushButtonクラスにはPushButton.AvailabilityClassNameプロパティもあります。このプロパティでは、このクラスの名前を設定して、コマンドボタンでそれに応じて有効/無効を切り替えることができます。

これが役に立ちます。

+0

ありがとうございました!出来た!それはあなたの反応を得ることを非常に慰めていました。ありがとうBugra! – PANANO

+0

StackOverflowへようこそPANANO。この回答があなたの問題を解決した場合は、それを合格とマークしてください。 – skeletank

関連する問題