### SOLIDWORKS API: Welcome and Getting Started Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/Overview/Library_Features_and_LibraryFeatureData_Objects_id=9f7cae87262948e8b1c3360693c60e5f This section serves as a welcome guide for new users of the SOLIDWORKS API, outlining the initial steps and resources for getting started with API programming. ```English // Welcome and getting started information is descriptive and does not contain code. ``` -------------------------------- ### Initialize SolidWorks API in C# Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Provides a C# example for initializing the SolidWorks API. It shows how to create an EwInteropFactoryX object, get the EwAPIX interface, and initialize the API in the background. It also includes retrieving an application instance. ```C# EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwInteropFactoryX ewInteropFactory = new EwInteropFactoryX(); EwAPIX ewApi = ewInteropFactory.getEwAPI(out ewErrorCode); if (ewApi != null) ewrCode = ewApi.initializeInBackground(0); EwApplicationX ewApplicationX = null; if (ewApi != null) ewApplicationX = ewAPI.getEwApplication("License Code(*)", out ewErrorCode); ``` -------------------------------- ### PDM Pro API Web Service Examples (JavaScript, Python, C#) Source: https://help.solidworks.com/2025/English/api/pdmprowebapihelp/GettingStarted This snippet provides console examples for interacting with the PDM Pro API Web Service using JavaScript, Python, and C#. These examples demonstrate common operations and integration patterns. ```javascript // JavaScript Example (Conceptual) console.log('Connecting to PDM Pro API...'); // Add JavaScript API calls here ``` ```python # Python Example (Conceptual) print('Connecting to PDM Pro API...') # Add Python API calls here ``` ```csharp // C# Example (Conceptual) System.Console.WriteLine("Connecting to PDM Pro API..."); // Add C# API calls here ``` -------------------------------- ### Get SOLIDWORKS Electrical Application Instance (VB) Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Shows a Visual Basic (VB) example for obtaining the SOLIDWORKS Electrical application instance. It uses GetObject to retrieve the interop factory and then calls getEwApplication. ```VB Dim ewInteropFactory As EwAPI.ewInteropFactoryX Dim ewApplication As EwAPI.ewApplicationX Dim ewErrorCode As EwAPI.ewErrorCode On Error GoTo Error_MayCauseAnError ewInteropFactory = GetObject(, "EwAPI.EwInteropFactoryX.1") 'Get the application from the factory ewApplicationX = ewInteropFactory.getEwApplication("License Code(*)", ewErrorCode) ``` -------------------------------- ### Get Installed Add-in Information Source: https://help.solidworks.com/2025/English/api/epdmapi/Load_Addin_Example_VBNET Retrieves and displays information for all installed SolidWorks add-ins. It iterates through an array of EdmAddInInfo2 objects, extracting details like name, class ID, company, description, path, and version. ```VB.NET Dim addIns() As EdmAddInInfo2 = Nothing AddinMgr.GetInstalledAddIns(addIns) Dim addinPath As String = "" Dim s As String = "" Dim idx As Integer idx = LBound(addIns) While idx <= UBound(addIns) s = "Add-in: " + addIns(idx).mbsAddInName + vbLf + "Class: " + addIns(idx).mbsClassID + vbLf s = s + "Company: " + addIns(idx).mbsCompany + vbLf + "Description: " + addIns(idx).mbsDescription + vbLf s = s + "Path: " + addIns(idx).mbsModulePath + vbLf + "Version: " + CStr(addIns(idx).mlAddInVersion) + vbLf s = s + "Req ver: " + CStr(addIns(idx).mlRequiredVersionMajor) + "." + CStr(addIns(idx).mlRequiredVersionMinor) MsgBox(s) addinName = addIns(idx).mbsAddInName ' Save the name of the add-in just installed idx = idx + 1 End While ``` -------------------------------- ### Get SOLIDWORKS Electrical Application Instance (Python) Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Illustrates how to get the SOLIDWORKS Electrical application instance using Python with the comtypes library. It includes error handling for when the application is not started. ```Python prog_id = 'EwAPI.EwInteropFactoryX' import comtypes.gen.EwAPI as EwAPI from comtypes.gen.EwAPI import * try: ew_interop_factory = comtypes.client.GetActiveObject(prog_id) except: print("Electrical is not started") error_code, i_apix = ew_interop_factory.getEwAPI() if error_code != comtypes.gen.EwAPI.EW_NO_ERROR: print("fail ew_interop_factory.getEwAPI: ", error_code) error_code, ew_application = ew_interop_factory.getEwApplication('License Code(*)') if error_code != comtypes.gen.EwAPI.EW_NO_ERROR: print("fail ew_interop_factory.getEwApplication: ", error_code) error_code, ew_environment = ew_application.getEwEnvironment() ew_environment=comtypes.client.dynamic._Dispatch(ew_environment._comobj).QueryInterface(IEwEnvironmentX) ``` -------------------------------- ### Start SolidWorks Application in Background C# Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Illustrates starting the SolidWorks application in the background using C#. The code creates an EwInteropFactoryX, gets the EwAPIX, initializes it for background operation, and then retrieves the application instance. ```C# static void startApplicationInBackground() { EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwInteropFactoryX ewInteropFactory = new EwInteropFactoryX(); EwAPIX ewApi = ewInteropFactory.getEwAPI(out ewErrorCode); if (ewApi != null) ewrCode = ewApi.initializeInBackground(0); EwApplicationX ewApplicationX = null; if (ewApi != null) ewApplicationX = ewAPI.getEwApplication("License Code(*)", out ewErrorCode); } ``` -------------------------------- ### Install Add-in Example (VB.NET) Source: https://help.solidworks.com/2025/English/api/epdmapi/Load_Addin_Example_VBNET This VB.NET code snippet demonstrates how to install an add-in using the SOLIDWORKS API. It is intended for developers working with SOLIDWORKS customization. ```VB.NET ' This is a placeholder for the actual VB.NET code to install an add-in. ' The specific implementation would involve interacting with the SOLIDWORKS API objects ' to register and load the add-in. ' Example structure: ' Sub InstallAddIn(addInPath As String) ' Dim swApp As Object ' swApp = CreateObject("SldWorks.Application") ' ' ... API calls to install add-in ... ' End Sub ``` -------------------------------- ### Authenticate and Authorize with PDM Pro Web API (Javascript, Python, C#) Source: https://help.solidworks.com/2025/English/api/pdmprowebapihelp/GettingStarted Examples are provided for authenticating users, authorizing access, and using GET and POST HTTP methods with the SOLIDWORKS PDM Pro Web API. These examples, particularly found in the api/{vaultName}/authenticate endpoint, are crucial for obtaining bearer tokens required for most API requests. ```Javascript See examples in api/{vaultName}/authenticate ``` ```Python See examples in api/{vaultName}/authenticate ``` ```C# See the C# console application example in api/{vaultName}/authenticate ``` -------------------------------- ### Get SOLIDWORKS Electrical Application Instance (C#) Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Provides a C# code example for retrieving the SOLIDWORKS Electrical application instance. It uses the Marshal.GetActiveObject method to get the interop factory and then the application object. ```C# EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwInteropFactoryX ewInteropFactory = (EwInteropFactoryX)Marshal.GetActiveObject("EwAPI.EwInteropFactoryX"); EwApplicationX ewApplicationX = null; if(ewInteropFactory != null) ewApplicationX = ewInteropFactory.getEwApplication("License Code(*)", out ewErrorCode); ``` -------------------------------- ### Connect to DraftSight API - VB.NET Source: https://help.solidworks.com/2025/English/api/draftsightapi/GettingStarted-draftsightapi Offers VB.NET code examples for connecting to a running DraftSight instance via the dsAutomation API. It shows how to get the active DraftSight application object. ```VB.NET Dim dsApp as Application Sub Main() 'Connect to DraftSight dsApp = GetObject(, "DraftSight.Application") ``` -------------------------------- ### Get Specific Add-in Information Source: https://help.solidworks.com/2025/English/api/epdmapi/Load_Addin_Example_VBNET Retrieves detailed information for a specific SolidWorks add-in using its path. It populates an EdmAddInInfo2 object with the add-in's properties. ```VB.NET Dim poInfo As EdmAddInInfo2 = Nothing AddinMgr.GetAddInInfo2(justInstalledPathName, Nothing, poInfo) s = "Getting info for add-in: " + poInfo.mbsAddInName + vbLf + "Class: " + poInfo.mbsClassID + vbLf s = s + "Company: " + poInfo.mbsCompany + vbLf + "Description: " + poInfo.mbsDescription + vbLf s = s + "Path: " + poInfo.mbsModulePath + vbLf + "Version: " + CStr(poInfo.mlAddInVersion) + vbLf s = s + "Req ver: " + CStr(poInfo.mlRequiredVersionMajor) + "." + CStr(poInfo.mlRequiredVersionMinor) MsgBox(s) ``` -------------------------------- ### Modify SOLIDWORKS eDrawings C# Example Project Source: https://help.solidworks.com/2025/English/api/emodelapi/GettingStarted-emodelapi This snippet outlines the procedure for modifying the main SOLIDWORKS eDrawings C# example project. Key steps include converting the project, updating the platform target to x64, removing old references, adding a new reference to eDrawingHostControl.dll, and updating Interop.EModelView.dll. ```csharp 1. Open **eDrawingsExample.csproj** in Microsoft Visual Studio and convert the project. 2. Click **Project > eDrawingsExample Properties > Build** and change Platform target to x64. 3. Click **Show All Files** in the Solution Explorer and expand **References**. 4. Remove the existing eDrawingHostControl reference and add a reference to **\bin\Debug\eDrawingHostControl.dll** , which you created in the first procedure. Check the date on the file to ensure that you are adding the DLL that you created. 5. Locate and update the existing reference to **Interop.****EModelView.dll** as necessary. 6. Change the name of the SOLIDWORKS or eDrawings file to open in **Form1.cs** to a file that exists on your computer. 7. Start debugging. 8. Click **Yes** when informed of different versions. 9. Click Open to open the file. 10. Click **OK** to close the message box. 11. Close the form, save, and exit the project. ``` -------------------------------- ### Install SOLIDWORKS API SDK Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/GettingStarted/SolidWorks_API_Getting_Started_Overview_id=496fa1c197e84f27a0267b0b82314401 Steps to install the SOLIDWORKS API SDK, including copying the MSI file and running the installer. It also covers manual template file copying for different Visual Studio versions. ```bash copy "\apisdk\SolidWorks API SDK.msi" "" copy "\win_b64\resources\MSI\SOLIDWORKS API SDK.msi" "" "\SolidWorks API SDK.msi" ``` ```bash c:\Users\_user_\Documents\Visual Studio 20xx\Templates\ProjectTemplates\Visual Basic c:\Users\_user_\Documents\Visual Studio 20xx\Templates\ProjectTemplates\Visual C# ``` -------------------------------- ### SOLIDWORKS Utilities API Application Steps Source: https://help.solidworks.com/2025/English/api/swutilitiesapi/GettingStarted-swutilitiesapi_id=4ce766403af0409b876dde89072ffad3 This snippet outlines the general workflow for creating a SOLIDWORKS Utilities application. It details the sequence of actions from opening documents to performing analyses and saving results. ```General 1. Opening the SOLIDWORKS document or documents, either interactively or programmatically. 2. Getting a pointer to the SOLIDWORKS Utilities interface. 3. If comparing faces on the SOLIDWORKS parts, getting and setting the angular or position tolerances. 4. Analyzing the geometry of a part, comparing features, geometry, or properties of documents, painting faces on the target part the same color as the source part, running a PowerSelect session, or running a thickness analysis. 5. Displaying or saving the results to a file. 6. Performing any necessary cleanup. ``` -------------------------------- ### Get DimensionStyle Names and Options Example (JS) Source: https://help.solidworks.com/2025/English/api/draftsightapi/Get_DimensionStyle_Names_and_Options_Example_JS This JavaScript example retrieves the names and options of DimensionStyles within a SOLIDWORKS document. It also demonstrates how to export the current view of a drawing to a PNG file. The example requires DraftSight to be started and provides steps to verify the output. ```JS /* This example shows how to get the names and options of the DimensionStyles in the document and how to export the current view of the drawing to a PNG file. 1. Start DraftSight. 2. Click **Get** **DimensionStyles**. 3. Examine the Output window. 4. Navigate to **C:\ProgramFiles\Dassault Systemes\DraftSight\Examples** to verify that the drawing document was exported to **B-44563.PNG.** NOTES: * Errors are printed to Output. * To recreate this example: 1. Right-click the topic and select to view the source. 2. Save the file as an HTML file. 3. Open the HTML file in your web browser. 4. If using Windows Internet Explorer and running scripts is blocked, click the Information bar near the top of the webpage and select **Allow Blocked Content**. */ // Placeholder for actual JavaScript code to interact with SOLIDWORKS API console.log("SOLIDWORKS API Example: Get DimensionStyle Names and Options"); console.log("This is a demonstration of retrieving DimensionStyle information and exporting a drawing view."); // Function to get DimensionStyle names and options (simulated) function getDimensionStyleInfo() { console.log("Getting DimensionStyle names and options..."); // In a real scenario, this would involve API calls to SOLIDWORKS return { "style1": {"optionA": "value1", "optionB": "value2"}, "style2": {"optionA": "value3", "optionB": "value4"} }; } // Function to export drawing view to PNG (simulated) function exportDrawingToPng(filePath) { console.log("Exporting current drawing view to: " + filePath); // In a real scenario, this would involve API calls to SOLIDWORKS console.log("Export successful (simulated)."); } // Execute the example functions const dimensionStyles = getDimensionStyleInfo(); console.log("Retrieved DimensionStyles:", dimensionStyles); const exportPath = "C:\\ProgramFiles\\Dassault Systemes\\DraftSight\\Examples\\B-44563.PNG"; exportDrawingToPng(exportPath); ``` -------------------------------- ### Setup Project to Distribute SOLIDWORKS Add-in Source: https://help.solidworks.com/2025/English/api/SWHelp_List_id=e2a356b3e02948e08c37849ecda9fb38 This section provides guidance on setting up a project for distributing SOLIDWORKS add-ins. It covers the necessary steps and considerations for packaging and deployment to ensure smooth installation for end-users. ```N/A Refer to SOLIDWORKS documentation for specific project setup and distribution guidelines for add-ins. ``` -------------------------------- ### Setup Project to Distribute SOLIDWORKS Add-in Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/Overview/Accessing_Add-ins This section details the steps required to set up a project for distributing a SOLIDWORKS Add-in. It likely covers project configuration, build settings, and packaging for deployment. ```N/A Setup Project to Distribute SOLIDWORKS Add-in ``` -------------------------------- ### SOLIDWORKS API: Setup Project to Distribute SOLIDWORKS Add-in Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/Overview/Implementation_Guidelines_id=d52c9f83bc1e44c69d6f53bbafed041b Provides guidance on setting up a distribution project for SOLIDWORKS add-ins. This involves configuring project settings, handling dependencies, and ensuring proper registration for deployment. ```C# // This is a conceptual example of project setup steps. // Actual implementation involves project configuration in Visual Studio. // 1. Create a new Class Library project in Visual Studio. // 2. Add references to SOLIDWORKS Interop assemblies (e.g., SolidWorks.Interop.sldworks.dll). // 3. Implement the ISwAddin interface. // 4. Use a Setup and Deployment project (or WiX Toolset) to create an installer. // 5. Ensure COM registration is handled correctly in the installer. ``` -------------------------------- ### SOLIDWORKS API: Setup Project to Distribute Add-in Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/Overview/Library_Features_and_LibraryFeatureData_Objects_id=9f7cae87262948e8b1c3360693c60e5f This documentation guides developers on setting up a project for distributing SOLIDWORKS add-ins. It covers packaging, deployment, and registration considerations for add-ins. ```C++ // Example of setup project configuration (conceptual) // This would typically involve build scripts or installer projects. ``` -------------------------------- ### Get Debug Add-in Information Source: https://help.solidworks.com/2025/English/api/epdmapi/Load_Addin_Example_VBNET Retrieves and displays information for SolidWorks add-ins that are configured for debugging. It iterates through an array of EdmAddInInfo2 objects, similar to installed add-ins, to show their properties. ```VB.NET Dim debugAddIns() As EdmAddInInfo2 = Nothing AddinMgr.GetDebugAddIns(debugAddIns) idx = LBound(debugAddIns) While idx <= UBound(debugAddIns) s = "Debug add-in: " + debugAddIns(idx).mbsAddInName + vbLf + "Class: " + debugAddIns(idx).mbsClassID + vbLf s = s + "Company: " + debugAddIns(idx).mbsCompany + vbLf + "Description: " + debugAddIns(idx).mbsDescription + vbLf s = s + "Path: " + debugAddIns(idx).mbsModulePath + vbLf + "Version: " + CStr(debugAddIns(idx).mlAddInVersion) + vbLf s = s + "Req ver: " + CStr(debugAddIns(idx).mlRequiredVersionMajor) + "." + CStr(debugAddIns(idx).mlRequiredVersionMinor) MsgBox(s) idx = idx + 1 End While ``` -------------------------------- ### Setup SOLIDWORKS Add-in Distribution Project Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/Miscellaneous/Create_Setup_Project_to_Distribute_SolidWorks_Add-in_id=ffe8d3404ce34123853cae9bbfc2d808 This snippet outlines the general steps and considerations for setting up a project to distribute SOLIDWORKS add-ins. It focuses on the project structure and necessary configurations for successful deployment. ```N/A 1. Create a new project in your preferred development environment (e.g., Visual Studio). 2. Configure the project to target the correct .NET Framework version compatible with your SOLIDWORKS version. 3. Add references to the SOLIDWORKS API type libraries (e.g., SolidWorks.Interop.sldworks.dll, SolidWorks.Interop.swpublished.dll). 4. Implement the add-in's functionality, ensuring it adheres to the SOLIDWORKS API interface requirements. 5. Set up the project's build output to include all necessary files, such as the add-in assembly, manifest files, and any external dependencies. 6. Create an installer package (e.g., MSI, ClickOnce) to facilitate easy distribution and installation of the add-in. ``` -------------------------------- ### Start SolidWorks Application in Background C++ Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b This C++ sample demonstrates starting the SolidWorks application in the background. It involves creating an instance of the interop factory, obtaining the API object, initializing it for background operation, and then retrieving the application instance. ```C++ void startApplicationInBackground() { EwAPI::IEwInteropFactoryXPtr iEwInteropFactoryXPtr; iEwInteropFactoryXPtr.CreateInstance(__uuidof(EwAPI::EwInteropFactoryX)); EwAPI::EwErrorCode errorCode = EwAPI::EwErrorCode::EW_UNDEFINED_ERROR; EwAPI::EwAPIX ewApi = iEwInteropFactoryXPtr->getEwAPI(&errorCode); if (ewApi != nullptr) errorCode = ewApi.initializeInBackground(0); EwAPI::IEwApplicationXPtr iEwApplicationXPtr = nullptr; if (ewApi != nullptr) iEwApplicationXPtr = ewApi.getEwApplication("License Code(*)", &errorCode); } ``` -------------------------------- ### Initialize SolidWorks API in C++ Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Demonstrates initializing the SolidWorks API in C++ using EwInteropFactoryX and retrieving an application instance. It shows how to create an instance of the factory, get the API object, initialize it in the background, and then obtain an application instance. ```C++ EwAPI::IEwInteropFactoryXPtr iEwInteropFactoryXPtr; iEwInteropFactoryXPtr.CreateInstance(__uuidof(EwAPI::EwInteropFactoryX)); EwAPI::EwErrorCode errorCode = EwAPI::EwErrorCode::EW_UNDEFINED_ERROR; EwAPI::EwAPIX ewApi = iEwInteropFactoryXPtr->getEwAPI(&errorCode); if (ewApi != nullptr) errorCode = ewApi.initializeInBackground(0); EwAPI::IEwApplicationXPtr iEwApplicationXPtr = nullptr; if (ewApi != nullptr) iEwApplicationXPtr = ewApi.getEwApplication("License Code(*)", &errorCode); ``` -------------------------------- ### Connect to SOLIDWORKS Toolbox Browser API (COM) Source: https://help.solidworks.com/2025/English/api/toolboxapi/GettingStarted-toolboxapi This snippet demonstrates how to connect to the SOLIDWORKS Toolbox Browser API using COM in C++. It involves getting an add-in object by its GUID and casting the Dispatch pointer to the IApplication interface. ```C++ LPDISPATCH pDisp = NULL; HRESULT hres = pSldWorks->GetAddInObject("{ED783340-D5DB-11d4-BD5A-00C04F019809}" , &pDisp); // Cast the Dispatch pointer to SOLIDWORKS.Interop.swbrowser.IApplication ``` -------------------------------- ### Get Line Edge Data in SolidWorks API Source: https://help.solidworks.com/2025/English/api/draftsightapi/Get_Hatch_and_Hatch_Boundary_Loop_Data_Example_CSharp Retrieves and prints the start and end point coordinates for a line segment within a hatch boundary loop. This function is part of the SolidWorks API for geometric data extraction. ```C# private static void GetLineEdgeData(HatchBoundaryLoop dsHatchBoundaryLoop, int edgeIndex) { double startPointX; double startPointY; double endPointX; double endPointY; dsHatchBoundaryLoop.GetLineEdgeData(edgeIndex, out startPointX, out startPointY, out endPointX, out endPointY); Debug.Print("Line edge data:"); Debug.Print(" Start point X = " + startPointX); Debug.Print(" Start Point Y = " + startPointY); Debug.Print(" End point X = " + endPointX); Debug.Print(" End point Y = " + endPointY); } ``` -------------------------------- ### Get Integer Input - With Prompt Source: https://help.solidworks.com/2025/English/api/draftsightlispreference/html/lisp_function_getint This example shows how to use the getint function with a custom prompt message to guide the user in specifying an integer value. ```SOLIDWORKS API : (getint "Specify an integer value: ") ``` -------------------------------- ### JavaScript Output Arguments - Single Value Source: https://help.solidworks.com/2025/English/api/draftsightapi/GettingStarted-draftsightapi Shows how to handle a single output argument from a DraftSight API function in JavaScript. It includes an example of calling a function and accessing its return value. ```JavaScript var mCircle = mSkMgr.InsertCircle(X,Y,Z,2); var mColor = mCircle.get_Color(); ``` -------------------------------- ### Instantiate SOLIDWORKS Connection and Access Simulation Add-in Source: https://help.solidworks.com/2025/English/api/swsimulationapi/GettingStarted-swsimulationapi This snippet demonstrates the initial steps to connect to SOLIDWORKS and access the Simulation add-in, which is a prerequisite for using the SOLIDWORKS Simulation API. It involves creating a SOLIDWORKS application instance and then retrieving the Simulation add-in object. ```vb.net Dim swApp As Object Dim COSMOSWORKS As Object Dim startAnalysis As Object ' Instantiate a SOLIDWORKS connection swApp = CreateObject("SldWorks.Application") ' Access the SOLIDWORKS Simulation add-in object COSMOSWORKS = swApp.GetAddInObject("SldWorks.Simulation") ``` -------------------------------- ### Accessing SOLIDWORKS API Examples and Projects Source: https://help.solidworks.com/2025/English/api/sldworksapiprogguide/Overview/SolidWorks_API_Examples_and_Projects_Overview_id=7d32d3dc4b1740c89ab6878fd99d6385 This section explains how to find and access API examples and projects for SOLIDWORKS. Examples are often linked within API Help topics, while sample projects are available on the SOLIDWORKS website via the Customer Portal's API Support page. Internet connection is required for downloading online resources. ```text Many interface, method, property, and delegate API Help topics contain links to examples in the Example section in the topics. Sample projects are available on the internet at the SOLIDWORKS website. Log in to the Customer Portal and visit the API Support page. NOTES: * You must be connected to the internet to download examples and projects stored on the internet. ``` -------------------------------- ### Modify SOLIDWORKS eDrawings Host Control C# Example Source: https://help.solidworks.com/2025/English/api/emodelapi/GettingStarted-emodelapi This snippet details the steps to modify the SOLIDWORKS eDrawings Host Control C# example project. It involves unzipping the source, opening the project in Visual Studio, updating references to Interop.EModelView.dll, and changing the platform target to x64. ```csharp 1. Unzip and extract **eDrawingHostControl source project.zip** , located in the HostControl folder. 2. Open **eDrawingHostControl.csproj** in Microsoft Visual Studio and convert the project. 3. Click **Show All Files** in the Solution Explorer and expand **References**. 4. Locate and update the existing reference to **Interop.EModelView.dll** as necessary. 5. Click **Project > eDrawingHostControl Properties**. 1. Click **Build** and change Platform target to x64. 2. Click **Application** , change Target framework as needed _,_ and click **Yes**. 6. Start debugging. 7. Click **Yes** when informed of different versions. 8. Click **Close** on the form. 9. Save and exit the project. ``` -------------------------------- ### Connect to DraftSight API - JavaScript Source: https://help.solidworks.com/2025/English/api/draftsightapi/GettingStarted-draftsightapi Includes JavaScript code to connect to DraftSight, utilizing provided library files and initializing a script manager to obtain the DraftSight application instance. ```JavaScript var mScript = new djScriptManager(); var mApp = mScript.getApplication(); ``` -------------------------------- ### Initialize SolidWorks API in C# Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=439eefe3bcd146938c39b891911bcc72 Provides a C# example for initializing the SolidWorks API. It includes creating an interop factory, obtaining the API object, initializing it in the background, and retrieving an application instance. ```C# EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwInteropFactoryX ewInteropFactory = new EwInteropFactoryX(); EwAPIX ewApi = ewInteropFactory.getEwAPI(out ewErrorCode); if (ewApi != null) ewrCode = ewApi.initializeInBackground(0); EwApplicationX ewApplicationX = null; if (ewApi != null) ewApplicationX = ewAPI.getEwApplication("License Code(*)", out ewErrorCode); ``` -------------------------------- ### Get Arc Edge Data in SolidWorks API Source: https://help.solidworks.com/2025/English/api/draftsightapi/Get_Hatch_and_Hatch_Boundary_Loop_Data_Example_CSharp Retrieves and prints geometric data for a circular arc edge, including its center coordinates, radius, start and end angles, and orientation. This function is part of the SolidWorks API for hatch boundary loop processing. ```C# private static void GetArcEdgeData(HatchBoundaryLoop dsHatchBoundaryLoop, int edgeIndex) { double centerX; double centerY; double radius; double startAngle; double endAngle; bool isCounterclockwiseFlag; dsHatchBoundaryLoop.GetArcEdgeData(edgeIndex, out centerX, out centerY, out radius, out startAngle, out endAngle, out isCounterclockwiseFlag); Debug.Print("Arc edge data:"); Debug.Print(" Center X = " + centerX); Debug.Print(" Center Y = " + centerY); Debug.Print(" Radius = " + radius); Debug.Print(" Start angle = " + startAngle); Debug.Print(" End angle = " + endAngle); Debug.Print(" Is counter-clockwise = " + isCounterclockwiseFlag); } ``` -------------------------------- ### SetupPage Constructor (Task Instance) Source: https://help.solidworks.com/2025/English/api/epdmapi/Schedule_Task_to_Find_Files_in_State_Addin_Example_CSharp Constructor for the SetupPage class when used with a task instance. It initializes the user control, vault, and task instance. Includes error handling for COM exceptions. ```C# public SetupPage(IEdmVault7 Vault, IEdmTaskInstance Props) { try { InitializeComponent(); mVault = Vault; mTaskProps = null; mTaskInst = Props; } catch (System.Runtime.InteropServices.COMException ex) { MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } ``` -------------------------------- ### Initialize SolidWorks API in Python Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b This Python sample shows how to initialize the SolidWorks API using comtypes. It demonstrates creating an object for EwAPI.EwInteropFactoryX, getting the API instance, initializing it in the background, and retrieving the application and environment objects. ```Python prog_id = 'EwAPI.EwInteropFactoryX' import comtypes.gen.EwAPI as EwAPI from comtypes.gen.EwAPI import * ew_interop_factory = comtypes.client.CreateObject(prog_id) error_code, i_apix = ew_interop_factory.getEwAPI() if error_code != comtypes.gen.EwAPI.EW_NO_ERROR: print("fail ew_interop_factory.getEwAPI: ", error_code) error_code = ew_API.initializeInBackground(0); error_code, ew_application = ew_interop_factory.getEwApplication('License Code(*)') if error_code != comtypes.gen.EwAPI.EW_NO_ERROR: print("fail ew_interop_factory.getEwApplication: ", error_code) error_code, ew_environment = ew_application.getEwEnvironment(); ``` -------------------------------- ### Get Layers Example (C#) Source: https://help.solidworks.com/2025/English/api/draftsightapi/Get_and_Set_Hatch_Pattern_Data_Example_CSharp This function retrieves all layer names from a given SOLIDWORKS document. It accesses the Layer Manager to get the layers and then extracts their names. ```C# private static string[] GetLayers(Document dsDoc) { LayerManager dsLayerManager = dsDoc.GetLayerManager(); object[] dsLayers = (object[])dsLayerManager.GetLayers(); string[] layerNames = new string[dsLayers.Length]; for (int index = 0; index < dsLayers.Length; ++index) { Layer dsLayer = dsLayers[index] as Layer; layerNames[index] = dsLayer.Name; } return layerNames; } ``` -------------------------------- ### SOLIDWORKS Document Manager API License Key Version Compatibility Source: https://help.solidworks.com/2025/English/api/swdocmgrapi/GettingStarted-swdocmgrapi This table illustrates the compatibility between the version of a SOLIDWORKS file and the version of the SOLIDWORKS Document Manager API license key, determining whether the API can access the file. ```Markdown Version in which SOLIDWORKS file created | Version of SOLIDWORKS Document Manager API license key | File Access Result ---|---|--- 2014 or earlier | 2014 or earlier | Success 2015 or later | 2014 or earlier | Failure 2015 or earlier | 2015 or later | Success ``` -------------------------------- ### SOLIDWORKS Toolbox Manager Example (VB.NET, C#) Source: https://help.solidworks.com/2025/English/api/toolboxapi/Welcome-toolboxapi_id=dbce4eab681440eba7af35140c8fe8f4 This example demonstrates how to develop an add-in to integrate a PDM application with the SOLIDWORKS Toolbox Browser. It is available for download from the SOLIDWORKS Forums and serves as a practical guide for utilizing the Toolbox Browser API. ```VB.NET ' Example VB.NET code for SOLIDWORKS Toolbox Manager Add-in ' (Actual code not provided in the input text, this is a placeholder) Public Class ToolboxManagerAddIn Implements ISwAddIn ' Add-in implementation details... End Class ``` ```C# // Example C# code for SOLIDWORKS Toolbox Manager Add-in // (Actual code not provided in the input text, this is a placeholder) using SolidWorks.Interop.sldworks; using SolidWorks.Interop.sldtoolboxconfigure; public class ToolboxManagerAddIn : ISwAddIn { // Add-in implementation details... } ``` -------------------------------- ### Get CAF Information for Add-in Source: https://help.solidworks.com/2025/English/api/epdmapi/Load_Addin_Example_VBNET Retrieves Common Application Framework (CAF) information for a SolidWorks add-in. This function populates EdmAddInInfo2, EdmAddInMenuInfo, and EdmAddInFileInfo objects with relevant data. ```VB.NET AddinMgr.GetCAFInfo(poInfo.mbsModulePath , "c:\temp", poInfo, ppoFiles, ppoCmds) msg = "Getting CAF info for add-in: " + poInfo.mbsAddInName + vbLf msg = msg + "CLSID=" + poInfo.mbsClassID + vbLf msg = msg + "Company=" + poInfo.mbsCompany + vbLf msg = msg + "Module=" + poInfo.mbsModulePath + vbLf msg = msg + "Version=" + CStr(poInfo.mlAddInVersion) + vbLf msg = msg + "Requires version=" + CStr(poInfo.mlRequiredVersionMajor) + "." + CStr(poInfo.mlRequiredVersionMinor) msg = msg + vbLf + "Files:" + vbLf idx = LBound(ppoFiles) While idx <= UBound(ppoFiles) msg = msg + ppoFiles(idx).mbsFileName + " Flags=" + CStr(ppoFiles(idx).mlEdmAddInFileInfoFlags) + vbLf idx = idx + 1 End While msg = msg + vbLf + "Commands:" + vbLf idx = LBound(ppoCmds) While idx <= UBound(ppoCmds) msg = msg + "'" + ppoCmds(idx).mbsMenuStr + "' flags=" + CStr(ppoCmds(idx).mlEdmMenuFlags) + vbLf idx = idx + 1 End While vault1.MsgBox(Me.Handle.ToInt32, msg) ``` -------------------------------- ### Traverse Model Features in SOLIDWORKS API (VB.NET) Source: https://help.solidworks.com/2025/English/api/sldworksapi/Create_and_Delete_Selection_Sets_Example_VBNET Initiates the traversal of features within a SOLIDWORKS model. It starts by getting the first feature and then calls a helper function to process subsequent features. ```VB.NET Sub TraverseModelFeatures(ByVal swModel As ModelDoc2) Dim swFeat As Feature swFeat = swModel.FirstFeature TraverseFeatureFeatures(swFeat) End Sub ``` -------------------------------- ### Get SOLIDWORKS Electrical Application Instance (C++) Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Demonstrates how to obtain an instance of the SOLIDWORKS Electrical application using the C++ API. It involves getting an interop factory and then retrieving the application object. ```C++ EwAPI::IEwInteropFactoryXPtr iEwInteropFactoryXPtr; iEwInteropFactoryXPtr.GetActiveObject(__uuidof(EwAPI::EwInteropFactoryX)); EwAPI::EwErrorCode errorCode = EwAPI::EwErrorCode::EW_UNDEFINED_ERROR; EwAPI::IEwApplicationXPtr iEwApplicationXPtr = nullptr; if (iEwInteropFactoryXPtr != nullptr) iEwApplicationXPtr = iEwInteropFactoryXPtr->getEwApplication("License Code(*)", &errorCode); ``` -------------------------------- ### Referencing SOLIDWORKS Routing API for .NET Source: https://help.solidworks.com/2025/English/api/routingapi/GettingStarted-routingapi_id=12bca2438c014348afca79ae4115f4dd For .NET applications, you must add a reference to the interop assembly. This assembly, 'SOLIDWORKS.interop.SWRoutingLib.dll', is typically found in the API redistributable folder within your SOLIDWORKS installation. ```.NET _install_dir_\api\redist\SOLIDWORKS.interop.SWRoutingLib.dll ``` -------------------------------- ### Referencing SOLIDWORKS Routing API for VBA/COM Source: https://help.solidworks.com/2025/English/api/routingapi/GettingStarted-routingapi_id=12bca2438c014348afca79ae4115f4dd For VBA and COM applications, you need to add a reference to the SOLIDWORKS Routing Type Library. This involves locating the 'SWRoutingLib.tlb' file in your SOLIDWORKS installation directory. ```VBA install_dir\SWRoutingLib.tlb ``` -------------------------------- ### Launch XLS Automation (VB) Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=36d317e100794466b1bee9a57069841b Automates the generation of an XLS file from the current SOLIDWORKS Electrical project. It prompts the user for confirmation and then executes the 'ewXlsAutomation' command with the current workbook's full path. This requires the 'EwAPI' library. ```VB Imports System Imports System.IO Imports System.Text Public Class testvb ' ... other methods ... Public Sub launchXlsAutomation(control As IRibbonControl) //! [Vb_launchXlsAutomation] Dim ewInteropFactory As New ewAPI.EwInteropFactoryX Dim ewApplication As ewAPI.ewApplicationX Dim ewEnvironment As ewAPI.EwEnvironmentX Dim ewErrorCode As ewAPI.ewErrorCode Dim ewProject As ewAPI.ewProjectX On Error GoTo Error_MayCauseAnError Set ewInteropFactory = GetObject(, "ewAPI.EwInteropFactoryX") 'Get the application from the factory Set ewApplication = ewInteropFactory.getEwApplication("License Code(*)", ewErrorCode) Set ewProject = ewApplication.getEwProjectCurrent(ewErrorCode) If ewProject Is Nothing Then 'If ewErrorCode = EwAPI.ewErrorCode.EW_NO_ACTIVEPROJECT Then MsgBox "You must create a new project before", vbCritical, "No Project" Exit Sub End If If MsgBox("Do you want generate XLS file ?", vbYesNo + vbQuestion + vbDefaultButton2, "XLS Automation") = vbNo Then Exit Sub End If Dim strCommand As String strCommand = "ewXlsAutomation " strCommand = strCommand + Workbooks(ThisWorkbook.Name).FullName ewErrorCode = ewApplication.runCommand(strCommand) Set ewApplication = Nothing Set ewProject = Nothing Set ewInteropFactory = Nothing Exit_MayCauseAnError: Exit Sub Error_MayCauseAnError: MsgBox "undefine error in XLS Automation", vbCritical, "Error" ' Resume execution with exit routine to exit function. Resume Exit_MayCauseAnError //! [Vb_launchXlsAutomation] End Sub End Class ``` -------------------------------- ### Connect to DraftSight API (JavaScript) Source: https://help.solidworks.com/2025/English/api/draftsightapi/GettingStarted-draftsightapi This snippet provides a conceptual outline for connecting to the DraftSight API using JavaScript. JavaScript examples are typically embedded within HTML files and interact with DraftSight through its COM interface. ```JavaScript // Example of connecting to DraftSight // This is a conceptual example and may require specific initialization steps. // var dsApp = new ActiveXObject("DraftSight.Application"); // dsApp.Visible = true; ``` -------------------------------- ### Start SolidWorks Application in Background in C++ Source: https://help.solidworks.com/2025/English/api/sldworkselecapihelp/index_id=439eefe3bcd146938c39b891911bcc72 This C++ sample demonstrates starting the SolidWorks application in the background. It involves creating an interop factory, getting the API object, initializing it, and then retrieving the application object. ```C++ void startApplicationInBackground() { EwAPI::IEwInteropFactoryXPtr iEwInteropFactoryXPtr; iEwInteropFactoryXPtr.CreateInstance(__uuidof(EwAPI::EwInteropFactoryX)); EwAPI::EwErrorCode errorCode = EwAPI::EwErrorCode::EW_UNDEFINED_ERROR; EwAPI::EwAPIX ewApi = iEwInteropFactoryXPtr->getEwAPI(&errorCode); if (ewApi != nullptr) errorCode = ewApi.initializeInBackground(0); EwAPI::IEwApplicationXPtr iEwApplicationXPtr = nullptr; if (ewApi != nullptr) iEwApplicationXPtr = ewApi.getEwApplication("License Code(*)", &errorCode); ``` -------------------------------- ### Connect to DraftSight API (VBA) Source: https://help.solidworks.com/2025/English/api/draftsightapi/GettingStarted-draftsightapi This example illustrates how to connect to the DraftSight API using VBA (Visual Basic for Applications). It typically involves setting a reference to the DraftSight type library within the VBA editor. ```VBA ' Example of connecting to DraftSight ' This is a conceptual example and may require specific initialization steps. ' Dim dsApp As DraftSight.Interop.dsAutomation.DrafSightApplication ' Set dsApp = New DraftSight.Interop.dsAutomation.DrafSightApplication ' dsApp.Visible = True ``` -------------------------------- ### Configure SolidWorks Task Setup Source: https://help.solidworks.com/2025/English/api/epdmapi/Schedule_Task_Addin_Example_CSharp This C# method configures the setup for a SolidWorks task add-in. It defines task properties, including menu command strings, status bar help text, and command IDs, to allow users to launch the task. ```C# private void OnTaskSetup(ref EdmCmd poCmd, ref EdmCmdData[] ppoData) { try { //Get the property interface used to //access the framework IEdmTaskProperties props = default(IEdmTaskProperties); props = (IEdmTaskProperties)poCmd.mpoExtra ; //Set the property flag that says you want a //menu item for the user to launch the task //and a flag to support scheduling props.TaskFlags = (int)EdmTaskFlag.EdmTask_SupportsInitExec + (int)EdmTaskFlag.EdmTask_SupportsScheduling ; //Set up the menu commands to launch this task EdmTaskMenuCmd[] cmds = new EdmTaskMenuCmd[1]; cmds[0].mbsMenuString = "List Approved files task"; cmds[0].mbsStatusBarHelp = "This command runs the task add-in to get the names of the files in the Approved state."; cmds[0].mlCmdID = 1; cmds[0].mlEdmMenuFlags = (int)EdmMenuFlags.EdmMenu_Nothing ; props.SetMenuCmds(cmds); } catch (System.Runtime.InteropServices.COMException ex) { MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } ``` -------------------------------- ### XML Configuration for C++ Add-ins Source: https://help.solidworks.com/2025/English/api/draftsightapi/GettingStarted-draftsightapi Specifies the XML structure for configuring C++ add-ins, including the add-in's name, help tooltip, startup behavior, and the path to the compiled DLL. This format is specific to C++ add-in projects. ```XML ```