How to create scripts with Visual Studio Express

Some users use scripts very often. The scripting tool has a good highlighting and is easy to use for small scripts and changes of scripts.
For users who want to create big scripts with many classes it is better to develop in visual studio.

You can download the free express version from microsoft under https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx. It's important to download the desktop version to open our example.

You find our example code to create a script in visual studio download here: Downlad C Sharp Code

We have added two references to the project.
First PCB-Investigator-Demo from the standard installation directory.
Than PCB-Investigator-Scripting.dll from the PlugIn subdirectory.


Add Reference to VS2010

At the end after developing your script with all comfort of visual studio you can import the class ScriptExample.cs in to your scripting tool or copy the code in an empty script.

Here is the main exampe class:

//Synchronous template
//-----------------------------------------------------------------------------------
// PCB-Investigator Automation Script
// Created on 25.03.2015
// Autor easylogix
//
// Template to show windows form for synchronous script.
//-----------------------------------------------------------------------------------
 
using System;
using System.Collections.Generic;
using System.Text;
using PCBI.Plugin;
using PCBI.Plugin.Interfaces;
using System.Windows.Forms;
using System.Drawing;
using PCBI.Automation;
using System.IO;
using System.Drawing.Drawing2D;
using PCBI.MathUtils;
 
namespace PCBIScript
{
  public class PScript : IPCBIScript
  {
    public PScript()
    {
    }
 
    public void Execute(IPCBIWindow parent)
    {
      //your code here
      FormExampleForScript myExampleForm = new FormExampleForScript();
      if (myExampleForm.ShowDialog() != DialogResult.OK) return;
 
      bool myOptionA = myExampleForm.OptionA;
 
      if (myOptionA)
        MessageBox.Show("User has selected option A!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
      else
        MessageBox.Show("User has unselected option A!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
 
      parent.UpdateView();
    }
 
    #region use form in script
    public class FormExampleForScript : Form
    {
      public FormExampleForScript()
      {
        InitializeComponent();
      }
      public bool OptionA
      {
        get { return checkBox1.Checked; }
      }
 
      private void button1_Click(object sender, EventArgs e)
      {
        this.DialogResult = System.Windows.Forms.DialogResult.OK;
        this.Close();
      }
 
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.IContainer components = null;
 
      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
      protected override void Dispose(bool disposing)
      {
        if (disposing && (components != null))
        {
          components.Dispose();
        }
        base.Dispose(disposing);
      }
 
      #region Windows Form Designer generated code
 
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
        this.button1 = new System.Windows.Forms.Button();
        this.checkBox1 = new System.Windows.Forms.CheckBox();
        this.SuspendLayout();
        //
        // button1
        //
        this.button1.Location = new System.Drawing.Point(234, 9);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 0;
        this.button1.Text = "OK";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        //
        // checkBox1
        //
        this.checkBox1.AutoSize = true;
        this.checkBox1.Location = new System.Drawing.Point(12, 13);
        this.checkBox1.Name = "checkBox1";
        this.checkBox1.Size = new System.Drawing.Size(86, 17);
        this.checkBox1.TabIndex = 1;
        this.checkBox1.Text = "Set Option A";
        this.checkBox1.UseVisualStyleBackColor = true;
        //
        // FormExampleForScript
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(321, 44);
        this.Controls.Add(this.checkBox1);
        this.Controls.Add(this.button1);
        this.Name = "FormExampleForScript";
        this.Text = "FormExampleForScript";
        this.ResumeLayout(false);
        this.PerformLayout();
 
      }
 
      #endregion
 
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.CheckBox checkBox1;
    }
 
    #endregion
  }
}