The SolidWorks Application Programming Interface (API) is the basis for the SolidWorks three macro
recorders: C#, VB.NET, and VBA. Each of the three SolidWorks API tutorials shows you how to:
record a macro to create a cut-extrude on a specific pre-selected face on a part,
modify the macro to create the cut-extrude on any pre-selected face on the part, and
create a form where users can specify the extrude's radius and depth values and create the
cut-extrude on any pre-selected face on the part
using the SolidWorks C#, VB.NET, or VBA macro recorder. Click a link to open the SolidWorks API tutorial
using that macro recorder.
This tutorial introduces you to the SolidWorks
ĮApplication Programming Interface (API), the SolidWorks
Visual Studio
ĮTools for Applications, and its Integrated Development Environment (IDE).
The SolidWorks API:
is the basis for the
SolidWorks macro recorders
.
lets you automate and customize the SolidWorks software and integrate your software with the
SolidWorks software.
The quickest and easiest way to start programming with the SolidWorks API is to record a macro. Then you
can modify the macro to fit your work site's needs. This tutorial provides instructions on recording, editing,
and running a macro written in
C#
in the SolidWorks software.
This tutorial assumes that you are familiar with using the SolidWorks software interactively. If you plan on
automating, customizing, or integrating your software with the SolidWorks software using the SolidWorks
API, you should take a Visual Basic or Visual C# programming course and then attend a SolidWorks API
training course offered at a SolidWorks Authorized Training and Support Center.
Create a SolidWorks API C# program by recording the operations performed to create a cut-extrude on a
face. The SolidWorks macro recorder records every operation you perform while recording.
1.
Click here
to open the candlestick part (or browse to
install_dir\samples\tutorial\api\cstick.sldprt.)
2. Click Options
(Standard toolbar) and make sure Stop VSTA debugger on macro exit is
selected and Automatically edit macro after recording is not selected.
3. Click OK.
4. Click Record\Pause Macro
(Macro toolbar) to begin recording the macro.
5. Select the face shown.
SolidWorks API Tutorials
SolidWorks API C# Overview
Recording a Macro
C# VB.NET VBANEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
6. Click Sketch
(Sketch toolbar) to insert a sketch.
7. Click Normal To
(Standard Views toolbar).
1. Click Circle
(Sketch toolbar).
2. Sketch a circle centered at the sketch origin.
3. In the PropertyManager, set Radius
to 15.
4. Click
1. Click Extruded Cut
(Features toolbar).
2. In the PropertyManager, under Direction 1:
Set End Condition to Blind.
Set Depth
to 25.
Click Draft On/Off
, and set Draft Angle to 15.
3. Click
.
A cut-extrude with a radius of 15mm, depth of 25mm, and draft of 15° centered on the top face of the
candlestick holder is created.
4. Click Stop Macro
(Macro toolbar) to stop recording the macro.
5. In the Save As dialog box, browse to the folder where you want to save the macro.
6. Make sure Save as type is SW VSTA C# Macro (*.csproj).
7. Type CreateCutExtrudeCSharp in File name.
8. Click Save.
1. Click Edit Macro
(Macro toolbar).
2. Open CreateCutExtrudeCSharp.csproj.
3. Click Open.
The SolidWorks VSTA IDE opens. The Code Editor window contains the SolidWorks API C# code
generated for the macro.
Sketching a Circle
Saving a Macro
Examining a Macro
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
4.
Click here
to display the macro code in a browser.
Your macro may contain more lines of code than the displayed code if you performed any operations
not specified in the previous exercise; for example, rotating the part.
5. Delete any lines of code in your macro that do not appear in the displayed code.
If swDoc.SketchManager.InsertSketch(true) does not appear in your code, then you created the
circle without first inserting a sketch.
6. Type swDoc.SketchManager.InsertSketch(true) where it appears in the displayed code, if
necessary.
Some arguments' numeric values in your macro may be different than those in the displayed code.
These values reflect coordinates of the model. Do not modify the values in your macro to match the
values in the displayed code.
7. Close the browser displaying the code. Leave the Code Editor window open.
Certain variables are declared automatically in a SolidWorks macro. You can delete any variables not used in
the program.
1. Delete these variables declarations.
2. Test the modified macro by recreating the cut-extrude in the candlestick holder.
a. In the SolidWorks software, drag the rollback bar up the FeatureManager design tree until it is
above the Cut-Extrude1 feature.
b. In the SolidWorks VSTA IDE, click Start Debugging
.
A new cut-extrude is created in the candlestick holder.
3. Delete the cut-extrude and the sketch just created.
4. Drag the rollback bar back to the bottom of the FeatureManager design tree.
5. Delete the original cut-extrude and sketch.
To learn how to debug code in C#, change the code in the Code Editor window to cause errors to occur while
executing it.
1. Delete the letters el from the variable ModelDoc2 and change the name of the property ActiveDoc to
ActiveDoc2
.
Modifying a Macro
PartDoc swPart = null;
DrawingDoc swDrawing = null;
AssemblyDoc swAssembly = null;
int longstatus = 0;
int longwarnings = 0;
Starting to Debug a Program
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
You cannot edit a running macro in SolidWorks x64. Instead, you must stop the running
macro, edit the macro, and run the macro again.
2. In the SolidWorks graphics area, select the top face.
1. Click Start Debugging
in the SolidWorks VSTA IDE.
A message box is displayed informing you that there were build errors.
2. To debug the errors, click No.
3. Double-click the first error to move the cursor to the line of code that contains the error.
4. Insert the letters el so ModDoc2 becomes ModelDoc2, which is a declared variable in the code.
5. Click Start Debugging
.
6. Click No and change ActiveDoc2 to ActiveDoc.
7. Click Start Debugging
.
The code compiles, and a cut-extrude is created on the selected face.
8. Delete the cut-extrude and sketch.
Modify the macro in the Code Editor window so that you can create a cut-extrude on any pre-selected face in
any part. To make the program more generic, eliminate the draft.
1.
Click here
for instructions on how to modify your macro.
2. Click Save SolidWorksMacro.cs
in the SolidWorks VSTA IDE to save the modified code.
3. In the SolidWorks graphics area, select the face on the bottom of the part.
4. Click Start Debugging
in the SolidWorks VSTA IDE.
A cut-extrude with a radius of 15mm and a depth of 25mm is created on the selected face and is
centered on the sketch point.
5. Delete the cut-extrude and sketch.
Currently you must modify the code to change the radius and depth values programmatically. To increase
the flexibility of the program, you can create a C# form where users can specify these values.
1. In the SolidWorks VSTA IDE, click View > Project Explorer .
2. In the Project Explorer, select SolidWorksMacro.cs.
3. Click Project > Add Windows Form.
4. Select Windows Form, leave Form1.cs in Name, and click Add.
5. To change the name of the form, click the form in the Design View window.
6. Type View > Properties Window to display the properties associated with Form1.
7. Type frmCutExtrude in the (Name) row in the Properties window.
Finishing Debugging a Program
Creating a Generic Cut-Extrude Program
Creating a Form
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
Use the scroll bar in the Properties window to locate the (Name) row, which is near the
beginning of the Properties window.
8. Click the form for the change to take effect.
The name at the top of the Properties window changes to frmCutExtrude. However, the name shown
on the form is the Text property of the form, which you did not change, so it remains Form1.
Add two text boxes and a command button, called controls, to the form using the Toolbox.
1. Display the toolbox by clicking View > Toolbox.
2. Expand Common Controls.
3. Drag
and place it near the upper-right corner of the form.
4. Drag another text box and place it below the text box that you just created.
5. Drag
, place it below the text boxes, and stretch it so that it is the same length as the text
boxes.
Change the names of the text boxes and the command button to more meaningful names.
1. Click the top text box on the form.
2. Type txtRadius in the (Name) row in the Properties window.
3. Click outside the row for the change to take effect.
4. Click the other text box and name it txtDepth.
5. Click the command button and name it bOK.
Add labels for both text boxes so that users know what information to type in the text boxes. Also, change
the caption on the command button.
Adding Controls
Changing Names of Controls
Finishing the Form
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
1. Drag
and place it beside the top text box.
2. Type Radius: in the Text row in the Properties window.
3. Click anywhere on the form.
4. Place a label named Depth: beside the other text box.
5. Click button1 on the form and change its caption to OK.
6. Click anywhere on the form.
C# can insert code templates for event procedures for controls. You modify the code template to specify
what you want to happen when an event occurs, such as when users click the OK button.
1. Double-click the OK button on the form to open the Code Editor window containing an event procedure
for this control.
The name of the event procedure, bOK_Click, is a combination of the control's name as specified in the
control's Name property, an underscore (_), and the name of the event. The Click procedure is the
default procedure for a command button.
2. Type, or copy and paste, these declarations above Private void bOK_Click(object sender,
EventArgs e)
.
3. Type, or copy and paste, this code between Private void bOK_Click(object sender, EventArgs e)
event's curly brackets.
Writing Code for the Form
public double radius;
public double depth;
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
Modify SolidWorksMacro.cs to display the form to users and to retrieve the depth and radius values from
the form.
1. Double-click SolidWorksMacro.cs in the Project Explorer to display its code in the Code Editor
window.
2. Scroll to the top of the macro and locate swDoc = ((ModelDoc2)(swApp.ActiveDoc));.
3. Insert the following code between swDoc = ((ModelDoc2)(swApp.ActiveDoc)); and //COMMENT OUT
THIS LINE OF CODE
to display the form and retrieve the depth and radius values typed by the user.
Replace the radius and depth values, which were automatically inserted by the SolidWorks macro recorder
when you created the cut-extrude in the SolidWorks user interface, with variables.
1. Scroll to near the bottom of the macro and locate dz = darray[2];.
2. Replace all of the code appear after dz = darray[2]; with this code.
double radiusResult;
double depthResult;
//Convert strings to doubles and
//make sure that the text in the two
//text boxes on the form are positive,
//non-zero, numeric values
double.TryParse(txtRadius.Text, out radiusResult);
double.TryParse(txtDepth.Text, out depthResult);
if (radiusResult > 0 && depthResult > 0)
{
radius = radiusResult;
depth = depthResult;
//Close the form and continue
Close();
}
else
{
//Display a message box telling the user to type
//positive, non-zero, numeric values in both text boxes
MessageBox.Show("You must type positive, non-zero, numeric values in both Radius and Depth.");
}
Adding Variables for Controls
//ADD THESE LINES OF CODE
double holeRadius;
double holeDepth;
//Create an instance of the user form
frmCutExtrude myForm = new frmCutExtrude();
//Set the title for the form
myForm.Text = "Size of Cut-Extrude in Millimeters";
//Display a model user form and retrieve radius
//depth values typed by the user; divide those values
//by 1000 to change mmillimeters to meters
myForm.ShowDialog();
holeRadius = myForm.radius / 1000;
holeDepth = myForm.depth / 1000;
//Dispose of the user form and remove it from
//memory because it's no longer needed
myForm.Dispose();
Saving the Code for the Form
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
3. Click Save SolidWorksMacro.cs
to save the modified code.
Now test the modified program and the form.
1. In the SolidWorks software, select the bottom face of the candlestick holder.
2. Click Start Debugging
in the SolidWorks VSTA IDE.
The Size of Cut-Extrude in Millimeters dialog is displayed.
3. Type 15 in Radius and 10 in Depth.
4. Click OK to create a cut-extrude of the specified depth and radius on the bottom face.
5. Click File > Exit in the SolidWorks VSTA IDE to exit it and return to SolidWorks.
6. Select the bottom face of the candlestick holder again.
7. Click Run Macro
(Macro toolbar).
8. Browse to the folder where you saved the project and then browse to \SwMacro\bin\Debug.
9. Select CreateCutExtrudeCSharp.dll and click Open.
10. Type 10 in Radius and 5 in Depth.
11. Click OK to create another cut-extrude of the specified depth and radius on the bottom face.
12. Close the candlestick part document without saving it.
Congratulations! You have completed this tutorial.
Return to the tutorials overview page.
This tutorial introduces you to the SolidWorks
ĮApplication Programming Interface (API), the SolidWorks
Visual Studio
ĮTools for Applications, and its Integrated Development Environment (IDE).
The SolidWorks API:
Is the basis for the
SolidWorks macro recorders
.
Lets you automate and customize the SolidWorks software and integrate your software with the
SolidWorks software.
The quickest and easiest way to start programming with the SolidWorks API is to record a macro. Then you
can modify the macro to fit your work site's needs. This tutorial provides instructions on recording, editing,
and running a macro written in
Visual Basic (VB.NET)
in the SolidWorks software.
//Create the sketch for cut-extrude
SketchSegment swSketchSegment = null;
swSketchSegment = (SketchSegment)swDoc.SketchManager.CreateCircleByRadius(dx, dy, dz, holeRadius);
//Create the cut-extrude feature
Feature swFeature = null;
swFeature = (Feature)swDoc.FeatureManager.FeatureCut3(true, false, false, 0, 0, holeDepth, 0.01, true, false, false, false, 0, 0, false, false, false, false, false, true, true, false, false, false, (int)swStartConditions_e.swStartSketchPlane, 0, false);
}
}
//KEEP THESE LINES OF CODE
///<summary>
///The Sldworks swApp variable is pre-assigned for you.
///</summary>
public SldWorks swApp;
}
Testing the Program and Form
SolidWorks API VB.NET Overview
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
This tutorial assumes that you are familiar with using the SolidWorks software interactively. If you plan on
automating, customizing, or integrating your software with the SolidWorks software using the SolidWorks
API, you should take a Visual Basic or Visual C# programming course and then attend a SolidWorks API
training course offered at a SolidWorks Authorized Training and Support Center.
Create a SolidWorks API VB.NET program by recording the operations performed to create a cut-extrude on
a face. The SolidWorks macro recorder records every operation you perform while recording.
1.
Click here
to open the candlestick part (or browse to
install_dir\samples\tutorial\api\cstick.sldprt.)
2. Click Options
(Standard toolbar) and make sure Stop VSTA debugger on macro exit is
selected and Automatically edit macro after recording is not selected.
3. Click OK.
4. Click Record\Pause Macro
(Macro toolbar) to begin recording the macro.
5. Select the face shown.
6. Click Sketch
(Sketch toolbar) to insert a sketch.
7. Click Normal To
(Standard Views toolbar).
1. Click Circle
(Sketch toolbar).
2. Sketch a circle centered at the sketch origin.
3. In the PropertyManager, set Radius
to 15.
4. Click
1. Click Extruded Cut
(Features toolbar).
2. In the PropertyManager, under Direction 1:
Set End Condition to Blind.
Set Depth
to 25.
Click Draft On/Off
, and set Draft Angle to 15.
3. Click
.
Recording a Macro
Sketching a Circle
Saving a Macro
NEXT TOPIC
Recording a MacroPREVIOUS TOPIC
SolidWorks API C# OverviewNEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VB.NET Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form
NEXT TOPIC
Recording a Macro
PREVIOUS TOPIC
SolidWorks API VBA Overview
NEXT TOPIC
Sketching a CirclePREVIOUS TOPIC
Recording a MacroNEXT TOPIC
Saving a MacroPREVIOUS TOPIC
Sketching a CircleNEXT TOPIC
Examining a MacroPREVIOUS TOPIC
Saving a MacroNEXT TOPIC
Modifying a MacroPREVIOUS TOPIC
Examining a MacroNEXT TOPIC
Starting to Debug a ProgramPREVIOUS TOPIC
Modifying a MacroNEXT TOPIC
Running a MacroPREVIOUS TOPIC
Starting to Debug a ProgramNEXT TOPIC
Finishing Debugging a ProgramPREVIOUS TOPIC
Running a MacroNEXT TOPIC
Creating a Generic Cut-Extrude Program
PREVIOUS TOPIC
Finishing Debugging a ProgramNEXT TOPIC
Creating a FormPREVIOUS TOPIC
Creating a Generic Cut-Extrude Program
NEXT TOPIC
Adding ControlsPREVIOUS TOPIC
Creating a FormNEXT TOPIC
Changing Names of ControlsPREVIOUS TOPIC
Adding ControlsNEXT TOPIC
Finishing the Form
PREVIOUS TOPIC
Changing Names of Controls
NEXT TOPIC
Writing Code for the Form
PREVIOUS TOPIC
Finishing the Form
NEXT TOPIC
Adding Variables for Controls
PREVIOUS TOPIC
Writing Code for the Form
NEXT TOPIC
Saving the Code for the Form
PREVIOUS TOPIC
Adding Variables for Controls
NEXT TOPIC
Testing the Program and Form
PREVIOUS TOPIC
Saving the Code for the Form