This document explains how to add Ribbon Tab dynamically in SOLIDWORKS or in SOLIDWORKS Electrical.
public bool connectToEwAPI(object ewInteropFactory)
{
if (currentEwInteropFactory == null)
return false;
addCommand();
{
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);
}
else
{
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;
if (mEwButtonPrep == null)
return false;
}
return true;
}