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;
EwApISoftType ewApiSoftType = mEwApplicationX.getApplicationType(out ewErrorCode);
addCommand();
if (mEwApplicationX.getApplicationType(out ewErrorCode) ==
EwApISoftType.kSoftType3DSW)
{
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;
mEwButtonPrep = mEwRibbonGroupX.addControl(
EwRibbonControlType.kControlButton,
"EwPreProject", out ewErrorCode);
if (mEwButtonPrep == null)
return false;
}
return true;
}
EwRibbonControlType
Type of the control that can be used in a ribbon.
Definition: EnumDefinition.idl:239
EwApISoftType
All the selection types.
Definition: EnumDefinition.idl:323
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:24
Use this interface to connect to the application.
Definition: EwAPI.idl:1500