예제 #1
0
        /*
         * 实现添加窗口的接口以便添加Command时可以调用,转发到SwAddin实现开实现委托方法
         */

        public int AddSWCommand(ICommandGroup cmdGroup, string guid, string name, int postion, string hint, string tooltip, int imageListIndex, int commandIndex, int menuOption)
        {
            var cmdCallbackFunc = $"{callbackMethodName}({guid})";
            var cmdEnableFunc   = $"{enableMethodName}({guid})";

            return(cmdGroup.AddCommandItem2(name, postion, hint, tooltip,
                                            imageListIndex, cmdCallbackFunc, cmdEnableFunc, commandIndex, menuOption));
        }
        private void SetupUI()
        {
            int errors = 0;
            // gather up the icons
            string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
            // create command group
            ICommandGroup commandGroup = _cmdMgr.CreateCommandGroup2(_mainCmdGrpId, "Custom Addin", "My custom add-in", "", -1, true, ref errors);

            // set the icon lists
            commandGroup.IconList     = new string[] { System.IO.Path.Combine(folder, "Icons", "icons.bmp") };
            commandGroup.MainIconList = new string[] { System.IO.Path.Combine(folder, "Icons", "icons.bmp") };

            // add the commands to the command group
            // this is just an example for demo purposes***
            List <int> commandItems = new List <int>();

            for (int i = 0; i < 10; i++)
            {
                // you wouldn't add your commands like this.
                // you would obviously create them one at a time
                // for example, in this demo, we're adding 10 commands, but they all call the same method ExucuteAction... that would be a dumb addin
                commandItems.Add(commandGroup.AddCommandItem2("Action " + i, -1, "Action " + i, "Action " + i, i, "ExecuteAction", "CanExecuteAction", _menuItemId1 + i, (int)swCommandItemType_e.swMenuItem | (int)swCommandItemType_e.swToolbarItem));
            }

            // activate command group
            commandGroup.HasToolbar = true;
            commandGroup.HasMenu    = true;
            commandGroup.Activate();

            // create the command tab
            foreach (int docType in new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocPART, (int)swDocumentTypes_e.swDocDRAWING })
            {
                ICommandTab commandTab = _cmdMgr.GetCommandTab(docType, "Custom Addin");

                if (commandTab != null)
                {
                    // recreate the command tab
                    _cmdMgr.RemoveCommandTab((CommandTab)commandTab);
                    commandTab = null;
                }

                // add the command tab
                commandTab = _cmdMgr.AddCommandTab(docType, "Custom Addin");
                // create a command box
                ICommandTabBox commandTabBox = commandTab.AddCommandTabBox();
                // add commands to command tab
                List <int> cmds      = new List <int>();
                List <int> textTypes = new List <int>();
                foreach (var cmdItem in commandItems)
                {
                    cmds.Add(commandGroup.CommandID[cmdItem]);
                    textTypes.Add((int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow);
                }
                bool result = commandTabBox.AddCommands(cmds.ToArray(), textTypes.ToArray());

                commandTab.AddSeparator((CommandTabBox)commandTabBox, cmds.First());
            }
        }
예제 #3
0
        public void AddCommandMgr()
        {
            if (iBmp == null)
            {
                iBmp = new BitmapHandler();
            }
            Assembly thisAssembly;
            int      cmdIndex0, cmdIndex1;
            string   Title = "CAPP 插件", ToolTip = "CAPP 插件";


            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[1] {
                mainItemID1
            };                                          // 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("Kingdee.CAPP.Solidworks.RoutingPlugIn.ToolbarLarge.bmp", thisAssembly);
            cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.ToolbarSmall.bmp", thisAssembly);
            cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.MainIconLarge.bmp", thisAssembly);
            cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.MainIconSmall.bmp", thisAssembly);

            int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);

            //增加菜单
            cmdIndex0 = cmdGroup.AddCommandItem2("关联零件到工艺路线", -1, "关联零件到工艺路线", "关联零件到工艺路线", 0, "Routing", "EnableRouting", mainItemID1, menuToolbarOption);
            cmdIndex1 = cmdGroup.AddCommandItem2("关联草图到工序", -1, "关联草图到工序", "关联草图到工序", 0, "SketchToProcess", "EnableRouting", mainItemID2, menuToolbarOption);
            //cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption);
            //cmdIndex1 = cmdGroup.AddCommandItem2("WinFormInFeatureMgr", -1, "Add Windows Form In FeatureManager", "WinFormInFeatureMgr", 2, "WinFormInFeatureMgr", "", mainItemID1, 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_TextHorizontal;

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

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

                    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;
        }
예제 #4
0
        private IDisposable AddCommands()
        {
            const int mainCmdGroupId = 5;
            const int mainItemId1    = 0;
            const int mainItemId2    = 1;

            const string title   = "C# Addin";
            const string toolTip = "C# Addin";

            int[] docTypes = { (int)swDocumentTypes_e.swDocPART };

            var cmdGroupErr    = 0;
            var ignorePrevious = false;

            object registryIDs;
            //get the ID information stored in the registry
            var getDataResult = CommandManager.GetGroupDataFromRegistry(mainCmdGroupId, out registryIDs);

            int[] knownIDs = { mainItemId1, mainItemId2 };

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

            ICommandGroup cmdGroup = CommandManager.CreateCommandGroup2(mainCmdGroupId, title, toolTip, "", -1, ignorePrevious,
                                                                        ref cmdGroupErr);

            cmdGroup.LargeIconList = GetBitMap("SwCSharpAddinMF.Icons.ToolbarLarge.bmp");
            cmdGroup.SmallIconList = GetBitMap("SwCSharpAddinMF.Icons.ToolbarSmall.bmp");
            cmdGroup.LargeMainIcon = GetBitMap("SwCSharpAddinMF.Icons.MainIconLarge.bmp");
            cmdGroup.SmallMainIcon = GetBitMap("SwCSharpAddinMF.Icons.MainIconSmall.bmp");

            var menuToolbarOption = (int)swCommandItemType_e.swToolbarItem | (int)swCommandItemType_e.swMenuItem;
            var cmdIndex0         = cmdGroup.AddCommandItem2(nameof(CreateSampleMacroFeature), -1, "Alpha Split", "Alpha Split", 0,
                                                             nameof(CreateSampleMacroFeature), "", mainItemId1, menuToolbarOption);
            var cmdIndex1 = cmdGroup.AddCommandItem2(nameof(CreateManipulatorSample), -1, "Manipulator", "Manipulator", 0,
                                                     nameof(CreateManipulatorSample), "", mainItemId1, menuToolbarOption);

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


            foreach (var type in docTypes)
            {
                var cmdTab = CommandManager.GetCommandTab(type, title);

                // 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
                if (cmdTab != null & !getDataResult | ignorePrevious)
                {
                    CommandManager.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 = CommandManager.AddCommandTab(type, title);

                    var cmdBox = cmdTab.AddCommandTabBox();

                    var cmdIDs = new[] { cmdIndex0, cmdIndex1 }
                    .Select(id => cmdGroup.CommandID[id])
                    .ToArray();

                    var textType = cmdIDs
                                   .Select(id => (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal)
                                   .ToArray();


                    cmdBox.AddCommands(cmdIDs, textType);
                }
            }

            return(Disposable.Create(() => CommandManager.RemoveCommandGroup(mainCmdGroupId)));
        }
예제 #5
0
        /// <summary>
        /// The add command mgr.
        /// </summary>
        public void AddCommandMgr()
        {
            if (this.iBmp == null)
            {
                this.iBmp = new BitmapHandler();
            }

            const string Title   = "Save PDF";
            const string ToolTip = "Save PDF";

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

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

            int  cmdGroupErr    = 0;
            bool ignorePrevious = false;

            object registryIDs;

            // get the ID information stored in the registry
            bool getDataResult = this.CmdMgr.GetGroupDataFromRegistry(MainCmdGroupId, out registryIDs);

            int[] knownIDs = { MainItemId1 };

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

            ICommandGroup cmdGroup = this.CmdMgr.CreateCommandGroup2(
                MainCmdGroupId,
                Title,
                ToolTip,
                "",
                -1,
                ignorePrevious,
                ref cmdGroupErr);

            cmdGroup.LargeIconList = this.iBmp.CreateFileFromResourceBitmap("SavePDF.ToolbarLarge.bmp", thisAssembly);
            cmdGroup.SmallIconList = this.iBmp.CreateFileFromResourceBitmap("SavePDF.ToolbarSmall.bmp", thisAssembly);

            const int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);

            int cmdIndex0 = cmdGroup.AddCommandItem2(
                "Save PDF",
                -1,
                "Save PDF Options",
                "Save PDF Options",
                0,
                "ShowPMP",
                "EnablePMP",
                MainItemId1,
                menuToolbarOption);

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

            foreach (int type in docTypes)
            {
                CommandTab cmdTab = this.CmdMgr.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 = this.CmdMgr.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 = this.CmdMgr.AddCommandTab(type, Title);

                    CommandTabBox cmdBox = cmdTab.AddCommandTabBox();

                    var cmdIDs   = new int[1];
                    var textType = new int[1];

                    cmdIDs[0] = cmdGroup.CommandID[cmdIndex0];

                    textType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal;

                    cmdBox.AddCommands(cmdIDs, textType);
                }
            }

            thisAssembly = null;
        }