The eDrawings API is implemented as a Microsoft ActiveX control.
Prerequisites
- Microsoft Visual Studio is installed
- eDrawings 20nn is installed
- eDrawings Example.zip is available
Modify SOLIDWORKS eDrawings C# example
Use the 3DSupport App to ask SOLIDWORKS API Support to provide the eDrawings Example.zip, which includes two Microsoft Visual Studio projects written in C# that you will modify in the following two procedures.
Procedure 1: Modify the SOLIDWORKS eDrawings Host Control C# example
- Unzip and extract eDrawingHostControl source project.zip, located in the HostControl folder.
- Open eDrawingHostControl.csproj in Microsoft Visual Studio and convert the project.
- Click Show All Files in the Solution Explorer and expand References.
- Locate and update the existing reference to Interop.EModelView.dll as necessary.
- Click Project > eDrawingHostControl Properties.
- Click Build and change Platform target to x64.
- Click Application, change Target framework as needed, and click Yes.
- Start debugging.
- Click Yes when informed of different versions.
- Click Close on the form.
- Save and exit the project.
Procedure 2: Modify the SOLIDWORKS eDrawings C# example
- Open eDrawingsExample.csproj in Microsoft Visual Studio and convert the project.
NOTE: This project is located in the eDrawingsExample folder.
- Click Project > eDrawingsExample Properties > Build and change Platform target to x64.
- Click Show All Files in the Solution Explorer and expand References.
- 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.
- Locate and update the existing reference to Interop.EModelView.dll as necessary.
- Change the name of the SOLIDWORKS or eDrawings file to open in Form1.cs to a file that exists on your computer.
- Start debugging.
- Click Yes when informed of different versions.
- Click Open to open the file.
- Click OK to close the message box.
- Close the form, save, and exit the project.
Create a C# eDrawings project
- Modify the SOLIDWORKS eDrawings Host Control C# example. See the first procedure.
- Open Microsoft Visual Studio.
- Create a C# Windows Forms Application project and name it WindowsFormsApplication1.
- Click Project > WindowsFormsApplication1 Properties.
- Click Build and change Platform target to x64.
- Click Application, change Target framework as needed, and click Yes.
- Click Show All Files in the Solution Explorer and expand References.
- Locate and add a reference to Interop.EModelView.dll.
- 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.
- Double-click Form1.cs in the Solution Explorer to show the form.
- Click View > Toolbox, expand All Windows Forms, and drag a button onto the form.
- Double-click the button.
- Replace the code in Form1.cs with this code:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using eDrawingHostControl;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
eDrawingHostControl.eDrawingControl ctrl = null;
public Form1()
{
InitializeComponent();
if (null == ctrl)
{
ctrl = new eDrawingControl();
}
this.Controls.Add(ctrl);
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
if(ctrl != null)
{
ctrl.Location = new Point(0,0);
ctrl.Size = new System.Drawing.Size(this.Size.Width,this.Size.Height);
ctrl.eDrawingControlWrapper.OpenDoc("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2024\\samples\\tutorial\\EDraw\\claw\\claw.sldprt", false, false, false, "");
}
}
}
}
- Start debugging to display the form.
- Click button1.
If the file specified in button1_Click 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 Form1.cs to specify a SOLIDWORKS or eDrawings file on your computer, and repeat steps 13 and 14.
- Close the form and save the project.
You can also ask SOLIDWORKS API Support to give you the sample, Add eModelViewControl to a Windows.Forms Application at runtime (eDrawings ActiveX Control), which shows how to add instances of the eDrawings ActiveX control IEModelViewControl to a Window.Forms application at runtime.
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:
- Run the Windows Registry editor, regedit.
- Expand HKEY_CLASSES_ROOT.
- 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 2024 is installed on your computer, then nn is 24.
- Click CLSID. Make note of the CLSID.
- Locate and double-click EModelViewMarkup.EModelMarkupControl.nn.
- Click CLSID. Make note of the CLSID.
- Exit regedit.
The version-independent eDrawings CLSIDs are:
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:
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