Hide Table of Contents
SOLIDWORKS Electrical API  2021.0.0
Electrical API
Add-in sample in C# with a specialized library.

Purpose

This library is used to make easier the creation of add-in inside the application than just using the raw API.

Create C# project with Visual Studio

To start the creation of an add-in, you need to:

  • Open Visual Studio
  • File -> New -> Project
  • Select Visual C# -> Class Library (.NET Framework)

Click Next.

Click Create.

In the solution tree -> Go to project properties.

Verify that solution platform is x64

In the Build Events tab, In the Post-build events command line Add this comand line: C:\WINDOWS\Microsoft.NET\Framework64\$(frameworkversion)\regasm.exe "$(TargetPath)" /codebase

Rename Class1.cs file with an appropriate name for the add-in.

Modify code to make the add-in



Open Assemblyinfo.cs:

Verify that you have ComVisible(true) and not ComVisible(false).

Include references

Go to "Tools->Manage Nuget Packages for Solution..."

Select Package source: nuget.org.

In Browse, Select ElectricalAddinSDK:

And click on "Install":

Click on "OK":

Check under References, if you see:

  • ElectricalAddinSDK
  • NLog
  • SimpleInjector

Right click on Reference and select Add reference...

Add EwAPI Browse to the location of EwAPIX.dll

Modify code to implement the interface in the Add-in

In your Class interface (HelloWorld.cs):

  • Add: using System.Runtime.InteropServices;
  • Add: using ElecworksAddinSdk.General;
  • Add: using EwAPI;

Like in screen shot below:

Create a main class which inherit AddinBasicSkeleton and implement mandatory methods

Finally add those methods to your main class to register this add-in:

[ComRegisterFunction] // Define the function which register your COM addin
public static void RegisterFunction(Type t)
{
RegisterAddin(
t,
description: "My beautiful add-in",
title: "My add-in"
);
}
[ComUnregisterFunction] // Define the function which unregister your COM addin
public static void UnregisterFunction(Type t)
{
UnregisterAddin(t);
}
// This override is optional you can implement it if you need to do some specification action at the addin load
public override EwErrorCode OnConnectToEwAPI(object ewInteropFactory)
{
EwErrorCode baseConnectionResult = base.OnConnectToEwAPI(ewInteropFactory);
// Now you can get the application object by using AddinContainer.Get<EwApplicationX>();
// And do what your add-in should do
return baseConnectionResult;
}
Note
License Code(*): Contact your reseller to get your license code
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:21


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:   SOLIDWORKS Electrical API: Add-in sample in C# with a specialized library.
*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) 2021 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.