solidworks二次开发

你好,可以向您问一下关于solidworks二次开发的问题吗

  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7410607
  • 你也可以参考下这篇文章:Solidworks二次开发系列入门1
  • 除此之外, 这篇博客: SolidWorks二次开发经验总结中的 五、工具栏的设置 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 模版SwAddin.cs中自带,找不同点进行修改(未精减)

    		public void AddCommandMgr()
            {
                ICommandGroup cmdGroup;
                if (iBmp == null)
                    iBmp = new BitmapHandler();
                Assembly thisAssembly;
                int cmdIndex0, cmdIndex1, cmdIndex2;
                //名称和提示文件
                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;
                //获取存储在注册表中的ID信息
                //get the ID information stored in the registry
                bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs);
    
                int[] knownIDs = new int[3] { mainItemID1, mainItemID2, mainItemID3 };
    
                if (getDataResult)
                {
                    //如果id不匹配,重置命令组
                    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("Addin2014.ToolbarLarge.bmp", thisAssembly);
                cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("Addin2014.ToolbarSmall.bmp", thisAssembly);
                cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("Addin2014.MainIconLarge.bmp", thisAssembly);
                cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("Addin2014.MainIconSmall.bmp", thisAssembly);
    
    			//增加按钮(工具栏的"触发器")
                int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
                cmdIndex1 = cmdGroup.AddCommandItem2("模型库", -1, "模型库", "模型库", 1, "ShowPMP", "", mainItemID2, menuToolbarOption);
                cmdIndex0 = cmdGroup.AddCommandItem2("用户登录", -1, "用户登录", "用户登录", 12, "Login", "", mainItemID1, menuToolbarOption);
                cmdIndex2 = cmdGroup.AddCommandItem2("上传数模", -1, "上传数模", "上传数模", 0, "Upload", "", mainItemID3, menuToolbarOption);
    
                cmdGroup.HasToolbar = true;
                cmdGroup.HasMenu = true;
                cmdGroup.Activate();
    
                bool bResult;
    
                foreach (int type in docTypes)
                {
                    CommandTab cmdTab;
    
                    cmdTab = iCmdMgr.GetCommandTab(type, Title);
    
                    //如果选项卡存在,但是我们忽略了注册表信息(或更改了命令组ID),那么重新创建选项卡.否则id将不匹配,标签将是空白的
                    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;
                    }
    
                    //如果cmdTab为空,必须首先加载(可能在重置之后),将命令添加到选项卡
                    //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(cmdIndex1);
    
                        TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
    
    
                        cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex0);
    
                        TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
    
    
                        cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex2);
    
                        TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
    
                        bResult = cmdBox.AddCommands(cmdIDs, TextType);
                    }
                }
                thisAssembly = null;
            }