Table of contents
No headersThe recommended method to expose a AutoCAD Civil 3D extension to users is to add it to the tab in , by creating a toolbox macro. The handles loading the .NET assembly or ARX DLL containing the commands.
There are two execution types that a toolbox macro can have:
- CMD - the command name is sent to the command line to execute. This is the recommended execution type for both .NET and ARX commands.
- .NET - a method name is located, via Reflection, in the assembly, and is executed directly. No attribute flags are read and the code is always run in application context. (A command executed from the command line runs in the drawing context by default). Therefore, code run as as a .NET execute type must always be a static method, and must handle its own document locking.
NoteIt is safe to explicitly lock a document, even if the code might be run in document context.
Here is an example of how to handle document locking:
static void setPrecision()
{
using (Autodesk.AutoCAD.ApplicationServices.DocumentLock locker = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
// perform any document / database modifications here
CivilApplication.ActiveDocument.Settings.DrawingSettings.AmbientSettings.Station.Precision.Value = 2;
}
}
To create a toolbox macro for a compiled command using the Toolbox Editor
- Click the tab in Toolspace.
- Click
to open the . - Right-click and click .
- Right-click the new category, and click .
- Select the new tool, and enter its name.
- For , click the drop-down and select or .
Note is the recommended execution type in most cases, because you do not need to explicitly handle document locking. See the discussion above.
- For , browse to the .NET assembly or ARX DLL that contains the command.
- For , enter:
- Name of the command to run, if the execute type is
- Name of the method to run, if the execute type is .
- Optionally, enter a help file and help topic for the command.
- Click
to apply the changes and close the editor.
After a command has been set up, it can be run by right-clicking it and clicking .