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.
Accessing the Application Object in Document-Level Macros
Before we continue with additional
MyFirstMacro*
examples, let's talk about the Revit
Application
object,
and the use of keyword pointers.
Developers know that in C#, you use the keyword
this
to return the current instance of an object. In VB.NET,
you use the keyword
Me
to return the current instance of an object.
In Revit, all of the Application-level macros are associated with the
Application
object. Thus using the
this
keyword (C#) or the
Me
keyword (VB.NET) always returns the API
Application
object. This includes all the
application-wide data and settings.
In Document-level macros (specific to a .rvt), the
this
keyword (in C#) or the
Me
keyword (VB.NET) returns
the API
Document
object. If you need to access the
Application
object from a Document-level macro, use:
this.Application
or:
Me.Application
Example: Document-Level Macro in C#
For the next example, in Macro Manager, select DocCSharp and click New.
Give your macro a name, such as
MyFirstMacroDocCS
.
In the IDE, use the following code for the method:
public void MyFirstMacroDocCS()
{
Autodesk.Revit.Geometry.XYZ baseVec = this.Application.Create.NewXYZ(1.0, 0.0, 0.0);
Autodesk.Revit.Geometry.XYZ upVec = this.Application.Create.NewXYZ(0.0, 0.0, 1.0);
Autodesk.Revit.Geometry.XYZ origin = this.Application.Create.NewXYZ(0.0, 0.0, 0.0);
Autodesk.Revit.Enums.TextAlignFlags align =
Autodesk.Revit.Enums.TextAlignFlags.TEF_ALIGN_LEFT |
Autodesk.Revit.Enums.TextAlignFlags.TEF_ALIGN_TOP;
string strText = "My First Macro, Document level, CS!";
double lineWidth = 4.0 / 12.0;
View pView = this.ActiveView;
this.Create.NewTextNote(pView, origin, baseVec, upVec, lineWidth, align, strText);
}
Notice the use of
this.Application
in this Document-level macro. For related information, see the previous
section about accessing the
Application
object from Document-level macros.
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, also notice that you are building the
DocCSharp
project. Your Document-level C# macro's code resides in ThisDocument.cs. 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.
Creating Your First Set of Macros | 1351
Содержание 24000-000000-9860 - Revit Architecture - PC
Страница 1: ...Revit Architecture 2009 User s Guide April 2008 240A1 050000 PM02A ...
Страница 4: ......
Страница 56: ...18 ...
Страница 116: ...78 Chapter 3 Revit Essentials ...
Страница 172: ...134 Chapter 4 ProjectViews ...
Страница 178: ...Schedule with Grid Lines Schedule with Grid Lines and an Outline 140 Chapter 4 ProjectViews ...
Страница 352: ...Defining the first scale vector Defining the second scale vector 314 Chapter 7 Editing Elements ...
Страница 554: ...516 ...
Страница 739: ...Curtain wall Curtain Grid Curtain Walls Curtain Grids and Mullions 701 ...
Страница 898: ...Pile caps with multiple piles Rectangular and triangular pile caps 860 Chapter 12 Working with Structural Components ...
Страница 1004: ...966 ...
Страница 1136: ...1098 ...
Страница 1226: ...1188 ...
Страница 1250: ...1212 ...
Страница 1276: ...1238 Chapter 20 Design Options ...
Страница 1310: ...1272 ...
Страница 1366: ...1328 ...
Страница 1406: ...1368 ...