### C# DraftSight API Setup and Connection Source: https://help.solidworks.com/2026/english/api/draftsightapi/Switch_Layouts_Example_CSharp.htm This section outlines the necessary preconditions and setup for the C# example, including project setup, assembly references, and connecting to an active DraftSight instance. ```csharp //-------------------------------------------------------------- //Preconditions: // 1. Create a C# Windows console project. // 2. Copy and paste this example into the C# IDE. // 3. Add a reference to: // _install_dir_\**APISDK\tlb\DraftSight.Interop.dsAutomation.dll**. // 4. Add references to **System **and** System.Windows.Forms**. // 5. Start DraftSight and open a document. // 6. Start debugging the project. // //Postconditions: Message boxes pop up when a model or sheet //is activated. Read the text in each message box before clicking //OK to close it. //---------------------------------------------------------------- using DraftSight.Interop.dsAutomation; using System; using System.Windows.Forms; using System.Runtime.InteropServices; ``` ```csharp static class Module1 { ``` ```csharp public static void Main() { ``` ```csharp DraftSight.Interop.dsAutomation.Application dsApp; Document dsDoc = default(Document); ``` ```csharp //Connect to DraftSight ``` ```csharp dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application"); dsApp.**AbortRunningCommand**(); // abort any command currently running in DraftSight to avoid nested commands ``` ```csharp //Get active document dsDoc = dsApp.GetActiveDocument(); ``` ```csharp if (dsDoc != null) { //Activate each layout, one by one SwitchLayouts(dsDoc); ``` ```csharp } else { MessageBox.Show("There are no open documents in DraftSight."); } } public static void SwitchLayouts(Document dsDoc) { Sheet dsSheet = default(Sheet); Model dsModel = default(Model); object[] dsVarSheets = null; int index = 0; string sheetName = null; ``` ```csharp //Get all sheets dsVarSheets = (object[])dsDoc.GetSheets(); ``` ```csharp if (dsVarSheets != null) { ``` ```csharp for (index = dsVarSheets.GetLowerBound(0); index <= dsVarSheets.GetUpperBound(0); index++) { dsSheet = (Sheet)dsVarSheets[index]; ``` ```csharp //Get sheet name sheetName = dsSheet.Name; ``` ```csharp //Change sheet name, if it is not a model ``` ```csharp if (sheetName != "Model") { //Activate sheet dsSheet.Activate(); ``` ```csharp //Verify if the sheet was activated if (dsSheet.IsActive()) { MessageBox.Show("The sheet " + sheetName + " was activated."); } ``` ```csharp } else { //Activate model sheet dsModel = (Model)dsDoc.GetModel(); ``` ```csharp if (dsModel != null) { //Activate model sheet dsModel.Activate(); ``` ```csharp //Verify if the sheet was activated if (dsModel.IsActive()) { MessageBox.Show("The model sheet was activated."); } ``` ```csharp } ``` ```csharp } ``` ```csharp } ``` ```csharp } ``` ```csharp } ``` ```csharp } ``` -------------------------------- ### Example: Getting the IApplication Object (C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IApplication.html This example demonstrates how to obtain an IApplication object using C++. ```APIDOC ## Example: Getting the IApplication Object (C++) ### Description This code snippet shows how to get the IApplication object in C++. ### Code Example ```cpp myApplication *myApp = NULL; const dsString myApplication::appID = L"_Replace_with__ a _dd-in's_ __GUID_ "; #ifdef DS_WIN DSADDINSAMPLE_EXPORT bool connectToDraftSight(int cookie, dsApplication_c *dsApp) #else //DS_WIN extern "C" DSADDINSAMPLE_EXPORT bool connectToDraftSight(int cookie, dsApplication_c *dsApp) #endif //DS_WIN { if ( myApp == NULL ) { myApp = new myApplication(dsApp); myApp->CreateUserInterfaceAndCommands(); return true; } return false; } ``` ``` -------------------------------- ### Example: Working with IRay Objects (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IRay.html?id=17.4.1.107 Example demonstrating how to get and process an IRay object from the selection manager. ```APIDOC ## Example: Working with IRay Objects (COM native C++) If the selected object is an IRay object, then get the object. ```cpp //Write number of selected objects to output file long selCount = dsSelManager->GetSelectedObjectCount( dsSelectionSetType_Current ); strPrint.Format( L"Selected objects: (%d):\r\n", selCount ); fileOutput.WriteString( strPrint ); if( selCount > 0 ) { for( long i = 0; i < selCount; ++i ) { //Get selected object type dsObjectType_e retObjType; IDispatchPtr selObj = dsSelManager->GetSelectedObject( dsSelectionSetType_Current, i, &retObjType ); //If selected object is an Ray entity if(dsRayType == retObjType ) { IRayPtr dsRay( selObj ); strPrint.Format( L"Ray\n" ); fileOutput.WriteString( strPrint ); //Do dump for Ray entity //See the entity's Layer, LineScale, LineStyle, LineWeight, //or Visible property for the DumpGraphicsEntity template CAddinDumpManager::DumpGraphicsEntity( dsRay, fileOutput ); } } } ``` ``` -------------------------------- ### Example: Getting the IApplication Object (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IApplication.html This example demonstrates how to obtain an IApplication object using COM native C++. ```APIDOC ## Example: Getting the IApplication Object (COM native C++) ### Description This code snippet shows how to get the IApplication object in COM native C++. ### Code Example ```cpp public: CComQIPtr m_DsApp; public: STDMETHOD(ConnectToDraftSight)(LPDISPATCH DsApp, long Cookie, VARIANT_BOOL * IsConnected) { m_DsApp = DsApp; IUnknown* dsUnk = NULL ; HRESULT hr = DsApp->QueryInterface(IID_IUnknown, (void **) &dsUnk) // ... rest of the implementation return S_OK; // Placeholder for actual return value } ``` ``` -------------------------------- ### Get Application Instance (C++) Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.0 Demonstrates how to get an active application instance using the EW Interop Factory. This is part of a larger sample for starting applications. ```cpp int main () { getApplication(); return 0; } void getApplication() { 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); } ``` -------------------------------- ### Full HelloWorld Add-in Example Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/page3.html?id=3.2.3 A complete C# example of a SOLIDWORKS Electrical add-in that displays 'Hello World' and 'Good Bye' messages. This includes necessary using statements, COM visibility, GUID, and the implementation of connection, disconnection, and dialog methods. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; using EwAPI; namespace MyCSharpAddin { [ComVisible(true)] [Guid("edb6bfd9-22a6-486a-98b0-07be0d9b34d0")] public class HelloWorld : EwAPI.EwAddIn { IEwApplicationX mEwApplicationX; IEwInteropFactoryX mEwInteropFactory; public bool connectToEwAPI(object ewInteropFactory) { mEwInteropFactory = (IEwInteropFactoryX)ewInteropFactory; if (mEwInteropFactory == null) return false; EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; mEwApplicationX = mEwInteropFactory.getEwApplication("License Code(*)", out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) ||(mEwApplicationX == null)) return false; hello(); return true; } public bool disconnectFromEwApi() { goodBye(); return true; } public void hello() { // your function here: Sample if (mEwApplicationX == null) return; EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) || (ewDialogTask == null)) return; ewDialogTask.setContent("Hello World."); newDialogTask.addButton("Ok", 1); newDialogTask.show(out ewErrorCode); } public void goodBye() { // your function here if (mEwApplicationX == null) return; EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) || (ewDialogTask == null)) return; ewDialogTask.setContent("Good Bye."); newDialogTask.addButton("Ok", 1); newDialogTask.show(out ewErrorCode); } [ComRegisterFunctionAttribute] public static void RegisterFunction(Type t) { try { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "SOFTWARE\\SolidWorks\\SOLIDWORKS Electrical\\AddIns\\{" + t.GUID.ToString() + "}"; Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname); addinkey.SetValue(null, 0); addinkey.SetValue("Description", "Your add in description"); addinkey.SetValue("Title", "Your Add-in Name"); addinkey.SetValue("Path", System.Reflection.Assembly.GetExecutingAssembly().Location); addinkey = hkcu.CreateSubKey(keyname); addinkey.SetValue("StartUp", Convert.ToInt32(1), Microsoft.Win32.RegistryValueKind.DWord); } catch (System.NullReferenceException nl) { Console.WriteLine("There was a problem registering this dll. \n\"" + nl.Message + "\""); } catch (System.Exception e) { Console.WriteLine(e.Message); } } [ComUnregisterFunctionAttribute] public static void UnregisterFunction(Type t) { try { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "Software\\SolidWorks\\SOLIDWORKS Electrical\\AddIns\\{" + t.GUID.ToString() + "}"; hklm.DeleteSubKey(keyname); hkcu.DeleteSubKey(keyname); } catch (System.NullReferenceException nl) { Console.WriteLine("There was a problem unregistering this dll: " + nl.Message); } catch (System.Exception e) { Console.WriteLine("There was a problem unregistering this dll: " + e.Message); } } } } ``` -------------------------------- ### Get IEwApplicationX Interface Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/page3.html?id=3.2.3 C++ example demonstrating how to obtain an IEwApplicationX object to manage the application. Requires a license code and handles potential errors. ```cpp IEwApplicationX getEwApplication(BSTR strKey, EwErrorCode *errorCode) Return an IEwApplicationX object connect to the application. ``` -------------------------------- ### COM native C++ Example Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.ILine.html?id=17.4.1.73 This example demonstrates how to get a selected ILine object and write its properties to an output file using COM native C++. ```APIDOC ## COM native C++ Example If the selected object is an ILine object, then get the object. ```cpp //Write number of selected objects to output file long selCount = dsSelManager->GetSelectedObjectCount( dsSelectionSetType_Current ); strPrint.Format( L"Selected objects: (%d):\r\n", selCount ); fileOutput.WriteString( strPrint ); if( selCount > 0 ) { for( long i = 0; i < selCount; ++i ) { //Get selected object type dsObjectType_e retObjType; IDispatchPtr selObj = dsSelManager->GetSelectedObject( dsSelectionSetType_Current, i, &retObjType ); //If selected object is Line entity if( dsLineType == retObjType ) { ILinePtr dsLine( selObj ); strPrint.Format( L"Line\r\n" ); fileOutput.WriteString( strPrint ); //Do dump for Line entity //See the entity's Layer, LineScale, LineStyle, LineWeight, //or Visible property for the DumpGraphicsEntity template CAddinDumpManager::DumpGraphicsEntity( dsLine, fileOutput ); } } } ``` ``` -------------------------------- ### Start Application in Background (C#) Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.3 Shows how to initialize and get the application instance in background mode using C#. ```APIDOC ## startApplicationInBackground ### Description Initializes SOLIDWORKS Electrical in the background and retrieves the application instance. ### Language C# ### Code ```csharp static void startApplicationInBackground() { EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwInteropFactoryX ewInteropFactory = new EwInteropFactoryX(); EwAPIX ewApi = ewInteropFactory.getEwAPI(out ewErrorCode); if (ewApi != null) ewErrorCode = ewApi.initializeInBackground(0); EwApplicationX ewApplicationX = null; if (ewApi != null) ewApplicationX = ewAPI.getEwApplication("License Code(*)", out ewErrorCode); } ``` ``` -------------------------------- ### C# Console Example for PDM Pro API Source: https://help.solidworks.com/2026/english/api/pdmprowebapihelp/GettingStarted.html This C# example illustrates how to call the PDM Pro API. It uses HttpClient to send a GET request. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class PdmApiClient { public static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { string url = "http://localhost:5000/api/v1/ResourceGroups"; try { HttpResponseMessage response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); // Throw if HTTP status is not 2xx string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } catch (HttpRequestException e) { Console.WriteLine($"Error: {e.Message}"); } } } } ``` -------------------------------- ### Python Console Example for PDM Pro API Source: https://help.solidworks.com/2026/english/api/pdmprowebapihelp/GettingStarted.html This example shows how to interact with the PDM Pro API using Python. This requires the 'requests' library to be installed. ```python import requests url = "http://localhost:5000/api/v1/ResourceGroups" headers = { "Content-Type": "application/json" } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes data = response.json() print(data) except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` -------------------------------- ### LISP getcorner Function Example Source: https://help.solidworks.com/2026/english/api/draftsightlispreference/html/lisp_function_getcorner.htm This example demonstrates how to use the getcorner function to get the opposite corner of a rectangle, starting from a base point. The optional prompt string is displayed in the Command Window. ```lisp (getcorner '(10 10) "Second point: ") ``` -------------------------------- ### Using initget and getkword Source: https://help.solidworks.com/2026/english/api/draftsightlispreference/html/lisp_function_getkword.htm This example demonstrates how to set up keywords using initget and then prompt the user for input with getkword. The prompt string is displayed in the Command Window. ```lisp (initget 257 "Yes No") (getkword "Erase entities ? (Y/N): ") ``` -------------------------------- ### GetSequenceStartNumber Method Usage (Visual Basic) Source: https://help.solidworks.com/2026/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IFamilyTableFeature~GetSequenceStartNumber.html This example shows how to use the GetSequenceStartNumber method in Visual Basic to get the item start number from a family table feature. ```vb Dim instance As IFamilyTableFeature Dim value As System.Integer value = instance.GetSequenceStartNumber() ``` -------------------------------- ### Start Application in Background (C++) Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.0 Shows how to create an EW Interop Factory, initialize the API in background mode, and then retrieve the application object. ```cpp 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); } ``` -------------------------------- ### Getting the IApplication Object (C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IApplication.html?id=17.4.1.2 Example demonstrating how to get the IApplication object using C++. ```APIDOC ## Getting the IApplication Object (C++) ### Description This code snippet shows how to get the IApplication object using C++ by calling the `connectToDraftSight` function. ### Code Example ```cpp myApplication *myApp = NULL; const dsString myApplication::appID = L"_Replace_with__ a _dd-in's_ __GUID_ "; #ifdef DS_WIN DSADDINSAMPLE_EXPORT bool connectToDraftSight(int cookie, dsApplication_c *dsApp) #else //DS_WIN extern "C" DSADDINSAMPLE_EXPORT bool connectToDraftSight(int cookie, dsApplication_c *dsApp) #endif //DS_WIN { if ( myApp == NULL ) { myApp = new myApplication(dsApp); myApp->CreateUserInterfaceAndCommands(); return true; } return false; } ``` ``` -------------------------------- ### Add Command Sample in C++ Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/_add_command.html Example demonstrating how to add a custom command using C++. ```cpp #include "swconst.h" #include "swpublished.h" #include "swcommands.h" // Add a command sample in C++ // This is a placeholder for the actual C++ code. ``` -------------------------------- ### QueryInterface with Renamed IEntity GUID Lookup (C#) Source: https://help.solidworks.com/2026/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IEntity.html Example of using QueryInterface with the renamed SWEntity interface and a GUID lookup. ```csharp pFace->QueryInterface**(__uuidof(SWEntity),** (LPVOID*)&entity); ``` -------------------------------- ### Add Command Sample in C++ Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/_add_command.html?id=3.1.1 Example demonstrating how to add a custom command using C++. ```cpp #include "swconst.h" #include "swcommands.h" #include "swcommands.h" // Add a command sample in C++ // This is a placeholder for the actual C++ code sample. ``` -------------------------------- ### Add Toolbar Example (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IToolbar.html Example demonstrating how to add a toolbar using COM native C++. Ensure the DraftSight application object and necessary parameters are available. ```cpp IToolbarPtr pToolbar = m_DsApp->AddToolbar( m_sApiUuid, dsUIState_Document, L"DsAddin Toolbar"); ``` -------------------------------- ### ISldWorks::InstallQuickTipGuide Source: https://help.solidworks.com/2026/english/api/swhtmlcontrolapi/SOLIDWORKS.Interop.swhtmlcontrol~SOLIDWORKS.Interop.swhtmlcontrol.ISwHtmlInterface.html Installs the QuickTip guide for SolidWorks. ```APIDOC ## InstallQuickTipGuide ### Description Installs the QuickTip guide for SolidWorks. ### Method (Method details not provided in source) ### Parameters (Parameters not provided in source) ### Response (Response details not provided in source) ``` -------------------------------- ### Complete Add-in Implementation Example Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/page3.html This is a comprehensive example of a SOLIDWORKS Electrical add-in in C#. It includes the necessary using statements, namespace, COM visibility, GUID, inheritance from EwAddIn, connection/disconnection methods, and the 'hello' and 'goodBye' methods for displaying messages. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; using EwAPI; namespace MyCSharpAddin { [ComVisible(true)] [Guid("edb6bfd9-22a6-486a-98b0-07be0d9b34d0")] public class HelloWorld : EwAPI.EwAddIn { IEwApplicationX mEwApplicationX; IEwInteropFactoryX mEwInteropFactory; public bool connectToEwAPI(object ewInteropFactory) { mEwInteropFactory = (IEwInteropFactoryX)ewInteropFactory; if (mEwInteropFactory == null) return false; EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; mEwApplicationX = mEwInteropFactory.getEwApplication("License Code(*)", out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) ||(mEwApplicationX == null)) return false; hello(); return true; } public bool disconnectFromEwApi() { goodBye(); return true; } public void hello() { // your function here: Sample if (mEwApplicationX == null) return; EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) || (ewDialogTask == null)) return; ewDialogTask.setContent("Hello World."); ewDialogTask.addButton("Ok", 1); newDialogTask.show(out ewErrorCode); } public void goodBye() { // your function here if (mEwApplicationX == null) return; EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) || (ewDialogTask == null)) return; ewDialogTask.setContent("Good Bye."); ewDialogTask.addButton("Ok", 1); newDialogTask.show(out ewErrorCode); } [ComRegisterFunctionAttribute] public static void RegisterFunction(Type t) { try { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "SOFTWARE\\SolidWorks\\SOLIDWORKS Electrical\\AddIns\\{" + t.GUID.ToString() + "}"; Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname); addinkey.SetValue(null, 0); addinkey.SetValue("Description", "Your add in description"); addinkey.SetValue("Title", "Your Add-in Name"); addinkey.SetValue("Path", System.Reflection.Assembly.GetExecutingAssembly().Location); addinkey = hkcu.CreateSubKey(keyname); addinkey.SetValue("StartUp", Convert.ToInt32(1), Microsoft.Win32.RegistryValueKind.DWord); } catch (System.NullReferenceException nl) { ``` -------------------------------- ### Getting the IApplication Object (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IApplication.html?id=17.4.1.2 Example demonstrating how to obtain the IApplication object using COM native C++. ```APIDOC ## Getting the IApplication Object (COM native C++) ### Description This code snippet shows how to get the IApplication object using COM native C++ by querying for the IUnknown interface. ### Code Example ```cpp public: CComQIPtr m_DsApp; public: STDMETHOD(ConnectToDraftSight)(LPDISPATCH DsApp, long Cookie, VARIANT_BOOL * IsConnected) { m_DsApp = DsApp; IUnknown* dsUnk = NULL ; HRESULT hr = DsApp->QueryInterface(IID_IUnknown, (void **) &dsUnk); // ... rest of the implementation return S_OK; // Placeholder for actual return value } ``` ``` -------------------------------- ### ISweepFeatureData::GuideCurves Source: https://help.solidworks.com/2026/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFeature.html Gets the guide curves for a sweep feature. ```APIDOC ## ISweepFeatureData::GuideCurves ### Description Gets the guide curves for a sweep feature. ### Property ``` ISweepFeatureData::GuideCurves ``` ``` -------------------------------- ### Get Application Instance (VB) Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.3 This sample shows how to obtain an instance of the SOLIDWORKS Electrical application using the EwInteropFactoryX. ```APIDOC ## Vb_Get_Application ### Description Retrieves an instance of the SOLIDWORKS Electrical application. ### Method ```vb Public Sub getApplication() ``` ### Parameters None ### Request Example ```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) ``` ### Response - **ewApplicationX** (EwAPI.ewApplicationX) - An instance of the SOLIDWORKS Electrical application. - **ewErrorCode** (EwAPI.ewErrorCode) - Error code indicating success or failure. ``` -------------------------------- ### Start Application in Background Mode Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.5 Shows how to initialize and get the SOLIDWORKS Electrical application instance in background mode. ```APIDOC ## Vb_Get_Application_BackgroundMode ### Description Initializes the SOLIDWORKS Electrical API in background mode and retrieves the application instance. ### Method getEwAPI, initializeInBackground, getEwApplication ### Endpoint N/A (COM object) ### Parameters None explicitly shown in this snippet, but requires a valid license. ### Request Example ```vb Dim ewInteropFactory As New EwAPI.EwInteropFactoryX Dim ewAPI As EwAPI.ewAPIX Dim ewApplication As EwAPI.ewApplicationX Dim ewErrorCode As EwAPI.ewErrorCode ewAPI = ewInteropFactory.getEwAPI(ewErrorCode) ewErrorCode = ewAPI.initializeInBackground(0) ewApplicationX = ewAPI.getEwApplication("License Code(*)", ewErrorCode) ``` ### Response #### Success Response (200) - **ewApplicationX** (EwAPI.ewApplicationX) - An instance of the SOLIDWORKS Electrical application in background mode. ``` -------------------------------- ### Start Application in Background Mode Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.4 Shows how to initialize and get the SOLIDWORKS Electrical application instance in background mode. ```APIDOC ## Vb_Get_Application_BackgroundMode ### Description Initializes the SOLIDWORKS Electrical API in background mode and retrieves the application instance. ### Method ```vb Private Sub startApplicationInBackground() ``` ### Parameters None ### Request Example ```vb Dim ewInteropFactory As New EwAPI.EwInteropFactoryX Dim ewAPI As EwAPI.ewAPIX Dim ewApplication As EwAPI.ewApplicationX Dim ewErrorCode As EwAPI.ewErrorCode On Error GoTo Error_MayCauseAnError 'Get the EwAPI from the factory ewAPI = ewInteropFactory.getEwAPI(ewErrorCode) 'Initialise the EwApi in Background mode ewErrorCode = ewAPI.initializeInBackground(0) 'Get the application from the EwAPI ewApplication = ewAPI.getEwApplication("License Code(*)", ewErrorCode) ``` ``` -------------------------------- ### Start Application in Background Mode Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.2 Shows how to initialize and get the SOLIDWORKS Electrical application instance in background mode. ```APIDOC ## Vb_Get_Application_BackgroundMode ### Description Initializes the SOLIDWORKS Electrical API in background mode and retrieves the application instance. ### Method ```vb Private Sub startApplicationInBackground() ``` ### Parameters None ### Request Example ```vb Dim ewInteropFactory As New EwAPI.EwInteropFactoryX Dim ewAPI As EwAPI.ewAPIX Dim ewApplication As EwAPI.ewApplicationX Dim ewErrorCode As EwAPI.ewErrorCode On Error GoTo Error_MayCauseAnError 'Get the EwAPI from the factory ewAPI = ewInteropFactory.getEwAPI(ewErrorCode) 'Initialise the EwApi in Background mode ewErrorCode = ewAPI.initializeInBackground(0) 'Get the application from the EwAPI ewApplication = ewAPI.getEwApplication("License Code(*)", ewErrorCode) ``` ### Response - **ewApplication** (EwAPI.ewApplicationX) - An instance of the SOLIDWORKS Electrical application. - **ewErrorCode** (EwAPI.ewErrorCode) - The error code from the operation. ``` -------------------------------- ### Start Application in Background Mode Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.1 Shows how to initialize and get the SOLIDWORKS Electrical application instance in background mode. ```APIDOC ## Vb_Get_Application_BackgroundMode ### Description Initializes the SOLIDWORKS Electrical API in background mode and retrieves the application instance. ### Method `startApplicationInBackground()` ### Parameters None ### Request Example ```vb Dim ewInteropFactory As New EwAPI.EwInteropFactoryX Dim ewAPI As EwAPI.ewAPIX Dim ewApplication As EwAPI.ewApplicationX Dim ewErrorCode As EwAPI.ewErrorCode ewAPI = ewInteropFactory.getEwAPI(ewErrorCode) ewErrorCode = ewAPI.initializeInBackground(0) ewApplication = ewAPI.getEwApplication("License Code(*)", ewErrorCode) ``` ### Response - `ewApplication` (EwAPI.ewApplicationX) - The SOLIDWORKS Electrical application instance. ``` -------------------------------- ### Highlighting and Gripping Entities with sssetfirst Source: https://help.solidworks.com/2026/english/api/draftsightlispreference/html/lisp_function_sssetfirst.htm?id=20.200 This example demonstrates how to get a selection set using ssget and then use sssetfirst to highlight and grip those entities. The pseudo-argument is set to nil. ```lisp (setq selset (ssget)) (sssetfirst nil selset) ``` -------------------------------- ### ILoftFeatureData::GuideCurves Source: https://help.solidworks.com/2026/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFeature.html Gets the guide curves for a loft feature. ```APIDOC ## ILoftFeatureData::GuideCurves ### Description Gets the guide curves for a loft feature. ### Property ``` ILoftFeatureData::GuideCurves ``` ``` -------------------------------- ### Adding a Toolbar Example Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IToolbar.html Examples demonstrating how to add a toolbar to the list of available toolbars using COM native C++ and C++. ```APIDOC ## Example: Adding a Toolbar ### COM native C++ This example shows how to add a toolbar using COM native C++. ```cpp IToolbarPtr pToolbar = m_DsApp->AddToolbar( m_sApiUuid, dsUIState_Document, L"DsAddin Toolbar"); ``` ### C++ This example shows how to add a toolbar using C++. ```cpp dsString ToolbarName = L"QAddIn1_Toolbar"; dsToolbar_ptr pToolbar; dsApp->AddToolbar( myApplication::appID, dsUIState_Document, ToolbarName, &pToolbar ); ``` ``` -------------------------------- ### GetLanguage Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IApplication_members.html?id=17.4.1.2.0 Gets the name of the language supported by this DraftSight installation. ```APIDOC ## GetLanguage ### Description Gets the name of the language supported by this DraftSight installation. ### Method Not applicable (method call) ### Endpoint Not applicable ### Parameters None ### Request Example None ### Response - **language** (string) - The name of the supported language. ``` -------------------------------- ### Accessing Sustainability Use Data Source: https://help.solidworks.com/2026/english/api/sustainabilityapi/SOLIDWORKS.Interop.sustainability~SOLIDWORKS.Interop.sustainability.ISustainabilityUse.html Example demonstrating how to access the ISustainabilityUse interface to get sustainability part use data. This example is in VBA. ```APIDOC ## Example Calculate Environmental Impact of Part (VBA) ### Accessors ISustainabilityApp::GetSustainabilityPartUse ### See Also #### ISustainabilityUse Members SolidWorks.Interop.sustainability Namespace ``` -------------------------------- ### Examples of Creating Viewports Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IViewport.html Links to examples demonstrating how to create different types of viewports in various programming languages. ```APIDOC ## Viewport Creation Examples ### Description Examples are provided for creating rectangular viewports using different programming languages supported by the DraftSight API. ### Examples - Create Rectangular Viewport (C#) - Create Rectangular Viewport (VB.NET) - Create Rectangular Viewport (VBA) - Create Rectangular Viewport (JavaScript) ``` -------------------------------- ### Get ISketchManager Object Example (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.ISketchManager.html This example demonstrates how to obtain an ISketchManager object using COM native C++. ```APIDOC ## Get ISketchManager Object Example (COM native C++) ### Description This code snippet shows how to get the sketch interface by retrieving an ISketchManager object. ### Code Example ```cpp //Get ISketchManager object ISketchManagerPtr dsSketchManagerSheet( sheets[i]->GetSketchManager() ); ``` ``` -------------------------------- ### Full C# Command Implementation Example Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/page_add_comand_c_s.html?id=3.1.3 A complete C# example demonstrating the implementation of a custom command, including all required overridden methods and a test function. ```csharp using System.Runtime.InteropServices; using EwAPI; namespace UsersCommand { [ComVisible(true)] public class EwUsersCommandX : EwCommandX { public IEwApplicationX mEwApplicationX = null; public string getName(out EwErrorCode errorCode) { errorCode = EwErrorCode.EW_NO_ERROR; return "HelloWorld"; } public string getDescription(out EwErrorCode errorCode) { errorCode = EwErrorCode.EW_NO_ERROR; return "An Hello World Message"; } public int getFlags(out EwErrorCode errorCode) { errorCode = EwErrorCode.EW_NO_ERROR; return (int) (EwCommandType.kCommandSession | EwCommandType.kCommandNoUndoMarker); } public EwErrorCode execute(EwCommandContextX commandContextX) { // your function here: Sample EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR; if (mEwApplicationX == null) // mEwApplicationX declare previously see return ewErrorCode; EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode); if ((ewErrorCode != EwErrorCode.EW_NO_ERROR) || (ewDialogTask == null)) return ewErrorCode; ewDialogTask.setContent("Hello World."); newDialogTask.addButton("Ok", 1); newDialogTask.show(out ewErrorCode); return ewErrorCode; } public void test() { mEwApplicationX.runCommand("HelloWorld"); } } } ``` -------------------------------- ### Add Toolbar Example (C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IToolbar.html Example demonstrating how to add a toolbar using C++. This requires defining the toolbar name and ensuring the application object is accessible. ```cpp dsString ToolbarName = L"QAddIn1_Toolbar"; dsToolbar_ptr pToolbar; dsApp->AddToolbar( myApplication::appID, dsUIState_Document, ToolbarName, &pToolbar ); ``` -------------------------------- ### Get Active Document (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IApplication~GetActiveDocument.html Example of how to get the active document using the GetActiveDocument method in COM native C++. ```cpp //Get active document m_DsActiveDoc = m_DsApp->GetActiveDocument(); ``` -------------------------------- ### Get Application Instance Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.2 Demonstrates how to get an instance of the SOLIDWORKS Electrical application using the EwInteropFactoryX. ```APIDOC ## Vb_Get_Application ### Description Retrieves an instance of the SOLIDWORKS Electrical application. ### Method ```vb Private Sub getApplication() ``` ### Parameters None ### Request Example ```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) ``` ### Response - **ewApplicationX** (EwAPI.ewApplicationX) - An instance of the SOLIDWORKS Electrical application. - **ewErrorCode** (EwAPI.ewErrorCode) - The error code from the operation. ``` -------------------------------- ### Visual Basic Usage Example Source: https://help.solidworks.com/2026/english/api/emodelapi/eDrawings.Interop.EModelViewControl~eDrawings.Interop.EModelViewControl._IEModelViewControlEvents_OnComponentSelectionNotify2EventHandler.html Example of how to instantiate the _IEModelViewControlEvents_OnComponentSelectionNotify2EventHandler delegate in Visual Basic. It shows the basic setup for attaching a handler method. ```vb Dim instance As New _IEModelViewControlEvents_OnComponentSelectionNotify2EventHandler(AddressOf HandlerMethod) ``` -------------------------------- ### Accessing ILayer Object Example (COM native C++) Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.ILayer.html?id=17.4.1.67 This example demonstrates how to get an ILayer object from the selection manager in COM native C++. ```APIDOC ## Accessing ILayer Object Example (COM native C++) ### Description This example shows how to check if the selected object is an ILayer and retrieve it. ### Code Example ```cpp //Write number of selected objects to output file long selCount = dsSelManager->GetSelectedObjectCount( dsSelectionSetType_Current ); strPrint.Format( L"Selected objects: (%d):\r\n", selCount ); fileOutput.WriteString( strPrint ); if( selCount > 0 ) { for( long i = 0; i < selCount; ++i ) { //Get selected object type dsObjectType_e retObjType; IDispatchPtr selObj = dsSelManager->GetSelectedObject( dsSelectionSetType_Current, i, &retObjType ); //If selected object is a Layer entity if(dsLayerType == retObjType ) { ILayerPtr dsLayer( selObj ); strPrint.Format( L"Layer\n" ); fileOutput.WriteString( strPrint ); //Do dump for Layer entity //See the entity's LineStyle or LineWeight //property for the DumpGraphicsEntity template CAddinDumpManager::DumpGraphicsEntity( dsLayer, fileOutput ); } } } ``` ``` -------------------------------- ### IPageSetup Source: https://help.solidworks.com/2026/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.ICoreFeatureData.html Interface for page setup options. ```APIDOC ## IPageSetup ### Description Represents the page setup options for printing SOLIDWORKS documents. ### Usage This interface allows programmatic control over paper size, orientation, and other print settings. ### Methods (No specific methods documented in the provided text) ``` -------------------------------- ### IPageSetup Interface Source: https://help.solidworks.com/2026/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IBreakLine.html Interface for page setup options. ```APIDOC ## IPageSetup ### Description Represents the page setup settings for printing. ### Interface IPageSetup ``` -------------------------------- ### Start Application with File - LISP Source: https://help.solidworks.com/2026/english/api/draftsightlispreference/html/lisp_function_startapp.htm Use this function to launch an application and open a specific file with it. Ensure the application is in your system's PATH or provide a full path. ```lisp (startapp "notepad" "sample.txt") ``` -------------------------------- ### Add and Get Frame Example Source: https://help.solidworks.com/2026/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IGtolFrame.html Demonstrates adding a new frame, retrieving its count, and then getting a specific frame object. Use this to manage GTOL frames. ```vb boolstatus = swGtol.**AddFrame** FrameCount = swGtol.**GetFrameCount** 'frame count should increase by 1 Debug.Print "Frame added. Frame count now: " & FrameCount Stop Set swGtolFrame = swGtol.**GetFrame**(FrameCount) ``` -------------------------------- ### Create New Project (VB) Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/index.html?id=3.0.3 This sample shows how to create a new project using a specified template and language code. ```APIDOC ## Vb_Create_New_Project ### Description Creates a new SOLIDWORKS Electrical project from a template. ### Method ```vb Public Sub createNewProject(control As IRibbonControl) ``` ### Parameters - **control** (IRibbonControl) - The ribbon control that triggered the action. ### Request Example ```vb Dim ewInteropFactory As New ewAPI.EwInteropFactoryX Dim ewApplication As ewAPI.ewApplicationX Dim ewEnvironment As ewAPI.EwEnvironmentX Dim ewErrorCode As ewAPI.ewErrorCode Set ewInteropFactory = GetObject(, "ewAPI.EwInteropFactoryX") 'Get the application from the factory Set ewApplication = ewInteropFactory.getEwApplication("License Code(*)", ewErrorCode) 'Get the folder containing templates Set ewEnvironment = ewApplication.getEwEnvironment(ewErrorCode) Dim strTemplateFolderPath As String strTemplateFolderPath = ewEnvironment.getFolderPath(ewAPI.EwEnvironmentFolderPathValue.kFolderPathProjectTemplate, ewErrorCode) Dim strTemplateName As String strTemplateName = "IEC" Dim strFilePath As String strFilePath = strTemplateFolderPath strFilePath = strFilePath + strTemplateName strFilePath = strFilePath + ".proj.tewzip" Dim fso, msg Set fso = CreateObject("Scripting.FileSystemObject") If (fso.FileExists(strFilePath) = False) Then Exit Sub End If ' here we are calling the command to create a new project ' this command have two parameters: the template name and the language code ' if you don't pass those parameters you will be prompted to select them Dim strCommand As String strCommand = "ewNewProjectNoProperties " strCommand = strCommand + strTemplateName strCommand = strCommand + " EN" ewErrorCode = ewApplication.runCommand(strCommand) '("ewNewProjectNoProperties IEC EN") Set ewApplication = Nothing Set ewEnvironment = Nothing Set ewInteropFactory = Nothing Exit_MayCauseAnError: Exit Sub Error_MayCauseAnError: MsgBox "undefine error create new project", vbCritical, "Error" ' Resume execution with exit routine to exit function. Resume Exit_MayCauseAnError ``` ### Response - **ewErrorCode** (ewAPI.ewErrorCode) - Error code indicating success or failure of the command execution. ``` -------------------------------- ### Add Command Sample in C# Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/_add_command.html?id=3.1.1 Example demonstrating how to add a custom command using C# and integrate it into the Ribbon UI. ```csharp // Add a command sample in C# // This is a placeholder for the actual C# code sample. ``` -------------------------------- ### LISP substr Function Example without Length Source: https://help.solidworks.com/2026/english/api/draftsightlispreference/html/lisp_function_substr.htm Demonstrates extracting a substring from a specified start index to the end of the string. The starting character index is 1-based. ```lisp (substr "1234567890" 3) ``` -------------------------------- ### Setup and Preconditions for DraftSight Event Handling Source: https://help.solidworks.com/2026/english/api/draftsightapi/Fire_Application_and_Document_Events_Example_CSharp.htm Before running the code, ensure a C# Windows console project is created, necessary DraftSight interop DLLs are referenced, and a sample drawing and image file exist. Start DraftSight and prepare a drawing file as specified. ```csharp //------------------------------------------------------------ // Preconditions: // 1. Create a C# Windows console project. // 2. Copy and paste this example into the C# IDE. // 3. Add a reference to: // _install_dir_\**APISDK\tlb\DraftSight.Interop.dsAutomation.dll**. // 4. Add references to **System** and **System.Windows.Forms**. // 5. Change the path and name of the image file to insert. // **NOTE**: Image must be a PNG file. // 6. Start DraftSight, create, save, and close a drawing named // **c:\test\circle.dwg**. // 7. Set a break point in the project where the project connects // to DraftSight. // 8. Press F10 to step through the project. // // Postconditions: Message boxes pop up for all events, // regardless if fired. Read the the text in each message box // before clicking OK to close it. //-------------------------------------------------------------- ``` -------------------------------- ### Get Upload Progress Status Source: https://help.solidworks.com/2026/english/api/pdmprowebapihelp/Upload%20SOLIDWORKS%20Files%20to%20PDM%20Vault.postman_collection.json Use this GET request to check the status of an ongoing file upload operation. Replace :GUID with the unique identifier for the upload. ```json { "name": "{{basicURL}}progress/:GUID/status", "request": { "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{token}}", "type": "string" } ] }, "method": "GET", "header": [], "url": { "raw": "{{basicURL}}progress/:GUID/status", "host": [ "{{basicURL}}progress" ], "path": [ ":GUID", "status" ], "variable": [ { "key": "GUID", "value": "{{$guid}}" } ] } }, "response": [] } ``` -------------------------------- ### Show Context Help Source: https://help.solidworks.com/2026/english/api/sldworkselecapihelp/_usefull_commands.html?id=3.4.2 Launches the SolidWorks help documentation for a specific topic. ```APIDOC ## showContextHelp ### Description This command launches the help documentation for a given keyword. ### Method runCommand ### Parameters #### Path Parameters - **strKeyWord** (string) - Required - The keyword to search for in the help documentation. ### Request Example ``` mEwApplicationX.runCommand("showContextHelp EwAPI"); ``` ### Response #### Success Response (200) Launches the help topic. #### Response Example (No specific response example provided) ``` -------------------------------- ### Example Usage Source: https://help.solidworks.com/2026/english/api/draftsightapi/Interop.dsAutomation~Interop.dsAutomation.IAlignedDimension.html?id=17.4.1.0 Examples demonstrating how to use the IAlignedDimension interface for creating dimensions. ```APIDOC ## Examples - Create Aligned Linear and Ordinate Dimensions (C#) - Create Aligned Linear and Ordinate Dimensions (VB.NET) - Create Aligned Linear and Ordinate Dimensions (VBA) - Insert and Dimension Sketch (JavaScript) ``` -------------------------------- ### initget Source: https://help.solidworks.com/2026/english/api/draftsightlispreference/html/lisp_functions_alphabetically.htm?id=20.0 Initializes the next user input function. ```APIDOC ## initget ### Description Initializes the next user input function. ### Syntax (initget [_integer_] [_string_]) ``` -------------------------------- ### Accessing Feature Folder Contents Source: https://help.solidworks.com/2026/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFeatureFolder.html Examples demonstrating how to get the contents of a FeatureFolder. ```APIDOC ## Get Contents of FeatureFolder ### Description Examples are provided for retrieving the contents of a FeatureFolder in C#, VB.NET, and VBA. ### Usage Examples - Get Contents of FeatureFolder (C#) - Get Contents of FeatureFolder (VB.NET) - Get Contents of FeatureFolder (VBA) ```