In this article:
What are Script Messages
A script message is a JavaScript code using TerraExplorer API that is executed when the TerraExplorer message with this script is activated. A message can be assigned to any object, location, and Project Tree message element. There are two interfaces that can be used in script messages: This80 and SGWorld80.
This80 - This interface represents the ITerraExplorerObject80 derived object that the message is assigned to. For example, for a text label (ITerrainLabel80), you can enter the following script:
<script type = "javascript">
alert("Text position is: " + This80.Position.ToString());
</script>
When the message is activated, a message box is displayed with the position of the text label.
SGWorld80 - This interface exposes the SGWorld interfaces, enabling you to use all ISGWorld properties and methods. For example, the script below loads the specified fly file when the message is activated.
<script type = "javascript">
SGWorld80.Open("c:\\project.fly");
</script>
Note: Older API versions, e.g., This74 & SGWorld74, are also supported, but it is recommended to use the latest versions.
Examples
Note: TerraExplorer must be installed to use the API. Download and install TerraExplorer >
Example #1: Use This80 to extend a circle object radius by 2 meters upon clicking it.
- Start TerraExplorer and open this project FLY file.
Note: The examples below are included in the project FLY file. - On the Objects tab, click 2D Shape, and select Circle
- In the 3D Window, click to define the center of the circle, and then drag the mouse to set its radius. Click again to finish.
- In the circle's properties sheet, in the Appearance group, set the Fill Opacity to 100%.
- In the circle's properties sheet, in the General group, click the Edit button in the Message property field.
- In the Create Message dialog, change the Type to Script.
- in the Script field, add the following script:
<script type = "javascript">
This80.Radius += 2;
</script> - Close the circle's properties sheet and then double-click the newly created object to fly to it.
- In the 3D Window, click the circle to run the script message.
Example #2: Use the SGWorld80 object to create and fly to a location and display a message with the location's coordinates.
- On the Home tab, in the Add group, click Project Tree and then select Create Tree Message.
- In the Create Message dialog, change the Type to Script.
- In the Script field, add the following script, and click OK:
<script type = "javascript">
var pos = SGWorld80.Creator.CreatePosition(-90.30242419, 38.64905961, 99, 0, 240.50, -22.80718, 0, 10);
alert(pos.ToString());
SGWorld80.Navigate.FlyTo(pos);
</script> - In the Project Tree, double click the message entry to display a message with the location’s coordinate information (X, Y, Altitude), orientation properties (Yaw, Pitch, Roll) and distance from which to observe the point of interest, and fly to the location.
Script message video tutorial >
More about: TerraExplorer's interfaces >