Macros
The quickest and easiest way to start programming with the
DraftSight API is to record a macro, which contains the DraftSight API calls
that correspond to the actions performed interactively in DraftSight. This Help
topic identifies the supported macro-recording programming languages and
DraftSight interfaces and describes how to interactively and
programmatically record macros.
NOTES:
-
Macro recording is available in DraftSight Premium only.
-
You must use Microsoft Visual Studio 2008 to edit, debug,
and build C++ Native, C#, VB, and C++ COM macro projects.
Supported languages
You can save macros as Microsoft Visual Studio 2008 projects, VBA
script files, and JavaScript HTML files. Thus, you should be familiar with at least one of
the following programming or scripting languages before using the macro recording
feature of DraftSight:
-
C++ Native (*.vcproj): Creates a Microsoft Visual
Studio 2008 project and an add-in (.dll)
in which you implement a command that executes the generated macro code. If
you edit and rebuild the add-in after loading it, then you must close and restart DraftSight
to reload the add-in.
-
C# (*.csproj): Creates a Microsoft Visual Studio 2008
project and an external application (.exe)
that executes the generated macro code that you can edit, rebuild, and rerun
the project without closing DraftSight.
-
JavaScript (*.html): Creates an HTML file from which
you execute the generated JavaScript macro code. Open the HTML file in a web browser
and click the button to execute the macro.
-
VB (*.vbproj): Creates a Microsoft Visual Studio 2008
project and an external application (.exe) that you can edit, rebuild, and rerun
the project without closing DraftSight. This type of
Microsoft Visual Studio project is also commonly referred to as a VB.NET
project.
-
C++ COM (*.vcproj): Creates a Microsoft Visual Studio
2008 project and add-in (.dll) in which you implement a command that
executes the generated macro code. If you edit and rebuild the add-in after
loading it, then you must close and restart DraftSight to reload the add-in.
-
VBA (*.swb): Creates a script file that you can:
-
Open, edit, debug, and run in the SOLIDWORKS VBA Integrated Development
Environment (IDE).
-
Import into any Microsoft Office product that supports
macros.
Back to top
Supported interfaces
This release supports recording macros for these interfaces:
Back to top
Interactively record macros
Typically to interactively record a DraftSight macro:
- Plan the interactive
DraftSight actions before recording
the macro.
- Set the location where to save the macro's
Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb
file.
- Set the level of detail to appear in the
macro's Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb
file.
- Record the
interactive DraftSight actions.
NOTE: If you are unfamiliar with recording DraftSight macros,
perform the interactive DraftSight actions a couple of times before starting
to record the macro to eliminate possible extraneous actions such as zooming in or out
of the drawing, panning, etc.
- Stop and save the macro in the language you
selected.
A Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb
file is created upon saving the macro at the
location specified in step 2.
- Open the macro's Microsoft
Visual Studio 2008 project, JavaScript HTML file in Notepad or any HTML editor, or
VBA .swb file in the SOLIDWORKS VBA IDE or Microsoft Office VBA Editor.
- Edit,
build, run, debug, rebuild, and rerun, as needed, the macro. Repeat this step until the macro is executing as
intended.
- Save the macro's Microsoft Visual Studio 2008 project, JavaScript HTML file, or
VBA .swb file.
Back to top
Interactively set macro location and level of
detail
To set the location where to save DraftSight API macros and the
level of detail to record:
-
Click Tools > Options to open the Options - System
Options dialog.
-
Click the System Options button.
-
Expand Macro Recording.
-
Expand Location.
-
Type the path of the location where to save macros.
- or -
Click Browse, navigate to the folder where to save macros, and click Select Folder.
The location where to save macros is stored in the sysvar APIPATH.
-
Expand Level of detail.
-
Select the level of detail to appear in the macro:
-
Low: Minimal code required to emulate interactive
actions and execute.
-
High: Verbose code, including intermediate steps,
required to emulate interactive actions and execute.
NOTE: Data recorded in macros for methods that expect users to
input data at the prompt in the command window, e.g.,
ISketchManager::InsertCircle, are ignored when executing the macro.
Instruct your users to examine the command window to determine if they
must input data at the prompt in the command window when recording
macros with the high-level of detail option selected. You might also
want to delete the lines of code in the macro that prompt for data.
The level of detail is stored in the sysvar APILEVEL.
-
Click OK to close the Options - System Options
dialog.
Back to top
Interactively record and save a macro
To record and save a macro:
-
Click Tools > Macro > Record or type _RECORDMACRO
in the command window.
-
Perform the interactive actions that you want to record.
-
When you are done recording, click Tools > Macro > Stop
or type _STOPMACRO in the command window to stop and save the
macro.
-
Type a name for the macro in File Name and select the
language to which to save the generated macro code in Save as type.
-
Click Save to save the macro in the location specified in
step 5 in the previous procedure.
Interactively edit, build, run, debug, rebuild,
rerun, and save a macro
To edit, build, run, debug, rebuild, rerun, and save a
macro:
-
Open the macro project in Microsoft Visual Studio
2008,
JavaScript HTML file in Notepad or any HTML editor, or the VBA .swb
file in the
SOLIDWORKS VBA IDE or any Microsoft Office VBA Editor, in the location specified in step
5 in the Set macro location and level of detail procedure.
-
Edit the macro
code to delete any extraneous lines of code, add lines of code for actions
not performed interactively while recording the macro, reformat the code, etc.
-
Build, if
needed, and run
the project or file to test it.
-
Debug, rebuild,
if needed, and rerun
the project or file again. Repeat this step until the
macro is executing as intended.
- Save the project.
Back to top
Programmatically record macros
Programmatically start and stop macros
The DraftSight API includes two methods to programmatically start and stop macro
recording:
These methods are useful if you want your add-in application to
record and play back DraftSight macros. For example, if your add-in application
allows end users to change dimension styles, then end users might want to record and play back the operations in a macro. This would allow end
users to easily change dimension styles in a large number of files by playing
back the macro.
Programmatically set macro location and level of
detail
The DraftSight API includes properties for programmatically getting and setting:
Back to top