C# Revit API-错误的完整类名

C# Revit API-错误的完整类名,c#,revit-api,revit,revit-2015,C#,Revit Api,Revit,Revit 2015,我对C#和编码非常陌生。如果可能的话,我希望得到一些帮助,弄清楚如何修复这段代码 他们各自工作。我可以在功能区上创建一个新按钮并执行标准的hello world。我还有一个宏,可以成功地删除所有图纸和视图,但是尝试将两者结合起来会带来很大的困难!代码生成正常,但我在revit中遇到以下错误: '未能初始化外接程序“删除视图”,因为类 在外接程序程序集中找不到“DeleteView”。FullClassName 提供Revit调用外接程序应用程序的入口点。对于 Revit若要运行外接程序,必须确保

我对C#和编码非常陌生。如果可能的话,我希望得到一些帮助,弄清楚如何修复这段代码

他们各自工作。我可以在功能区上创建一个新按钮并执行标准的hello world。我还有一个宏,可以成功地删除所有图纸和视图,但是尝试将两者结合起来会带来很大的困难!代码生成正常,但我在revit中遇到以下错误:

'未能初始化外接程序“删除视图”,因为类 在外接程序程序集中找不到“DeleteView”。FullClassName 提供Revit调用外接程序应用程序的入口点。对于 Revit若要运行外接程序,必须确保此类实现 “Autodesk.Revit.UI.ExternalCommand”界面

我很确定我的问题是在这第二段代码中引用。我知道我打错电话了,但还没有找到任何解决办法

如果这是一个愚蠢的问题,我深表歉意,但我真的非常感谢任何帮助我学习的帮助

谢谢你能给我的任何帮助

守则:

namespace BGPanel
{
public class CsBGPanel : IExternalApplication
{
    public UIDocument ActiveUIDocument { get; private set; }
    public Result OnStartup(UIControlledApplication application)
    {
        RibbonPanel ribbonPanel = application.CreateRibbonPanel("Tools");

        string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
        PushButtonData buttonData = new PushButtonData("cmdDeleteViews",
           "Delete Views", thisAssemblyPath, "BGPanel.DeleteViews");

        PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;

        pushButton.ToolTip = "Delete all sheets, schedules & views except structural plans";

        Uri uriImage = new Uri(@"C:\Revit_API\Revit_2015\32px-Broom.png");
        BitmapImage largeImage = new BitmapImage(uriImage);
        pushButton.LargeImage = largeImage;

        return Result.Succeeded;
    }

         public void DeleteViews()
    {
        UIDocument uidoc = this.ActiveUIDocument;
        Document doc = uidoc.Document;

        FilteredElementCollector collector = new FilteredElementCollector(doc);
        ICollection<Element> collection = collector.OfClass(typeof(View)).ToElements();

        using (Transaction t = new Transaction(doc, "Delete Views"))
        {
            t.Start();

            int x = 0;

            foreach (Element e in collection)
            {
                try
                {
                    View view = e as View;

                    switch (view.ViewType)
                    {
                        case ViewType.FloorPlan:
                            break;
                        case ViewType.EngineeringPlan:
                            break;
                        case ViewType.ThreeD:
                            break;
                        default:
                            doc.Delete(e.Id);
                            x += 1;
                            break;
                    }
                }
                catch (Exception ex)
                {
                    View view = e as View;
                    TaskDialog.Show("Error", e.Name + "\n" + "\n" + ex.Message);
                    TaskDialog.Show("Error", ex.Message);
                }
            }
            t.Commit();

            TaskDialog.Show("BG_API DeleteViews", "Views Deleted: " + x.ToString());
        }

    }
    public Result OnShutdown(UIControlledApplication application)
    {
        return Result.Succeeded;
    }
}
}
名称空间面板
{
公共类CsBGPanel:IExternalApplication
{
公共UIDocument ActiveUIDocument{get;private set;}
启动时的公共结果(uicontrolLED应用程序)
{
RibbonPanel RibbonPanel=application.CreateRibbonPanel(“工具”);
字符串thisAssemblyPath=Assembly.GetExecutionGassembly().Location;
PushButtonData buttonData=新的PushButtonData(“CmdDeleteView”,
“删除视图”,thisAssemblyPath,“BGPanel.DeleteViews”);
按钮按钮=ribbonPanel.AddItem(buttonData)作为按钮;
putton.ToolTip=“删除除结构平面外的所有图纸、明细表和视图”;
Uri URIMAGE=新Uri(@“C:\Revit\U API\Revit\U 2015\32px Broom.png”);
BitmapImage largeImage=新的BitmapImage(uriImage);
按钮。大图像=大图像;
返回结果。成功;
}
公共视图()
{
UIDocument uidoc=this.ActiveUIDocument;
单据单据=uidoc.单据;
FilteredElementCollector=新的FilteredElementCollector(单据);
ICollection collection=collector.OfClass(typeof(View)).ToElements();
使用(事务t=新事务(文档,“删除视图”))
{
t、 Start();
int x=0;
foreach(集合中的元素e)
{
尝试
{
视图=e作为视图;
开关(view.ViewType)
{
案例ViewType.FloorPlan:
打破
案例视图类型.工程平面图:
打破
案例ViewType.ThreeD:
打破
违约:
删除文件(e.Id);
x+=1;
打破
}
}
捕获(例外情况除外)
{
视图=e作为视图;
TaskDialog.Show(“错误”,例如Name+“\n”+“\n”+ex.Message);
TaskDialog.Show(“错误”,例如消息);
}
}
t、 提交();
TaskDialog.Show(“BG_API删除视图”,“删除视图:”+x.ToString());
}
}
关闭时的公共结果(uicontrol LED应用程序)
{
返回结果。成功;
}
}
}

首先,不要自己键入类名,考虑使用反射:

typeof(YourClassName).FullName
其次,Revit中的每个命令都需要自己的类来实现
IExternalCommand
。我还没有测试,但您的代码应该如下所示:

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Media.Imaging;

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace BGPanel
{
  public class CsBGPanel : IExternalApplication
  {
    public Result OnStartup(UIControlledApplication application)
    {
      RibbonPanel ribbonPanel = application.CreateRibbonPanel("Tools");

      string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
      PushButtonData buttonData = new PushButtonData("cmdDeleteViews",
         "Delete Views", thisAssemblyPath, typeof(DeleteViews).FullName);

      PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;

      pushButton.ToolTip = "Delete all sheets, schedules & views except structural plans";

      Uri uriImage = new Uri(@"C:\Revit_API\Revit_2015\32px-Broom.png");
      BitmapImage largeImage = new BitmapImage(uriImage);
      pushButton.LargeImage = largeImage;

      return Result.Succeeded;
    }

    public Result OnShutdown(UIControlledApplication application)
    {
      return Result.Succeeded;
    }
  }

  public class DeleteViews : IExternalCommand
  {
    // this will not work...
    //public UIDocument ActiveUIDocument { get; private set; }

    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
      UIDocument uidoc = commandData.Application.ActiveUIDocument; //this.ActiveUIDocument;
      Document doc = uidoc.Document;

      FilteredElementCollector collector = new FilteredElementCollector(doc);
      ICollection<Element> collection = collector.OfClass(typeof(View)).ToElements();

      using (Transaction t = new Transaction(doc, "Delete Views"))
      {
        t.Start();

        int x = 0;

        foreach (Element e in collection)
        {
          try
          {
            View view = e as View;

            switch (view.ViewType)
            {
              case ViewType.FloorPlan:
                break;
              case ViewType.EngineeringPlan:
                break;
              case ViewType.ThreeD:
                break;
              default:
                doc.Delete(e.Id);
                x += 1;
                break;
            }
          }
          catch (Exception ex)
          {
            View view = e as View;
            TaskDialog.Show("Error", e.Name + "\n" + "\n" + ex.Message);
            TaskDialog.Show("Error", ex.Message);
          }
        }
        t.Commit();

        TaskDialog.Show("BG_API DeleteViews", "Views Deleted: " + x.ToString());
      }
      return Result.Succeeded; // must return here
    }
  }
}
使用系统;
使用System.Collections.Generic;
运用系统反思;
使用System.Windows.Media.Imaging;
使用Autodesk.Revit.DB;
使用Autodesk.Revit.UI;
名称空间面板
{
公共类CsBGPanel:IExternalApplication
{
启动时的公共结果(uicontrolLED应用程序)
{
RibbonPanel RibbonPanel=application.CreateRibbonPanel(“工具”);
字符串thisAssemblyPath=Assembly.GetExecutionGassembly().Location;
PushButtonData buttonData=新的PushButtonData(“CmdDeleteView”,
“删除视图”,thisAssemblyPath,typeof(DeleteViews).FullName);
按钮按钮=ribbonPanel.AddItem(buttonData)作为按钮;
putton.ToolTip=“删除除结构平面外的所有图纸、明细表和视图”;
Uri URIMAGE=新Uri(@“C:\Revit\U API\Revit\U 2015\32px Broom.png”);
BitmapImage largeImage=新的BitmapImage(uriImage);
按钮。大图像=大图像;
返回结果。成功;
}
关闭时的公共结果(uicontrol LED应用程序)
{
返回结果。成功;
}
}
公共类DeleteViews:IExternalCommand
{
//这行不通。。。
//公共UIDocument ActiveUIDocument{get;private set;}
公共结果执行(ExternalCommandData commandData、ref字符串消息、ElementSet元素)
{
UIDocument uidoc=commandData.Application.ActiveUIDocument;//this.ActiveUIDocument;
单据单据=uidoc.单据;
FilteredElementCollector=新的FilteredElementCollector(单据);
ICollection collection=collector.OfClass(typeof(View)).ToElements();
使用(事务t=新事务(文档,“删除视图”))
{
t、 Start();
int x=0;
foreach(集合中的元素e)
{
尝试
{
视图=e作为视图;
开关(view.ViewType)
{
案例ViewType.FloorPlan:
打破
案例视图类型.工程平面图:
打破
案例ViewType.ThreeD:
打破
违约:
德博士
[Transaction(TransactionMode.Manual)]