Scripting Compound Attribute Types

The Ansys Orbit Determination Tool Kit (ODTK®) application uses several compound types that have special methods for handling units, dimensions, date representations, and coordinate system transformations. Types also include standard containers such as lists and sets.

This topic provides short descriptions and application-related code examples (COM and Cross-platform API) for the following compound types:

Type QUANTITY

Type DATE

Type LINKTO

Type LINKTO ENUMERATION

Type LIST

Type SETLINKTOOBJ

Type SET

Type QUANTITY

Quantities are values that have an associated unit, such as 1 second, 5 kilometers, and 3 radians/second. Several methods and properties are available to work with the quantity attributes.

The properties "Unit" and "Dimension" return the default unit and dimension.

COM

Cross-Platform API

 

The methods GetIn() and Set() perform unit conversion based on the input unit.

COM

Cross-Platform API

 

Even though the following will work, it is unsafe to assume the default unit.

COM

 

You can also get the internal value with the function GetInternal, which is likely to be in different units than the default input/output units. Internal units may change from version to version, so you should avoid using this function.

In addition to working with one of the scenario object quantities, you can create a new quantity object with the ODTK.NewQuantity() function. You can either assign the returned quantity object to one of the existing attributes or use it to perform a unit conversion.

COM

When using VBScript, it is very important to use the "set" keyword when saving return values from the NewQuantity function. Using "set" ensures that you save a handle to the Quantity object. Without the "set" keyword, VBScript will retrieve the CDbl value of the Quantity value.

Copy
X = ODTK.NewQuantity(100,"mi/hr")
MsgBox x.GetIn("km/sec") ' This generates a run-time error: x is CDbl

Cross-Platform API

Type DATE

Dates are treated similarly to Quantities. They have a Set() method to assign a value and a Format() method to retrieve the DateTime string in a specified format. To see available date formats, click the icon while editing any Date field. You can create a new Date object using the ODTK.NewDate() function. The first parameter is the value or string containing the date, and the second parameter is one of the standard ODTK date formats.

COM

Cross-Platform API

 

As with the Quantity object, make sure to use the "set" with VBScript or you will get an undefined behavior.

The Set() function returns a handle to the Date object that is being modified. The input parameters are the same as the NewDate function.

COM

Cross-Platform API

 

The ODTK Date object also implements three Date Time arithmetic methods: AddTime, SubtractTime, and SubtractDate.

COM

Cross-Platform API

In addition to arithmetic functions, these functions allow date comparison:

  • Equals()

  • GreaterThan()

  • GreaterThanOrEqual()

  • Inequality()

  • LessThan()

  • LessThanOrEqual()

They return a Boolean, and you can use them to test dates as follows:

COM

Cross-Platform API

 

Date objects are often useful when converting date and time formats from other software or systems. You can use the ODTK application as a date conversion utility, even when the input format is not one that the ODTK application natively supports. You can often reorganize the input date and time into something that the ODTK application can handle. For example, you may have a date and time format that consists of the year and the elapsed seconds since the beginning of the year, assumed to be 1 Jan 00:00:00 UTC. Consider the date and time given as 2009/2560004. You could rely on your own date conversion routines and worry about leap years and leap seconds. Or you could simply pass it into the ODTK application using something like the following and then request it back out in a different format.

COM

Cross-Platform API

This trick of using the hour, minute, or second field and putting any value you want in it is perfectly acceptable.

Type LINKTO

File and directory names are strings, but they are validated during the assignment. The application makes sure that an input file exists, or an output file can be written. Otherwise, it will generate an error and the new value will not be set.

Examples of setting values are as follows:

COM

Cross-Platform API

The following are examples of getting values for a filename:

COM

Cross-Platform API

Type LINKTO ENUMERATION

Some objects have links to enumerated types, such as the solar radiation pressure model or measurement bias model, and are identified as having type "LINKTO ENUMERATION". These parameters have an extra attribute "Type" that you can use to set and get their values.

There are some unique Multiple Representation attributes that combine enumeration behavior for reading attributes, but use object-like scope for assigning attributes. See these special cases (e.g., Satellite.OrbitState and Facility.Position) in the Scripting Multiple Representations section.

COM

Cross-Platform API

Type LIST

The List container holds an unordered list of simple types like STRINGs or INTs or compound objects. The easiest way to identify which types of objects are in a list is to add an element through the user interface. The columns in the list identify the names of each of the properties of the elements.

Use the NewElem() method to create a new object to add to the list. Add it to the list by using push_back(ne) or push_front(ne). You can clear the entire list using clear(), and you can remove the ith element using RemoveAt(i). Obtain the number of elements in the list by using size for COM and size.eval() or count for Cross-platform API. Access the elements in the list by index number or by iterating through the list.

COM

Cross-Platform API

Type SETLINKTOOBJ

Some ODTK objects have a special container SetLinkToObj that acts like a Set. It can only contain unique items, and the unique items are links to other ODTK objects. A common example of this is a Filter object's SatelliteList. You can choose to add specific satellite objects into the SatelliteList, but you can only add the satellite once. Use the InsertbyName() method to add a new object into the list. Alternatively, you can retrieve the list in your script via the Choices property. You can clear the entire SetLinkToObj using clear() and remove an individual element using erase(). Obtain the number of elements in the SetLinkToObj by using size for COM and size.eval() or count for Cross-platform API. Access the elements in the SetLinkToObj by index number or by iterating through the SetLinkToObj. The methods begin() and end() return iterators that have the following methods: IsSafeToDereference(), Dereference(), Increment(), and Decrement().

There are some unique Multiple Representation attributes that combine enumeration behavior for reading attributes, but use object-like scope for assigning attributes. See these special cases (e.g., Satellite.OrbitState and Facility.Position) in the Scripting Multiple Representations section

COM

Cross-Platform API

Type SET

The Set container is similar to a list but is ordered by an internal constraint and will reject duplicates. The following functions are supported:

Function Description
NewElem() Creates a new element to add to the set.
insert(element) Adds a newly created element to the set.
clear()

Clears the entire set.

erase(element) Removes an individual element from the set.
size Obtains the number of elements in the set for COM.
size.eval() or count

Obtains the number of elements in the set for Cross-Platform API.

begin()

Returns an iterator pointing to the first item of the set.

The iterator has the following methods: IsSafeToDereference(), Dereference(), Increment(), and Decrement().

end()

Returns an iterator pointing to the end of the set (past the last item).

The iterator has the following methods: IsSafeToDereference(), Dereference(), Increment(), and Decrement().

Access the elements in the set by index number or by iterating through the set. Some sets have additional methods that are useful:

Function Description
InsertByName(string)

Returns a boolean indicating whether the element was successfully added.

FindByName(string)

Returns an iterator pointing to the specified item in the set.

The iterator has the following methods: IsSafeToDereference(), Dereference(), Increment(), and Decrement().

RemoveByName(string)

Returns a boolean indicating whether the element was successfully removed.

COM

Cross-Platform API

In addition to the unlimited sets, there are predefined sets (SET ENUMERATION) and sets of the objects (SET LINKTOOBJ). For some sets, insert() and erase() accept either an object name or the handle. However, you have to check that each works for a particular set.