매크로 소스 코드 예

다음 코드 샘플을 사용하여 매크로 관리자 도구를 탐색합니다.

Hello World

이 코드 예제는 "Hello World"라는 내용이 포함된 "Dialog"라는 제목의 대화상자를 엽니다.
using Autodesk.Revit.UI;

namespace My_First_Module
{
   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   [Autodesk.Revit.DB.Macros.AddInId("E04BAFB6-D442-457A-A88C-CF2D7208793E")]
   public partial class ThisApplication
   {
      private void Module_Startup(object? sender, EventArgs e)
      {

      }

      private void Module_Shutdown(object? sender, EventArgs e)
      {

      }

      public void hello()
      {
         TaskDialog.Show("Dialog", "Hello World");
      }

   }
}

샘플 매크로 실행:

모든 요소 선택

이 코드 예제는 현재 모델의 모든 요소를 선택합니다.
using Autodesk.Revit.DB;

namespace My_First_Module
{
   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   [Autodesk.Revit.DB.Macros.AddInId("E04BAFB6-D442-457A-A88C-CF2D7208793E")]
   public partial class ThisApplication
   {
      private void Module_Startup(object? sender, EventArgs e)
      {

      }

      private void Module_Shutdown(object? sender, EventArgs e)
      {

      }


      public void SelectAllElements()
      {
         // Get the UIDocument
         Autodesk.Revit.UI.UIDocument uidoc = this.ActiveUIDocument;

         // Get the Document from the UIDocument
         Autodesk.Revit.DB.Document doc = uidoc.Document;

         // Create a FilteredElementCollector that will collect all elements in the Document
         FilteredElementCollector collector = new FilteredElementCollector(doc);

         // Apply no filter, which means all elements are collected
         collector.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(false), new ElementIsElementTypeFilter(true)));

         // Convert the collected elements to a list of element ids
         IList<ElementId> ids = collector.ToElementIds().ToList();

         // Check if there are elements to select
         if (ids.Count > 0)
         {
            // Start a new transaction (Revit API requires this for most changes to the model)
            using (Transaction trans = new Transaction(doc, "Select All Elements"))
            {
               trans.Start();

               // Make the selection
               uidoc.Selection.SetElementIds(ids);

               trans.Commit();
            }
         }
      }
   }
}

새로 작성된 3D 직교 뷰에서 샘플 Revit 모델 Snowdon Towers 샘플 Architectural.rvt를 사용하여 샘플 매크로를 실행하고 창에 맞게 줌: