solidworks 插件开发相关问题

Larry_666 2017-11-21 05:22:51
用C#创建了一个solidworks的插件,自带例子代码。在注释了相关代码后,界面有没发生改变
public void AddCommandMgr()
{
ICommandGroup cmdGroup;
if (iBmp == null)
iBmp = new BitmapHandler();
Assembly thisAssembly;
int cmdIndex0, cmdIndex1;
string Title = "制造云软件", ToolTip = "制造云软件";


int[] docTypes = new int[]{(int)swDocumentTypes_e.swDocASSEMBLY,
(int)swDocumentTypes_e.swDocDRAWING,
(int)swDocumentTypes_e.swDocPART};

thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType());


int cmdGroupErr = 0;
bool ignorePrevious = false;

object registryIDs;
//get the ID information stored in the registry
bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs);

int[] knownIDs = new int[2] { mainItemID1, mainItemID2 };

if (getDataResult)
{
if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup
{
ignorePrevious = true;
}
}

cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr);
cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("DrawingTransformExpert.ToolbarLarge.bmp", thisAssembly);
cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("DrawingTransformExpert.ToolbarSmall.bmp", thisAssembly);
cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("DrawingTransformExpert.MainIconLarge.bmp", thisAssembly);
cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("DrawingTransformExpert.MainIconSmall.bmp", thisAssembly);

int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption);
cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption);

cmdGroup.HasToolbar = true;
cmdGroup.HasMenu = true;
cmdGroup.Activate();

bool bResult;



FlyoutGroup flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint",
cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable");


flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1");

flyGroup.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple;


foreach (int type in docTypes)
{
CommandTab cmdTab;

cmdTab = iCmdMgr.GetCommandTab(type, Title);

if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank
{
bool res = iCmdMgr.RemoveCommandTab(cmdTab);
cmdTab = null;
}

//if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs
if (cmdTab == null)
{
cmdTab = iCmdMgr.AddCommandTab(type, Title);

CommandTabBox cmdBox = cmdTab.AddCommandTabBox();

int[] cmdIDs = new int[3];
int[] TextType = new int[3];

cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0);

TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1);

TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

cmdIDs[2] = cmdGroup.ToolbarId;

TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout;

bResult = cmdBox.AddCommands(cmdIDs, TextType);



//CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox();
//cmdIDs = new int[1];
//TextType = new int[1];

//cmdIDs[0] = flyGroup.CmdID;
//TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout;

//bResult = cmdBox1.AddCommands(cmdIDs, TextType);

//cmdTab.AddSeparator(cmdBox1, cmdIDs[0]);

}

}
thisAssembly = null;

}
上述代码,我注释的部分应该不显示


上图中红色圈中的应该不显示呢
...全文
442 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hb006 2017-12-21
  • 打赏
  • 举报
回复
正好做到这个地方,估计楼主已经解决了~ 回复给自己做个标记吧。 造成问题原因是, 首次加载,代码将mainCmdGroupID、mainItemID1 、mainItemID2 保存到了注册表里, 以后每次加载,以下代码
 bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs);
如果没有修改mainCmdGroupID,那么,getDataResult=true;
if (getDataResult)
            {
                if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup
                {
                    ignorePrevious = true;
                }
            }
ID都相同的话 ignorePrevious =false,会导致
 
                CommandTab cmdTab;
                cmdTab = iCmdMgr.GetCommandTab(type, Title);
                //这里 true & false | false移除代码就不执行了。
                //可以试试把ignorePrevious强制设置为true
                if (cmdTab != null & !getDataResult | ignorePrevious)
                {
                    bool res = iCmdMgr.RemoveCommandTab(cmdTab);
                    cmdTab = null;
                }
                //cmdTab!=null,注释的代码不执行。
                if (cmdTab == null)
                {
                }

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧