• 大小: 33KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-06-13
  • 语言: 其他
  • 标签: Revit  二次开发  

资源简介

包含《Autodesk Revit 二次开发基础教程》所有示例代码片段,方便初学者免去重新敲代码的麻烦。

资源截图

代码片段和文件信息

//============代码片段2-1:外部命令中Excute函数的定义============
public interface IExternalCommand
{
  public Autodesk.Revit.UI.Result Execute(
   Autodesk.Revit.UI.ExternalCommandData commandData
   ref string message
   Autodesk.Revit.DB.ElementSet elements)
}

//============代码片段2-2:从commandData中取到Document============
UIApplication uiApplication = commandData.Application;
Application application = uiApplication.Application;
UIDocument uiDocument = uiApplication.ActiveUIDocument;
Document document = uiDocument.Document;

//============代码片段2-3:使用message参数============
   public class command : IExternalCommand
   {
      public Result Execute(
             ExternalCommandData commandData
             ref string message
             ElementSet elements)
      {
         message = “message test“;
         return Result.Failed;
      }
   }

//============代码片段2-4:使用element参数============
public Result Execute(ExternalCommandData commandData ref string message ElementSet elements)
{
   message = “Please take attention on the highlighted Walls!“;
   //先从UI选取元素,然后执行该插件
   ElementSet elems = commandData.Application.ActiveUIDocument.Selection.Elements;
   foreach (Element elem in elems)
   {
      Wall wall = elem as Wall;
      if (null != wall)
      {
   elements.Insert(elem);
      }
   }
   return Result.Failed;
}

//============代码片段2-5:外部命令中Excute函数的返回值============
public Result Execute(ExternalCommandData commandData ref string message ElementSet elements)
{
   try
   {
      UIDocument uiDoc = commandData.Application.ActiveUIDocument;
      Document doc = uiDoc.Document;
      List selectedElem = new List();
      foreach(Element elem in uiDoc.Selection.Elements)
      {
         selectedElem.Add(elem.Id);
      }

      doc.Delete(selectedElem);

      TaskDialogResult result = TaskDialog.Show(
         “Revit“
         “Yes to return succeeded and delete all selection“+
         “No to cancel all commands.“
         TaskDialogCommonButtons.Yes|TaskDialogCommonButtons.No);

      if (TaskDialogResult.Yes == result)
      {
         return Result.Succeeded;
      }
      else if (TaskDialogResult.No == result)
      {
         elements = uiDoc.Selection.Elements;
         message = “Failed to delete selection.“;
         return Result.Failed;
      }
      else
      {
         return Result.Cancelled;
      }
   }
   catch
   {
      message = “Unexpected Exception is thrown out.“;
      return Result.Failed;
   }
}

//============代码片段2-6:IExternalApplication接口定义============
public interface IExternalApplication
{
   Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application);
   Autodesk.Revit.UI.Result onstartup(UIControlledApplication application);
}

//============代码片段2-7:使用IExternalApplication定制UI============
public Autodesk.Revit.UI.Result onstartup(UIControlledApplication application)
{
   //添加一个新的Ribbon面板
   RibbonPanel ribbonPanel = application.CreateRibbonPanel(“NewRibbonPanel“);

   //在新的Ribbon面板上添加一个按钮
 

评论

共有 条评论