Scripting for Objects

There are a number of functions in the Ansys Orbit Determination Tool Kit (ODTK®) application to manage the scenario and objects in the scenario. See the sections below for example uses. For a complete list of functions, see Application Scope Functions.

Creating ODTK objects

You can create new objects with the CreateObj function. It takes three parameters: the parent object of the new object, the type of object to create, and the name of the new object. This function returns a handle to the new object.

Internal names used by the Automation Interface itself, such as "Name", "Class", "Count", "Item", "ItemExists", "ItemByName", and "GetProp", as well as class names of the object families such as "Satellite", "Filter", and "Smoother", are illegal names for ODTK objects and could cause issues.

Here are some sample scripts for creating objects:

COM

Cross-Platform API

Deleting ODTK objects

The DeleteObject function takes an object handle and returns a success status.

Here are some sample scripts for deleting objects:

COM

Cross-Platform API

Saving ODTK objects

You can save the scenario or any object to a file with the SaveObj function. It takes three parameters: the object handle, the destination file name, and the boolean SaveObjectChildren flag.

Here are some sample scripts for saving objects:

COM

Cross-Platform API

Loading ODTK objects

Only one scenario at a time is allowed; unload the current scenario before loading the next one.

To load an object at a later time, use the LoadObj function. Its parameters are the path of the parent object, where the new object is to be loaded, and the source file name containing the object to be loaded. You can load Satellite and Facility objects that are produced by either the ODTK application or the Systems Tool Kit® (STK®) application.

Here are some sample scripts for loading objects:

COM

Cross-Platform API

Testing to see if an ODTK object exists

The scripting interface supports an ItemExists() method to test if an object exists.

Consider the below script which accesses an ODTK scenario with Facilities named "02", "03", and "AA".

Example JavaScript:

Copy
// Obtain the list of Facilities in the Tracking System in the Scenario
let facilities = ODTK.Scenario(0).TrackingSystem(0).Children.Facility;

// The Item() function looks up items by index if the parameter can be interpreted as an index.
// If the parameter cannot be interpreted as an index, it will interpret the parameter as the string name of the item.
alert(facilities.Item(0).Name.value());     // Displays '02'
alert(facilities.Item("00").Name.value());  // Displays '02'
alert(facilities.Item("01").Name.value());  // Displays '03'
alert(facilities.Item("02").Name.value());  // Displays 'AA'
alert(facilities.Item("AA").Name.value());  // Displays 'AA'

// Examples that throw 'Index Out of Range' errors.
try {
    facilities.Item("03").Name.value();
} catch (error) {
    alert(error); // Displays 'Error: Index Out of Range'
}
try {
    facilities.Item("07").Name.value();
} catch (error) {
    alert(error); // Displays 'Error: Index Out of Range'
}

// The ItemExists() function looks up items by string name only.
alert(facilities.ItemExists("01")); // Displays 'false'
alert(facilities.ItemExists("02")); // Displays 'true'
alert(facilities.ItemExists("AA")); // Displays 'true'

// The ItemByName() function follows the same policy as Item(). See comment above for information.
alert(facilities.ItemByName(0).Name.value());     // Displays '02'
alert(facilities.ItemByName("00").Name.value());  // Displays '02'
alert(facilities.ItemByName("01").Name.value());  // Displays '03'
alert(facilities.ItemByName("02").Name.value());  // Displays 'AA'
alert(facilities.ItemByName("AA").Name.value());  // Displays 'AA'

// Examples that throw 'Index Out of Range' errors.
try {
    facilities.ItemByName("03").Name.value();
} catch (error) {
    alert(error); // Displays 'Error: Index Out of Range'
}
try {
    facilities.ItemByName("07").Name.value();
} catch (error) {
    alert(error); // Displays 'Error: Index Out of Range'
}

Cross-Platform API