Hide Table of Contents
SOLIDWORKS Electrical API  2021.0.0
Electrical API
Add a Ribbon button command in C# using a specialized C# library.

Create C# class with Visual Studio

  • Open your project in Visual Studio
  • Select your project and click on
  • Add -> New Item...
  • Select Visual C# Items -> Class
  • Rename your class here with MyCommandWithRibbonControl

Click OK.

Create a new Ribbon button Command

To create a new command, derive your MyCommandWithRibbonControl class from the AbstractRibbonCommand interface.

To use these interfaces see the Add-in sample in C# with a specialized library. sample.

public class MyCommandWithRibbonControl : AbstractRibbonCommand
{
public override string CommandName => "MySuperCommandWithRibbonControl";
protected override string RibbonTabSelector => "MyRibbonTab";
protected override string RibbonGroupSelector => "MyRibbonGroup";
protected override string ControlCaption => "MyCommand";
protected override string ControlImagePath => EmbeddedResourceExtractor.ExtractResourceFileInApplicationTemp("Sample.Resources.myImage.ico"); // The build action of this image needs to be set as "Embedded Resource"
protected override EwRibbonControlType RibbonControlType => EwRibbonControlType.kControlButton;
public override EwErrorCode execute(EwCommandContextX commandContextX)
{
AddinContainer.Get<Logger>()?.Info()
.Message("Called from command with ribbon control")
.Write();
return EwErrorCode.EW_NO_ERROR;
}
public override string getDescription(out EwErrorCode errorCode)
{
errorCode = EwErrorCode.EW_NO_ERROR;
return "My description";
}
}
Note
mEwApplicationX: application object previously created.
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:21
EwRibbonControlType
Type of the control that can be used in a ribbon.
Definition: EnumDefinition.idl:183


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 a Ribbon button command in C# using a specialized C# 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.