Visual Studio UI Plugin Template

This template enables developers to build an STK UI Plugin quickly by setting up a properly configured, blank plugin. The template includes several useful code sample and libraries:

  • Examples for adding a progress bar, a link to the plugin from the context menu, a link to the plugin from the main menu, and a link to the plugin from the toolbar
  • An example of a persistent preference page, which keeps user selections even after STK is closed
  • The STK code library, which is used for interacting with STK and manipulating STK objects, including simple methods to subscribe to events in STK and get a list of objects in an STK scenario
  • Globe mouse events code that are commented out

To use the template to build a UI Plugin, follow the instructions below.

Copy the templates

Copy the following zip files to your Visual Studio user folder (<user area>Visual Studio<version number>Templates\ProjectTemplates\Visual C#):

Template used for creating UI plugin
<stk install folder>/CodeSamples/CodeSamples/Extend/Ui.Plugins/Visual Studio Templates/STK13.UiPlugin.Template.zip

Template used for copying binaries and creating XML file
<stk install folder>/Codesamples/Codesamples/Extend/Ui.Plugins/Visual Studio Templates/STK13.UiPlugin.Copier.zip

Do not unzip these files.

Create a new Visual Studio project

Launch Visual Studio and follow these instructions:

  1. Create a new project; the New Project dialog box will appear.
  2. If you are using Visual Studio 2019, do not filter or search for templates. Scroll to the bottom of this list and select the STK13.UIPlugin.Template, and then skip to Step 4.

  3. In the left pane of the dialog box, select Visual C# under templates.
  4. In the right pane, select STK13.UIPlugin.Template.
  5. Enter a unique name for your project. If the name is not unique, your plugin will be in conflict with other UI plugins that have the same name.
  6. Click OK.

Build and deploy your project

  1. Open Setup.cs in the Visual Studio editor.
  2. Highlight and copy your namespace. Also take note of the name of your public class. In the example above, STK13.UiPlugin.Demo is the name space and Setup is the public class.
  3. Right-click your solution and add a new project.
  4. Select STK13.UiPlugin.Copier and give a unique name to the project.
  5. Right-click the project name in the Solution Explorer and select Set as StartUp Project.
  6. Build and run the solution in Debug mode. You will be presented with following dialog box:
  7. Click the ellipsis button and select the output folder for your plugin. Enter the following:

    Display Name. The external name of your plugin.

    Assembly Name. The namespace for your plugin. (If you forgot it, see Build your Project above.)

    Type Name. The entry point for the plugin. In this example, it is the full path to the Setup class (namespace + “.Setup”).

  8. Click Run Setup, click Done, and then close the Setup window.
  9. From the Build menu, select Configuration Manager and switch the configuration from Debug to Release.
  10. Build the copier project.
  11. Open Windows Explorer and go to the release folder of the copier project.
  12. You can either copy the first two files (exe and config) and give them to your customers, or run the exe yourself to install the plugin on your computer. If you run the exe, you will get following dialog:
  13. Click Install, click the OK button, and Close the dialog when finished.
  14. The plugin is now installed on your computer.

Debugging your plugin

The plugin is now available in STK, but most of its features are commented out. If you want to debug the plugin, you need to point your manifest file, which was created by the copier, to your debug binary folder. Here are instructions for setting up the plugin for debugging:

  1. In Windows Explorer, go to the debug folder for the plugin and copy path.
  2. Go to your manifest file (C:\ProgramData\AGI\STK 13\Plugins).
  3. Open the XML file in the text editor of your choice and change the code path to your debug folder:
  4. <?xml version = "1.0"?>

    <AGIRegistry version = "1.0">

    <CategoryRegistry>

    <Category Name = "UiPlugins">

    <NETUiPlugin

    DisplayName="Demo plugin"

    TypeName="Stk13.UiPlugin.Demo.Setup"

    AssemblyName="Stk13.UiPlugin.Demo"

    CodeBase="D:\MyProjects\UIPlugin\Stk13.UiPlugin.Demo\Stk13.UiPlugin.Demo\bin\Debug">

    </NETUiPlugin>

    </Category>

    </CategoryRegistry>

    </AGIRegistry>

  5. Back in Visual Studio, switch the startup project back to the plugin and make sure that the configuration is set to Debug.
  6. Open the plugin project properties and select the Debug tab. Change Start Action to Start External Program and select AgUiApplication.exe in the STK installed bin folder.

Related topics: