Click or drag to resize
Debugging Script Add-In With Visual Studio (C#)

You can develop and debug your CUSTOMTOOLS script add-ins by using the Microsoft Visual Studio IDE.

This topic shows you the specific options you need to setup in order to develop and debug your Visual C# script add-in properly by using the Visual Studio.

Options to Be Made in the CUSTOMTOOLS Administration Tool

In order to allow the CUSTOMTOOLS script add-in to be developed with the Microsoft Visual Studio, the script debugging needs to be enabled from the script add-in settings in the CUSTOMTOOLS Administration Tool. Script add-ins in CUSTOMTOOLS have an option called Debug add-in which is used to allow development and debugging of the script add-in outside the CUSTOMTOOLS Administration Tool.

The following instructions helps you to enable debugging of a CUSTOMTOOLS script add-in:

  1. Run the CUSTOMTOOLS Administration Tool.

  2. Login to your CUSTOMTOOLS database the script add-in is located in.

  3. Select the Manage Scripts node from the Database View.

  4. From the Selected script box, select the script add-in you would like the develop with the Visual Studio.

  5. Select the Load at start-up option to make the script add-in loaded on the SOLIDWORKS startup in association with the CUSTOMTOOLS itself.

  6. Select the Debug add-in option. This option allows you to debug the script add-in in an external program like the Microsoft Visual Studio mentioned in this example.

  7. Click the Check In button to save the changes.

C# Project Options to be Made in Visual Studio

To debug a CUSTOMTOOLS script add-in using the Visual Studio, the class library project the script add-in have been created as, needs to be compiled into the CUSTOMTOOLS database specific folder in workstation's local hard drive. All CUSTOMTOOLS databases have their own local folder in hard drive which path is similar than the following example.

C:\Users\<WindowsUserName>\AppData\Local\CustomTools\<CTMajorVersion>\ExampleDatabase

Tip Tip

For example: With a Windows user called Developer, a CUSTOMTOOLS 2018 database called CUSTOMTOOLS Scripting, have the script add-ins located in the following local path:

C:\Users\Developer\AppData\Local\CustomTools\2018\CUSTOMTOOLS Scripting\Add-ins\

CUSTOMTOOLS script add-ins are located in a sub folder called Add-ins. Each script add-in you have, has own sub folder in the Add-ins folder. The script add-in should be compiled into that folder with the Visual Studio as well to make possible the debugging and developing the script add-in.

Changing the project compile path in Visual Studio

Change the output path of your C# project in Visual Studio with the following instructions while you have your C# project open in Visual Studio:

  1. In the Solution Explorer, right-click on the C# project name node and select Properties.

  2. Select the Build tab in the project properties view.

  3. Under the Output group, define path of your CUSTOMTOOLS database's script add-in folder into the Output path box.

  4. Save changes to your project.

Attach the Visual Studio Debugger to the SOLIDWORKS Process

When you are about to debug you CUSTOMTOOLS script add-in that is attached to an event that occur in SOLIDWORKS, you need to attach the Visual Studio debugger to your running SOLIDWORKS process instance in order to debug the script's operations. Use the following instructions to attach the Visual Studio debugger to your SOLIDWORKS process.

  1. Start SOLIDWORKS with CUSTOMTOOLS as an active add-in.

  2. Once SOLIDWORKS is started, open your Microsoft Visual Studio window with a solution of your CUSTOMTOOLS script add-in open.

  3. In the Visual Studio, click DEBUG, Attach to process.

    The Attach to process dialog box appear.

  4. Click the Select button associated to the Attach to box.

    The Select Code Type dialog box appear.

  5. Select the Debug these code types option and then select Managed (v4.5, v4.0) from the list associated to the Debug these code types option. Once the selections are done, click OK to exit the Select Code Type dialog box.

  6. From the Available Processes list, select the SOLIDWORKS process which is called SLDWORKS.exe.

  7. Click the Attach button to attach the Visual Studio Debugger to your running SOLIDWORKS process.

Now, if you have any breakpoint(s) set into your script add-in's source code in Visual Studio, the breakpoint icons associated to the lines of code should keep their appearance to indicate you that they will be hit while running the SOLIDWORKS operation the script add-in is about to be attached to.

See Also