Пример #1
0
        /// <summary>
        ///
        /// Command Manager example
        /// http://help.solidworks.com/2012/English/api/sldworksapi/Create_Flyouts_in_the_CommandManager_Example_CSharp.htm
        ///
        /// Adding menus and toolbars
        /// http://www.angelsix.com/cms/products/tutorials/64-solidworks/74-solidworks-menus-a-toolbars
        ///
        /// Defining dynamic methods
        /// http://msdn.microsoft.com/en-us/library/exczf7b9(v=vs.100).aspx
        /// </summary>
        private void UISetup()
        {
            config_info = new ConfigInfo(config_path);
            plugin_info = config_info.list();

            plugin_icon_img_path = Path.GetFullPath(Path.Combine(working_dir(), "IconSprite.bmp"));

            try
            {
                callback_handler = (new PluginCall(config_info, this)).callback_container;
                mSWApplication.SetAddinCallbackInfo(0, (object)callback_handler, mSWCookie);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message + "\n" + e.StackTrace);
            }

            bool commands_added = add_commands();

            ThreadPool.QueueUserWorkItem((x) =>
            {
                System.Net.Sockets.Socket s = PluginCall.run_host(config_info.host_info()["proc_name"], config_info.host_info()["proc_path"]);
                s.Close();
            });
        }
Пример #2
0
        private bool populate_plugin_commands(CommandGroup group, List <Dictionary <String, String> > plugins)
        {
            // if (plugins_populated) { return false; }
            // All command items to be a menu and toolbar item
            int itemType = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
            int n        = plugins.Count;

            for (int i = 0; i < n; i++)
            {
                String cmd         = plugins[i]["command"];
                String strCallback = "";

                // Special cases List and Exit
                if (cmd.ToUpper() == "EXIT")
                {
                    strCallback = "call_exit";
                }
                else if (cmd == "")
                {
                    strCallback = "call_list";
                }
                else
                {
                    strCallback = PluginCall.prefixed_callback(plugins[i]["command"]);
                }
                plugin_count_id++;
                strCallback = PluginCall.prefixed_callback(plugins[i]["command"]);

                group.AddCommandItem2(plugins[i]["name"], (i + 1), plugins[i]["hint"], plugins[i]["tooltip"],
                                      Convert.ToInt16(plugins[i]["icon_index"]), strCallback, "enable_plugin", Convert.ToInt16(plugins[i]["id"]), itemType);
            }
            return(true);
        }