Hide Table of Contents
Getting Started

Glossary Item Box

Using the eDrawings ActiveX control

The eDrawings API is implemented as a Microsoft ActiveX control. This topic shows how to create Microsoft Visual Basic and C# Windows Forms applications that use this control to load eDrawings drawings.

Prerequisites
  • Microsoft Visual Studio 2010 or later is installed.
  • eDrawings 20nn is installed.
Instructions
eDrawings

Click the link that matches the language in which you want to create a Microsoft Visual Studio Windows Forms application:

The SolidWorks API Forum contains working VB.NET and C# examples for 32-bit machines. You must be a SolidWorks subscription customer to access the SolidWorks API forum's documents.

  1. Open https://forum.solidworks.com/community/solidworks/api?view=documents.
  2. Log in.
  3. Click SolidWorks > API to open the SolidWorks API forum.
  4. Click the Documents tab.
  5. Locate and download eDrawings 2013 API Example (VB.NET, C#).
Visual Basic
  1. Create a Visual Basic Windows Forms application.
    1. Open Microsoft Visual Studio 2010.
    2. Select New Project on Start Page.
    3. In Installed Templates, expand Visual Basic and select Windows Forms Application.

      NOTE: Depending on how you set up your Microsoft Visual Studio environment, you might have to expand Other Languages to access Visual Basic.
    4. Type a name for the new project in Name.
    5. Click OK.
    6. Right-click the new project in the Solution Explorer and select Add Reference.
    7. In the Add Reference dialog, select COM, and select EModelView 20nn Type Library.
    8. Click Add.
    9. Click Close.
  2. Configure the Toolbox with the eDrawings 20nn Control.
    1. If the Toolbox tab is not visible:
      1. Select Tools > Import and Export Settings > Reset all settings.
      2. Click Next.
      3. Click Next.
      4. Select Visual Basic Development Settings.
      5. Click Finish.
      6. Click Close.
    2. In the Toolbox, right-click anything and select Choose Items.
    3. In the Choose Toolbox Items dialog, select the COM Components tab.
    4. Select eDrawings 20nn Control.

      NOTE: EModelView.dll contains an ActiveX control that is registered as eDrawings 20nn Control when eDrawings is installed in C:\Program Files\SolidWorks Corp\SolidWorks eDrawings. If you see more than one version of the eDrawings control in the COM Components tab, select only the newer version. Only one version can be referenced in the project. If you do not see eDrawings 20nn Control:

           1. Click Browse at the bottom of the Choose Toolbox Items dialog.
           2. Open C:\Program Files\SolidWorks Corp\SolidWorks eDrawings\EModelView.dll.
           3. Select eDrawings 20nn Control.
    5. Click OK.

      eDrawings 20nn Control is now available in the Toolbox.
  3. Populate the Windows form.
    1. Drag the eDrawings 20nn Control from the Toolbox to a location on the Windows form.
    2. Double-click the control to open the code for the control.

      The name of the variable that is assigned to the eDrawings ActiveX control is AxEModelViewControl1. This is the entry point into the eDrawings API for Visual Basic. Use this variable to call the rest of the eDrawings API.
    3. Close the code window.
    4. Drag a button from the Toolbox to a location on the Windows form.
    5. Double-click the button to open the code for Button1.
    6. Add the following line to the Button1_Click subroutine:

      AxEModelViewControl1.OpenDoc("C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\edraw\claw\claw-mechanism.edrw", False, False, False, "")
  4. Start debugging the project.
  5. Click Button1 on the Windows form.

    The specified drawing loads into the eDrawings ActiveX control.
  6. Stop debugging and save the project.

    Back to top

C#
  1. Create a C# Windows Forms application.
    1. Open Microsoft Visual Studio 2010.
    2. Select New Project.
    3. In the Installed Templates tab, expand Visual C# and select Windows Forms Control Library.

      NOTE: Depending on how you set up your Microsoft Visual Studio environment, you might have to expand Other Languages to access Visual C#.
    4. Type a name for the new project in Name.
    5. Click OK.
    6. Right-click the new project in the Solution Explorer and select Add Reference.
    7. In the Add Reference dialog, select COM, and select EModelView 20nn Type Library.
    8. Click Add.
    9. Click Close.
  2. Configure the Toolbox with the eDrawings 20nn Control.
    1. If the Toolbox tab is not visible:
      1. Select Tools > Import and Export Settings > Reset all settings.
      2. Click Next.
      3. Click Next.
      4. Select Visual C# Development Settings.
      5. Click Finish.
      6. Click Close.
    2. In the Toolbox, right-click anything and select Choose Items.
    3. In the Choose Toolbox Items dialog, select the COM Components tab.
    4. Select eDrawings 20nn Control.

      NOTE: EModelView.dll contains an ActiveX control that is registered as eDrawings 20nn Control when eDrawings is installed in C:\Program Files\SolidWorks Corp\SolidWorks eDrawings. If you see more than one version of the eDrawings control in the COM Components tab, select only the newer version. Only one version can be referenced in the project. If you do not see eDrawings 20nn Control:

           1. Click Browse at the bottom of the Choose Toolbox Items dialog.
           2. Open C:\Program Files\SolidWorks Corp\SolidWorks eDrawings\EModelView.dll.
           3. Select eDrawings 20nn Control.
    5. Click OK.

      eDrawings 20nn Control is now available in the Toolbox.
  3. Populate the Windows form.
    1. Drag the eDrawings 20nn Control from the Toolbox to a location on the Windows form.
    2. Double-click the control to open the code for the control. 

      The name of the variable that is assigned to the eDrawings ActiveX control is axEModelViewControl1. This is the entry point into the eDrawings API for C#. Use this variable to call the rest of the eDrawings API.
    3. Close the code window.
    4. Drag a button from the Toolbox to a location on the Windows form.
    5. Double-click the button to open the code for button1.
    6. Add the following line to the button1_Click subroutine:

      axEModelViewControl1.OpenDoc("C:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\edraw\\claw\\claw-mechanism.edrw", false, false, false, "");
  4. Start debugging the project.
  5. Click button1 on the Windows form.

    The specified drawing loads into the eDrawings ActiveX control.
  6. Stop debugging and save the project.

Back to top

eDrawings x64

Modify SolidWorks Forum eDrawings x64 Host Control C# example

If running eDrawings 20nn x64 Edition, then you must manually generate the 64-bit primary interop assembly DLL needed by your Microsoft Visual Studio C# Windows Forms Application, because Microsoft Visual Studio is a 32-bit application. 

 

To generate the 64-bit primary assembly DLL:

  1. Install eDrawings 20nn x64 Edition, if it is not already installed on your computer.
  2. Install Microsoft.NET Framework v2.0 Software Development Kit (SDK) (64bit), if it is not already installed on your computer.
  3. Click Start > All Programs > Microsoft .NET Framework SDK v2.0 (64bit) > SDK Command Prompt.
  4. At the SDK Command Prompt, type:
    1. tlbimp.exe "C:\Program Files\SolidWorks Corp\SolidWorks eDrawings X64 Edition\EModelView.dll"
      - or -
      tlbimp.exe "C:\Program Files\Common Files\eDrawings20nn\EModelView.dll"

      Examine the command window to verify that Type library imported to EModelView.dll is returned.

      NOTE: If eDrawings 20nn x64 Edition is installed elsewhere on your computer, then modify the path to EModelView.dll.
    2. exit

 

To modify the SolidWorks Forum eDrawings x64 Host Control C# example:

  1. Open and extract the eDrawings Host Control example, eDrawings Example.zip, which includes two Microsoft Visual Studio projects written in C#.

    NOTE: You must be a SolidWorks Subscription Service customer to access the example.
  2. Unzip and extract eDrawingHostControl source project.zip, located in the HostControl folder.
  3. Open eDrawingHostControl.csproj in Microsoft Visual Studio 2010 and convert the project.
  4. Click the Show All Files button in the Solution Explorer and expand References.
  5. Remove the existing reference to EModelView and add a reference to C:\Program Files\Microsoft.NET\SDK\V2.0 64bit\EModelView.dll, which you created in the previous procedure.
  6. Start debugging.
  7. Click Yes when informed of different versions.
  8. Click Close on the form.
  9. Save and exit the project.

 

To modify the SolidWorks Forum eDrawings example:

  1. Open eDrawingsExample.csproj in Microsoft Visual Studio 2010 and convert the project. This project is located in the eDrawingsExample folder.
  2. Click the Show All Files button in the Solution Explorer and expand References.
    1. Remove the existing eDrawingHostControl reference and add a reference to \bin\Debug\eDrawingHostControl.dll, which you created when you debugged eDrawingHostControl.csproj in the previous procedure. Check the date on the file to ensure that you are adding the DLL that you created.
    2. Remove the reference to Interop.EModelView and add a reference to C:\Program Files\Microsoft.NET\SDK\V2.0 64bit\EModelView.dll.
  3. Change the name of the SolidWorks or eDrawings file to open in Form1.cs to a file that exists on your computer.
  4. Start debugging.
  5. Click Yes when informed of different versions.
  6. Click Open to open the file.
  7. Click OK to close the message box.
  8. Close the form, save, and exit the project.

Back to top

Create C# eDrawings x64 project

To create a C# eDrawings x64 project:

  1. Create an eDrawings x64 EModelView.dll. See the first procedure in the previous section. Skip this step if you performed that procedure.
  2. Download and modify the SolidWorks Forum eDrawings x64 Host Control example's Host Control project. See the second procedure in the previous section. Skip this step if you performed that procedure.
  3. Open Microsoft Visual Studio 2010.
    1. Create a C# Windows Forms Application project.
    2. Click the Show All Files button in the Solution Explorer and expand References.
    3. Add a reference to the C:\Program Files\Microsoft.NET\SDK\V2.0 64bit\EModelView.dll.
    4. Add a reference to \bin\Debug\eDrawingHostControl.dll, which you created when you debugged eDrawingHostControl.csproj in the second procedure in the previous section. Check the date on the file to ensure that you are adding the DLL that you created.
    5. Drag the eDrawings Control from the Toolbox to a location on the form.
    6. Double-click the control on the form to add the eDrawingControl1_Load event to the form's code. Close the form's code.
    7. Drag a button from the Toolbox to a location on the form.
    8. Double-click button1.
    9. Add the following code to the button1_Click event:

      eDrawingControl1.eDrawingControlWrapper.OpenDoc("c:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\edraw\\claw\\claw.sldprt", false, false, false, "");
    10. Click the Debug drop-down list box, select Configuration Manager, click x86 in the Platform column, select <New>, and make sure that Any CPU appears in New platform, click OK, and click Close.
    11. Start debugging.

      The form is displayed. Click button1. If the file specified in step 3.i exists on your computer, it is displayed. If that file does not exist on your computer, then close the form, edit the file's path and file name in the form's code to specify a SolidWorks or eDrawings file on your computer, and start debugging.
    12. Close the form and save the project.

Back to top

Instantiating the eDrawings Control

You can instantiate the eDrawings control using version-specific or version-independent class IDs (CLSIDs).

To get your version-specific eDrawings control's CLSIDs:

  1. Run the Windows Registry editor, regedit.

  2. Expand HKEY_CLASSES_ROOT.

  3. Locate and double-click EModelView.EModelViewControl.nn, where nn is the 2-digit release year of the version of eDrawings installed on your computer. For example, if eDrawings 2014 is installed on your computer, then nn is 14.

  4. Click CLSID. Make note of the CLSID.

  5. Locate and double-click EModelViewMarkup.EModelMarkupControl.nn.

  6. Click CLSID. Make note of the CLSID.

  7. Exit regedit.

The version-independent eDrawings CLSIDs are:

  • EModelNonVersionSpecificViewControl = 22945A69-1191-4DCF-9E6F-409BDE94D101
  • EModelNonVersionSpecificMarkupControl = 5BBBC05A-BD4D-4e3b-AD5B-51A79DFC522F

SolidWorks recommends that you use version-specific CLSIDs, because Microsoft Visual Studio selects them by default. However, because CLSIDs are version specific, with each new release of eDrawings you must edit:

  • your application.  

  • any HTML pages that reference version-specific CLSIDs.

Although you do not need to edit your application when working with multiple versions of eDrawings when using the version-independent CLSID, if your application uses a newer API than present in an older version of eDrawings installed by your user, your application will not work properly. This scenario can be difficult to debug remotely, especially with HTML applications.

Back to top



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Getting Started
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.