VB.NET Application-Level Macro Code Example

In the IDE, use the following code for the method:

Public
Sub MyFirstMacroAppVB()    
Dim
baseVec As Autodesk.Revit.DB.XYZ = Application.Create.NewXYZ(1.0,
0.0, 0.0)Dim
upVec As Autodesk.Revit.DB.XYZ = Application.Create.NewXYZ(0.0,
0.0, 1.0)Dim
origin As Autodesk.Revit.DB.XYZ = Application.Create.NewXYZ(0.0,
0.0, 0.0)Dim
align As Autodesk.Revit.DB.TextAlignFlags = Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_LEFT
Or Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_TOPDim
strText As String = "My First Macro, App Level, VB.NET!"Dim
lineWidth As Double = 4.0 / 12.0Dim
pView As Autodesk.Revit.DB.View = ActiveUIDocument.Document.ActiveViewDim
Transaction As Autodesk.Revit.DB.Transaction = New Autodesk.Revit.DB.Transaction(ActiveUIDocument.Document, "NewTextNote")Transaction.Start()ActiveUIDocument.Document.Create.NewTextNote(pView,
origin, baseVec, upVec, lineWidth, align, strText)Transaction.Commit()
End Sub

Please note that because this application-level macro is written to modify a document, you must begin a transaction (Transaction.Start()) and end the transaction (Transaction.Commit()) for it to run properly.

Tip: Be sure to build your project in the Revit macro IDE before trying to run it from the Macro Manager.

For this example, when you build the project in the Revit macro IDE, notice that you are building the AppVisualBasic project. Your Application-level VB.NET macro's code resides in ThisApplication.vb. You can use the IDE's Project Explorer to see its location on disk. To run your newly built macro, select it in Macro Manager and click Run. Then if necessary, right-click in the active view, and select Zoom to Fit from the menu to see the text note added by your macro.

The macro placed text box