Sample Add-in for Macro Command
A sample add-in to add a macro command to RootPro CAD is shown below.
A macro command is used by adding a new menu to [Add-ins] menu of RootPro CAD, and clicking it to execute.
- Start up Visual Studio to create a new add-in project.
For detailed procedures, see Creating Add-in. - Open AppAddIn.cs file (or AppAddIn.vb for VB), and add the following codes in AppAddIn_Startup and AppAddIn_Shutdown functions.
- The first parameter of AddMacroCommand ("RootProCADAddInCircleCS") is an identifier used to allocate a short-cut key to a macro command, or add a macro command to a toolbar button. Specify a unique string not duplicated with other macro commands.
- The second parameter for AddMacroCommand ("Create Circle") is a menu name displayed on [Add-ins] menu.
- The third parameter for AddMacroCommand (MacroCommand) is a function name to be executed when the macro command menu is clicked.
[For Visual Basic]private void AppAddIn_Startup(object sender, EventArgs e) { // Add the following line. // Add Macro Command. CommandManager.AddMacroCommand("RootProCADAddInCircleCS", "Create Circle", MacroCommand); } private void AppAddIn_Shutdown(object sender, EventArgs e) { // Add the following line. // Delete Macro Command. CommandManager.RemoveMacroCommand(MacroCommand); }
Private Sub AppAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup ' Add the following line. ' Add Macro Command. CommandManager.AddMacroCommand("RootProCADAddInCircleCS", "Create Circle", MacroCommand) End Sub Private Sub AppAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown ' Add the following line. ' Delete Macro Command. CommandManager.RemoveMacroCommand(MacroCommand) End Sub
- Describe the following code at the bottom of AppAddIn.cs file (or AppAddIn.vb for VB).
Add MacroCommand function to execute the macro command.
A circle with the center point at (100, 100) and radius at 100 is added on the current part drawing on the active drawing.
The processes surrounded by BeginUndoUnit and EndUndoUnit can be undone for one time.
[For C#]
[For Visual Basic]// Circle creation macro command private void MacroCommand() { // Retrieve active drawing. Document doc = ActiveDocument; // Retrieve current part drawing. Drawing drawing = doc.CurrentDrawing; // Start operation that can be undone. doc.UndoManager.BeginUndoUnit(); // Add circle to part drawing. Point2d pointCenter = Geometry.CreatePoint(100, 100); // Center point of circle double radius = 100.0; // Radius drawing.Shapes.AddCircle(pointCenter, radius); // Exit operation that can be undone. doc.UndoManager.EndUndoUnit(); }
' Macro Command to Create Circle Private Sub MacroCommand() ' Retrieve active drawing. Dim doc As Document = ActiveDocument ' Retrieve current part drawing. Dim drawing As Drawing = doc.CurrentDrawing ' Start operation that can be undone. doc.UndoManager.BeginUndoUnit() ' Add circle to part drawing. Dim pointCenter As Point2d = Geometry.CreatePoint(100, 100) ' Center point Dim radius As Double = 100.0 ' Radius drawing.Shapes.AddCircle(pointCenter, radius) ' Exit operation that can be undone. doc.UndoManager.EndUndoUnit() End Sub
- Execute the build to check the add-in operates correctly.
For detailed procedures, see Creating Add-in.
Supplemental | |
▪ | Add-ins are only used in RootPro CAD Professional. RootPro CAD Free cannot use these functions. |