{"id":227,"date":"2022-10-10T10:24:38","date_gmt":"2022-10-10T08:24:38","guid":{"rendered":"http:\/\/test.pcbinvestigator.de\/en\/?page_id=227"},"modified":"2022-10-10T13:49:56","modified_gmt":"2022-10-10T11:49:56","slug":"how-to-use-your-script-as-plug-in","status":"publish","type":"page","link":"https:\/\/www.pcb-investigator.com\/en\/support\/help-center\/how-to-instructions\/how-to-use-your-script-as-plug-in\/","title":{"rendered":"How to use your script as plug-in"},"content":{"rendered":"\n<p>Many users create scripts. Sometimes it&#8217;s comfortable to have them in form of a plug-in with a direct button in your menu.<br><br>For this case we have an empty demo project:<br><a href=\"http:\/\/www.easylogix.de\/download\/HowTo\/Demo12ScriptToPlugIn.zip\" target=\"_blank\" rel=\"noopener\">Download C Sharp Code<\/a><br><br><strong>There are two classes in this example code one with the plugin:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ClassPCBIConnection.cs includes all the details PCB-Investigator needs to create and react to the button.<\/li><li>CalssScript.cs has an execute method like all scripts, just put your code and variables in it to change the PCB-Investigator button.<\/li><\/ul>\n\n\n\n<p>After rebuilding your class library it is necessary to copy the dll to your plug-in directory. You find the directory by opening PCB-Investigator, goto options -&gt; Plug-ins.<br>(see image at the end)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class ClassScript\n  {\n    internal string NameOfPlugIn = \"Unique Name of Script PlugIn or GUID\";\n    internal string TextOnButton = \"Start Demo\";\n \n    public void Excecute(IPCBIWindow parent)\n    {\n      parent.UIAction.Execute(ID_ActionItem.ID_JOB_LIBRARY);\n \n      parent.UpdateView();\n    }\n  }\n \n&#91;Plugin(\"RibbonDemo\", \"Demo\", \"Demo to show how to add to PCB-Investigator Ribbon menu.\", \"1.0.0.0\")]\n  public class ClassPCBIConnection: IPluginRibbonCommand\n  {\n \n    #region IPluginToolStrip Members\n    \/\/On which position should the toolbar dock.\n    private ContainerPosition position = ContainerPosition.Left;\n    public ContainerPosition Position\n    {\n      get\n      {\n        return position;\n      }\n      set\n      {\n        position = value;\n      }\n    }\n    #endregion\n \n    #region IPlugin Members\n    \/\/interface information\n    private bool pluginEnabled;\n    public bool PluginEnabled\n    {\n      get\n      {\n        return pluginEnabled;\n      }\n      set\n      {\n        pluginEnabled = value;\n      }\n    }\n    private string assembly;\n    public string Assembly\n    {\n      get\n      {\n        return assembly;\n      }\n      set\n      {\n        assembly = value;\n      }\n    }\n    private string path;\n    public string Path\n    {\n      get\n      {\n        return path;\n      }\n      set\n      {\n        path = Path;\n      }\n    }\n    private Type type;\n    public Type Type\n    {\n      get\n      {\n        return type;\n      }\n      set\n      {\n        type = value;\n      }\n    }\n    IPCBIWindow parent;\n    public IPCBIWindow Parent\n    {\n      get\n      {\n        return parent;\n      }\n      set\n      {\n        parent = value;\n      }\n    }\n    private PluginDestinationWindow pluginDestination = PluginDestinationWindow.MainWindow;\n    public PluginDestinationWindow PluginDestination\n    {\n      get\n      {\n        return pluginDestination;\n      }\n      set\n      {\n        pluginDestination = value;\n      }\n    }\n    public bool IsActionAllowed(ID_ActionItem action)\n    {\n      return false;\n    }\n    public void InitEvents(IPCBIWindow Parent)\n    {\n    }\n    #endregion\n \n    #region ribbon\n    int registerEntryPCBI = -1;\n    \n    public void OnCommandExecute(int cmdID)\n    {\n      if (cmdID == registerEntryPCBI)\n      {\n        try\n        {\n          if(UsedScriptToStart!=null) UsedScriptToStart.Excecute(parent);\n        }\n        catch (Exception exceptionInScript)\n        {\n          \/\/do error handling\n \n        }\n      }\n    }\n \n    public void RegisterCommand()\n    {\n      UsedScriptToStart = new ClassScript();\n \n      registerEntryPCBI = Parent.UIAction.RegisterID(new IRegisterItem()\n      {\n        Category = \"Demo\",\n        EnableOn = Availability.Always,\n        GUID = \"MustBeUnique!_\" + UsedScriptToStart.NameOfPlugIn,\n        RegisterType = RegisterItemType.BUTTON,\n        Text = UsedScriptToStart.TextOnButton\n      });\n \n \n    }\n \n    #endregion\n \n    ClassScript UsedScriptToStart = null;\n  }<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.pcb-investigator.com\/wp-content\/uploads\/2022\/09\/PlugInsDirectory.jpg\" alt=\"\" class=\"wp-image-1170\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Many users create scripts. Sometimes it&#8217;s comfortable to have them in form of a plug-in with a direct button in your menu. For this case we have an empty demo project:Download C Sharp Code There are two classes in this example code one with the plugin: ClassPCBIConnection.cs includes all the details PCB-Investigator needs to create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":246,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-227","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/comments?post=227"}],"version-history":[{"count":1,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/227\/revisions"}],"predecessor-version":[{"id":228,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/227\/revisions\/228"}],"up":[{"embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/246"}],"wp:attachment":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/media?parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/categories?post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/tags?post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}