Example: Document-Level Macro in VB.NET
For the next example, in Macro Manager, select DocVisualBasic and click New.
Give your macro a name, such as
MyFirstMacroDocVB
.
In the IDE, use the following code for the method:
Public Sub MyFirstMacroDocVB()
Dim baseVec As Autodesk.Revit.Geometry.XYZ = Me.Application.Create.NewXYZ(1.0, 0.0, 0.0)
Dim upVec As Autodesk.Revit.Geometry.XYZ = Me.Application.Create.NewXYZ(0.0, 0.0, 1.0)
Dim origin As Autodesk.Revit.Geometry.XYZ = Me.Application.Create.NewXYZ(0.0, 0.0, 0.0)
Dim align As Autodesk.Revit.Enums.TextAlignFlags =
Autodesk.Revit.Enums.TextAlignFlags.TEF_ALIGN_LEFT Or
Autodesk.Revit.Enums.TextAlignFlags.TEF_ALIGN_TOP
Dim strText As String = "My First Macro, Doc Level, VB.NET!"
Dim lineWidth As Double = 4.0 / 12.0
Dim pView As Autodesk.Revit.Elements.View = Me.ActiveView
Me.Create.NewTextNote(pView, origin, baseVec, upVec, lineWidth, align, strText)
End Sub
TIP
Be sure to build your project in the Revit VSTA IDE before trying to run it from Macro Manager.
For this example, when you build the project in the Revit VSTA IDE, notice that you are building the
DocVisualBasic project, and your Document-level VB.NET macro's code resides in ThisDocument.vb. You
can use the IDE's Project Explorer to see its temporary location on disk. Recall that the code for successfully
built Document-level macros are stored in the .rvt file after you Save the .rvt file; the project files are removed
from the temporary location when you exit Revit.
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.
Using the StepInto Option
You can debug your macros by using StepInto option in Macro Manager and features in the Revit VSTA IDE:
■
Open the code for your macro in the IDE.
■
To set breakpoints, click in the left margin of the code window, or click in the code and press F9 or Toggle
Breakpoint in the Debug menu.
■
Then switch to Macro Manager. Select your macro from the categorized list, and click StepInto. The
macro will stop at the first line.
■
Press F5 or Continue to move to the breakpoint.
1352 | Chapter 24 Creating Macros with Revit VSTA
Summary of Contents for 24000-000000-9860 - Revit Architecture - PC
Page 1: ...Revit Architecture 2009 User s Guide April 2008 240A1 050000 PM02A ...
Page 4: ......
Page 56: ...18 ...
Page 116: ...78 Chapter 3 Revit Essentials ...
Page 172: ...134 Chapter 4 ProjectViews ...
Page 178: ...Schedule with Grid Lines Schedule with Grid Lines and an Outline 140 Chapter 4 ProjectViews ...
Page 554: ...516 ...
Page 739: ...Curtain wall Curtain Grid Curtain Walls Curtain Grids and Mullions 701 ...
Page 1004: ...966 ...
Page 1136: ...1098 ...
Page 1226: ...1188 ...
Page 1250: ...1212 ...
Page 1276: ...1238 Chapter 20 Design Options ...
Page 1310: ...1272 ...
Page 1366: ...1328 ...
Page 1406: ...1368 ...