Creating a Web Page | Using Embedded Scripts to Control the Status Bar | Commanding STK with the STK Object Model

HTML Interface

One simple way to extend the STK User Interface is to write HTML pages and load them in the STK internal HTML viewer. The advantage of this method is its relative simplicity. No development environment is required. You can just create an HTML page with any text editor. However the integration with the STK user interface is limited and the user is required to navigate manually to the correct HTML page. Custom HTML pages loaded in STK can access the application object model using the "window.external" property exposed by the web control. That property returns an object of type IAgUiApplication from the AgUiApplication library. That interface exposes methods and properties enabling to manipulate the application windows and toolbars, and also to access the object model in order to manipulate the STK objects in your scenarios.

The HTML Interface enables you to:

HTML interfaces control STK by using the STK Object Model.

Creating a Web Page

You can interact with STK over the COM interface using customized Web pages that you create.

You can create your own home page with links to other pages that you use frequently. You can also put buttons on your home page to send commands to STK. You can even put text fields and other controls on your home page that allow you to enter data that can be used in commands sent to STK. This capability allows you to build a home page that makes it easy for you to do your common tasks, including those that run STK. To do this, you will need to write your own home page in HTML.

To display the HTML Viewer window, select HTML Viewer from the View menu. The HTML Viewer is actually using an embedded version of Microsoft's Web browser, "Internet Explorer" to display these pages.

You can create and edit HTML files using any text editor, such as NotePad or TextPad (by Helios Software Solutions). There are also more sophisticated programs that allow you to create HTML pages, such as MacroMedia's HomeSite, Microsoft's FrontPage and Word, Netscape's Composer, and W3C's Amaya. However, if this is your first time writing HTML, you may want to stick to a simple text editor to get going.

Note: Issuing a SetUnits Connect command from an HTML page will change the units for the STK session.

Using Embedded Scripts to Control STK from an HTML Page

To command STK from an HTML page, you will need to do two things:

Buttons can be added using an <INPUT> tag.

Embedded scripts can be written in several languages, depending on how your computer is configured. The most common are VBScript and JScript, which are supported by the Windows operating systems. (Note that although VBScript is similar to Visual Basic, it is a different language. Likewise, JScript is not the same as Java.) Other languages are also available. For instance, if you have installed Active State's PERL on your computer, you can configure your system to allow PerlScript (the scripting version of PERL) to be embedded in the HTML.

Here is a simple example of an HTML page with a button that creates a new scenario when clicked:


<TITLE>Custom HTML page</TITLE>

<script language="vbscript">
Dim uiApp
Dim stkRoot

Sub InitPage
    ' The window.external property returns
    ' the IAgUiApplication interface
    Set uiApp = window.external

    ' Access the IAgStkObjectRoot interface
    ' from the object model
    Set stkRoot = uiApp.Personality2
End Sub

Sub CreateNewScen()
    ' Creates a new scenario using the
    ' NewScenario method of the IAgStkObjectRoot
    ' interface
End Sub

Sub UnloadScenario()
    on error resume next
    Set notUsed = stkRoot.CloseScenario()
End Sub

Sub UnLoadPage()
    ' Clean-up
    Set uiApp = Nothing
    Set stkRoot = Nothing
End Sub
' -->

<BODY onLoad="InitPage()" onUnload="UnLoadPage()">

<INPUT type="button" align="Center" value="New Scenario" onClick="CreateNewScen()">
<INPUT type="button" align="Center" value="Close Scenario" onClick="UnloadScenario()">


Display the page in a Web browser. Notice that the VBScript is found in the SCRIPT section. The buttons are added in the BODY using the <INPUT> tag. The <BR> tag is a line break.

In the <BODY> tag itself, one of the VBScript subroutines is assigned to run when the HTML page is first loaded (onLoad="InitPage()"), and another to run when the page is removed (onUnload="UnLoadPage()"). In a similar fashion, the buttons in the <INPUT> tag assign subroutines to be run when they are clicked with the mouse (onClick="CreatNewScen()").

Using Embedded Scripts to Control the Status Bar

You can use two window properties, status and defaultStatus, to display custom messages in the status bar. For example, to display a custom message after preferences have been updated, you set the defaultStatus. For example,

defaultStatus = "File preferences have been updated"

You can also set status in the onMouseOver event handler of a hyperlink to display hints in the status bar. The event handler must return true to set status. For example, use the following code to display Click to Explore STK in the status bar when you move the mouse over the link:

<A HREF="explore.html" onMouseOver="javascript:window.status='Click to Explore STK'; return true">Explore STK<A>

Commanding STK with the STK Object Model

The VBScripts command STK using Component Object Model (COM) automation. The example HTML page above is using STK as an automation server. Automation is a protocol that allows one application or component (the Client) to control another application or component (the Server).

In order to control STK you must have a variable that represents STK as an object. This is a two-step process done in the HTML example with the following statements:

Dim uiApp
Dim stkRoot

Set uiApp = window.external
Set stkRoot = uiApp.Personality2

The Dim statements create variables that are used subsequently to represent the objects.

There is one object already available to your scripts if the HTML window is displayed from within STK. This is the 'window' object. The window object has a property called 'external'. STK sets the 'external' property of the HTML windows that it displays to be equal to the 'AGI Application User Interface Object'.

The first step above sets a variable (uiApp) to represent the 'AGI Application User Interface Object' by getting it from the 'external' property of the window object (Set uiApp = window.external).

The second step is to set a variable (stkRoot) to represent the STK Object Model Root by getting it from the 'Personality2' property of the uiApp object (Set stkRoot = uiApp.Personality2). Now with the STK Object Model Root, you can use many of its methods to control STK via connect commands or STK Object Model object oriented method calls.

The STK Object Model Root has a method called ExecuteCommand(). This method can be used to send commands using standard Connect syntax. For instance instead of calling the "NewScenario" method in the above example, one could use the following connect command ...

Set notUsed = stkRoot.ExecuteCommand("new / Scenario MyNewScenario")

... which sends the Connect command to create a new scenario named "Demo". Likewise, instead of the "CloseScenario" method call seen in the above sample, one could issue the following connect command...

Set notUsed = stkRoot.ExecuteCommand("unload / */")

...which sends the command to unload a scenario from STK.

The simple examples in this document have demonstrated that you can create new HTML pages containing buttons on which you can click with a mouse. You can associate embedded scripts with these buttons, and the scripts can use the STK Object Model or send Connect commands to STK. It's also shown how to set any HTML page your default Home Page using STK's menu system.

STK's embedded HTML pages can be used to create custom interfaces for you to automate common and routine tasks. This can save time and reduce the risk of errors. We encourage you to try this new capability by going through the examples and modifying them to your specific needs.

Related Topics:

STK 11.2.1 Programming Interface