Hide Table of Contents
SOLIDWORKS Electrical API  2021.0.0
Electrical API
How to add a Ribbon Tab in SOLIDWORKS or in SOLIDWORKS Electrical

Table of Contents

Purpose

This document explains how to add Ribbon Tab dynamically in SOLIDWORKS or in SOLIDWORKS Electrical.

public bool connectToEwAPI(object ewInteropFactory)
{
IEwInteropFactoryX currentEwInteropFactory = (IEwInteropFactoryX)ewInteropFactory;
if (currentEwInteropFactory == null)
return false;
EwErrorCode ewErrorCode = EwErrorCode.EW_UNDEFINED_ERROR;
// ...
EwApISoftType ewApiSoftType = mEwApplicationX.getApplicationType(out ewErrorCode);
// Add some commands
addCommand();
if (mEwApplicationX.getApplicationType(out ewErrorCode) == EwApISoftType.kSoftType3DSW)
{
// We are in SOLIDWORKS and we want to add a new ribbon tab.
mSldWorks = (SldWorks.SldWorks)Marshal.GetActiveObject("SldWorks.Application");
if (mSldWorks == null)
return false;
mSwInterface = (SwInterface)mSldWorks.GetAddInObject("EwSwCabinetLayoutAddin.SwInterface.1");
if (mSwInterface == null)
return false;
mAddinID = mSwInterface.getCookie();
int[] cmdIndexPdf = new int[mMaxCommand];
int[] cmdIndexTxt = new int[mMaxCommand];
int cmdGroupErr = 0;
ICommandManager iCmdMgr = mSldWorks.GetCommandManager(mAddinID);
mCmdGroup = iCmdMgr.GetCommandGroup(mMainCmdGroupID);
if (mCmdGroup == null)
mCmdGroup = iCmdMgr.CreateCommandGroup2(mMainCmdGroupID, Properties.Resources.STR_ETC, Properties.Resources.STR_ETC, "", -1, true, ref cmdGroupErr);
int nToolbarOption = (int)swCommandItemType_e.swToolbarItem;
fillImageList();
cmdIndexPdf[0] = mCmdGroup.AddCommandItem2(Properties.Resources.STR_REF_PDF, 0, Properties.Resources.STR_GEN_PDF_COMMENT, Properties.Resources.STR_REF_PDF
, 0, "executeCommandCallBack(" + mEwCommandProject.getName(out ewErrorCode) + ")"
, "", mainItemID1, nToolbarOption);
// Add some other group or control ...
}
else
{
// We are in SOLIDWORKS Electrical and we want to add a new ribbon tab.
mEwRibbonX = mEwApplicationX.getEwRibbon(out ewErrorCode);
if (mEwRibbonX == null)
return false;
mEwRibbonTabX = mEwRibbonX.addTab(_getStrAddInName(), out ewErrorCode);
if (mEwRibbonTabX == null)
return false;
mEwRibbonGroupX = mEwRibbonTabX.addGroup(Properties.Resources.STR_PDF_COMPARISON, out ewErrorCode);
if (mEwRibbonGroupX == null)
return false;
mEwButtonPrep = mEwRibbonGroupX.addControl(EwRibbonControlType.kControlButton, "EwPreProject", out ewErrorCode);
if (mEwButtonPrep == null)
return false;
// Add some other group or control ...
}
return true;
}
Use this interface to connect to the application.
Definition: EwAPI.idl:1228
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:21
IEwRibbonControlX addControl(EwRibbonControlType eRibbonControlType, BSTR strCommand, EwErrorCode *errorCode)
Add a new control at the end of the ribbon group.
EwApISoftType
All the selection types.
Definition: EnumDefinition.idl:267
EwRibbonControlType
Type of the control that can be used in a ribbon.
Definition: EnumDefinition.idl:183
IEwRibbonTabX addTab(BSTR strCaption, EwErrorCode *errorCode)
Return an IEwRibbonTabX added to the Ribbon Tab.
EwApISoftType getApplicationType(EwErrorCode *errorCode)
Return application type.
IEwRibbonX getEwRibbon(EwErrorCode *errorCode)
return an IEwRibbonX interface to EwRibbonX object.
IEwRibbonGroupX addGroup(BSTR strCaption, EwErrorCode *errorCode)
Add a new group at the end of the ribbon tab.


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: How to add a Ribbon Tab in SOLIDWORKS or in SOLIDWORKS Electrical
*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.