SOS Classic Mission Planner Script Functions

Script Functions

This document describes the Mission Planner script language functions, return types, and record structures. All units are metres and seconds unless stated otherwise. All positions and velocities are in the ECI (Earth-Centered Inertial) coordinate system unless stated otherwise.

Angle convention: SOS orbital-mechanics functions (CreateOrbitalElements, CreateDeltaV, CreateThrust, etc.) use degrees for all angles (inclination, RAAN, argument of periapsis, true anomaly, delta-V angle). The Math trigonometry functions (Sin, Cos, Tan, Asin, Acos, Atan, Atan2) use radians. Convert between them with: degrees = radians * 180 / Pi and radians = degrees * Pi / 180.


Math Constants

Constant Value Description
E 2.718281828… Euler’s number (base of natural logarithm)
PI 3.141592653… Pi
Tau 6.283185307… Tau (2 * Pi)

Math Functions

All trigonometry functions work in radians, not degrees.

Trigonometric Functions

Function Signature Description
Acos Acos(double d) : double Angle whose cosine is d
Acosh Acosh(double d) : double Inverse hyperbolic cosine of d
Asin Asin(double d) : double Angle whose sine is d
Asinh Asinh(double d) : double Inverse hyperbolic sine of d
Atan Atan(double d) : double Angle whose tangent is d
Atanh Atanh(double d) : double Inverse hyperbolic tangent of d
Atan2 Atan2(double y, double x) : double Angle whose tangent is y/x
Cos Cos(double d) : double Cosine of angle d
Cosh Cosh(double d) : double Hyperbolic cosine of d
Sin Sin(double a) : double Sine of angle a
SinCos SinCos(double x) : (double Sin, double Cos) Sine and cosine of x
Sinh Sinh(double value) : double Hyperbolic sine of value
Tan Tan(double a) : double Tangent of angle a
Tanh Tanh(double value) : double Hyperbolic tangent of value

Rounding and Sign Functions

Function Signature Description
Abs Abs(double value) : double Absolute value
Ceiling Ceiling(double a) : double Smallest integer >= a
Clamp Clamp(double value, double min, double max) : double Clamps value to [min, max]
CopySign CopySign(double x, double y) : double Returns x with the sign of y
Floor Floor(double d) : double Largest integer <= d
Round Round(double a) : double Round to nearest integer
Round Round(double value, int digits) : double Round to n fractional digits
Sign Sign(double value) : int Returns -1, 0, or 1 indicating the sign
Truncate Truncate(double d) : double Integer part of d

Exponential and Logarithmic Functions

Function Signature Description
Cbrt Cbrt(double d) : double Cube root of d
Exp Exp(double d) : double e raised to the power d
Log Log(double d) : double Natural logarithm of d
Log Log(double a, double newBase) : double Logarithm of a in given base
Log2 Log2(double d) : double Base-2 logarithm of d
Log10 Log10(double d) : double Base-10 logarithm of d
Pow Pow(double x, double y) : double x raised to the power y
Sqrt Sqrt(double d) : double Square root of d

Min, Max, and Comparison Functions

Function Signature Description
Max Max(double val1, double val2) : double Larger of two values
MaxMagnitude MaxMagnitude(double x, double y) : double Value with larger absolute value
Min Min(double val1, double val2) : double Smaller of two values
MinMagnitude MinMagnitude(double x, double y) : double Value with smaller absolute value

Other Math Functions

Function Signature Description
BigMul BigMul(long a, long b) : long Full product of two 64-bit integers
BitDecrement BitDecrement(double x) : double Largest value less than x
BitIncrement BitIncrement(double x) : double Smallest value greater than x
DivRem DivRem(int a, int b) : (int Quotient, int Remainder) Quotient and remainder of integer division
FusedMultiplyAdd FusedMultiplyAdd(double x, double y, double z) : double (x * y) + z computed as one operation
IEEERemainder IEEERemainder(double x, double y) : double IEEE remainder of x / y
ILogB ILogB(double x) : int Base-2 integer logarithm of x
ReciprocalEstimate ReciprocalEstimate(double d) : double Estimate of 1/d
ReciprocalSqrtEstimate ReciprocalSqrtEstimate(double d) : double Estimate of 1/sqrt(d)
ScaleB ScaleB(double x, int n) : double x * 2^n

Informational Functions

These functions retrieve information without changing orbits or simulations.

GetEarthInfo

Returns Earth’s basic information. If a date is provided, returns extended information for that date.

GetEarthInfo() : EarthInfo
GetEarthInfo(DateTimeOffset|TimeSpan Epoch) : EarthExtendedInfo

The time parameter accepts either a DateTimeOffset (absolute time) or a TimeSpan (offset from simulation start).

GetRadiusAtLatitude

Returns Earth’s radius at the specified latitude. Earth is not a perfect sphere due to equatorial bulge. This is a method on EarthInfo (returned by GetEarthInfo()), not a standalone function.

earthInfo.GetRadiusAtLatitude(double Latitude) : double

GetMoonInfo

Returns Moon’s basic information. If a date is provided, returns extended information for that date.

GetMoonInfo() : MoonInfo
GetMoonInfo(DateTimeOffset|TimeSpan Epoch) : MoonExtendedInfo

The time parameter accepts either a DateTimeOffset (absolute time) or a TimeSpan (offset from simulation start).

GetLocationInfo

Returns the Earth surface viewing location defined in the project. If a date is provided, returns extended information for that date.

GetLocationInfo() : LocationInfo
GetLocationInfo(DateTimeOffset|TimeSpan Time) : LocationInfoExtended

The time parameter accepts either a DateTimeOffset (absolute time) or a TimeSpan (offset from simulation start).

GetGsoDistance

Returns the radius required for Geostationary Orbit (approximately 42,164 km).

GetGsoDistance() : double

GetHohmannTransferInfo

Given initial and final circular orbit radii, returns the required delta-Vs and timings for a Hohmann transfer. GM defaults to Earth’s GM if not provided.

GetHohmannTransferInfo(double rInitial, double rFinal [, double GM]) : HohmannTransferInfo

GetSatInitialConditions

Returns a satellite’s defined initial conditions (epoch and state vectors).

GetSatInitialConditions(string SatName) : SatInitialConditions

GetSimProperties

Returns an object that allows project and simulation properties to be read and written to.

GetSimProperties() : SimProperties

Informational Helper Functions for Orbital Elements

GetEccentricAnomaly

GetEccentricAnomaly(double TrueAnomaly, double Eccentricity) : double
GetEccentricAnomaly(OrbitalElements OE) : double

GetEccentricity

GetEccentricity(double Periapsis, double Apoapsis) : double

GetLatitudeAndLongitude

Converts an ECI position to latitude and longitude at the given time.

GetLatitudeAndLongitude(Vector3 Position, DateTimeOffset Time) : LatLon
GetLatitudeAndLongitude(StateVectors Position, DateTimeOffset Time) : LatLon
GetLatitudeAndLongitude(OrbitalElements Position, DateTimeOffset Time) : LatLon

GetMeanAnomaly

GetMeanAnomaly(double TrueAnomaly, double Eccentricity) : double
GetMeanAnomaly(OrbitalElements OE) : double

GetOrbitalPeriod

GM defaults to Earth’s GM if not provided.

GetOrbitalPeriod(double SemiMajorAxis [, double GM]) : TimeSpan
GetOrbitalPeriod(OrbitalElements OE, double GM) : TimeSpan

GetRightAscensionAndDeclination

Converts an ECI position to right ascension and declination.

GetRightAscensionAndDeclination(Vector3 Position) : RaDec
GetRightAscensionAndDeclination(StateVectors Position) : RaDec
GetRightAscensionAndDeclination(OrbitalElements Position) : RaDec

GetSemiMajorAxis

GetSemiMajorAxis(double Periapsis, double Apoapsis) : double

GetTrueAnomaly

GetTrueAnomaly(double MeanAnomaly, double Eccentricity) : double

Active Functions

These functions interact with the simulator and make changes to orbits and simulations.

SetSatInitialConditions

Sets a satellite’s initial values: position, velocity, and epoch. The epoch can be anywhere in the simulation window. Using a NORAD ID downloads the latest TLE for that satellite. If the satellite doesn’t exist, it is created with default configuration.

SetSatInitialConditions(string SatName, DateTimeOffset Epoch, Vector3 Position, Vector3 Velocity) : bool
SetSatInitialConditions(string SatName, DateTimeOffset Epoch, StateVectors StateVector) : bool
SetSatInitialConditions(string SatName, DateTimeOffset Epoch, OrbitalElements OrbitalElements) : bool
SetSatInitialConditions(string SatName, DateTimeOffset Epoch, string NoradId) : bool

SetSatBurnoutConditions

Sets a satellite’s initial conditions to a burnout point above Earth. Specify the launch site (latitude, longitude), burnout altitude above the surface, velocity magnitude, and desired orbit inclination. The simulator computes the ECI state vectors for the burnout condition. If the satellite doesn’t exist, it is created.

SetSatBurnoutConditions(string SatName, DateTimeOffset Epoch, double Latitude, double Longitude, double Altitude, double Velocity, double Inclination [, bool LaunchNorth [, double PitchDeg]]) : bool
  • PitchDeg: Pitch angle from vertical in degrees (90 = straight up, 0 = horizontal). Default: 90. Minimum: 30. The pitch is applied within the orbital plane so that the desired inclination is preserved.

SetSatBurnoutOrbit

Launches a satellite from a surface site at burnout altitude and iteratively finds the burnout velocity that places apogee at the target orbit altitude, then applies a circularization delta-V burn at apogee. Uses the secant method under the full propagated physics model (Moon gravity, J2 oblateness, atmospheric drag, etc.). If the satellite doesn’t exist, it is created.

Returns a BurnoutOrbitResult with the converged burnout velocity, circularization delta-V magnitude, and the satellite state at apogee.

SetSatBurnoutOrbit(string SatName, DateTimeOffset Epoch, double Latitude, double Longitude, double BurnoutAltitude, double TargetAltitude, double Inclination [, bool LaunchNorth [, double PitchDeg [, double ToleranceMetres]]]) : BurnoutOrbitResult
  • BurnoutAltitude: Altitude above surface at burnout (metres), must be less than TargetAltitude
  • TargetAltitude: Desired final circular orbit altitude above surface (metres)
  • Inclination: Desired orbit inclination (degrees)
  • LaunchNorth: Launch direction (default: true)
  • PitchDeg: Pitch angle from vertical in degrees (90 = straight up, 0 = horizontal). Default: 90. Minimum: 30. The pitch is applied within the orbital plane so that the desired inclination is preserved.
  • ToleranceMetres: Convergence tolerance in metres (default: 100)

Return type — BurnoutOrbitResult:

  • .BurnoutVelocity — converged burnout velocity (m/s)
  • .CircularizationDeltaV — circularization delta-V magnitude (m/s)
  • .ApogeeState — SatelliteState at apogee before circularization

Example — launch to 400 km circular orbit from KSC:

simStart = CreateDateTime("2026-03-11T12:00:00Z")
SetSimulationWindow(simStart, CreateTimeSpan("6:00:00"))

result = SetSatBurnoutOrbit("Explorer-1", simStart, 28.573, -80.649, 100000.0, 400000.0, 28.5)
Say(format("Burnout velocity: {0:0.3} m/s", result.BurnoutVelocity))
Say(format("Circularization dV: {0:0.3} m/s", result.CircularizationDeltaV))

Note: Each iteration propagates the full orbit, so this function is slower than analytical helpers. Typically converges in 4–8 iterations.

SetSatParkingOrbitConditions

Sets a satellite’s initial conditions to a circular parking orbit above a launch site. Specify latitude, longitude, altitude above the surface, and desired orbit inclination. The simulator computes the circular orbital velocity and ECI state vectors. If the satellite doesn’t exist, it is created.

SetSatParkingOrbitConditions(string SatName, DateTimeOffset Epoch, double Latitude, double Longitude, double Altitude, double Inclination [, bool LaunchNorth]) : bool

SetSatLagrangeConditions

Sets a satellite’s initial conditions to an Earth-Moon Lagrange point (L1–L5). The simulator computes the position and velocity at the specified Lagrange point for the given epoch. If the satellite doesn’t exist, it is created. The Lagrange point can be a string (“L1”–“L5”).

SetSatLagrangeConditions(string SatName, DateTimeOffset Epoch, Lagrange LagrangePoint) : bool

SetSimulationWindow

Sets the simulation window start time and duration. Optionally sets the integration step size (DeltaT), integrator method, and sub-steps. Smaller DeltaT gives better accuracy but longer compute time; the default is 1 second.

SetSimulationWindow(DateTimeOffset Time, TimeSpan Duration [, TimeSpan DeltaT [, string Integrator [, int SubSteps]]]) : bool

SetIntegrator

Sets the numerical integration method and optionally the number of sub-steps (1–8). Available integrators: “Euler”, “Verlet” (Velocity Verlet), “RK4” (Runge-Kutta 4th Order).

SetIntegrator(string Integrator [, int SubSteps]) : bool

ClearAllDeltaV

Clears all delta-Vs for a satellite. Should be called at the beginning of a script.

ClearAllDeltaV(string SatName) : bool

CreateDeltaV

Creates an instantaneous velocity change (delta-V) on a satellite. The SatellitePathChange overload applies a path-computed delta-V. The delta-V can be expressed as a vector or scalar.

CreateDeltaV(string SatName, TimeSpan TS, Vector3 DeltaV [, string Description]) : bool
CreateDeltaV(string SatName, DateTimeOffset Time, Vector3 DeltaV [, string Description]) : bool
CreateDeltaV(string SatName, TimeSpan TS, double DeltaV [, string Description]) : bool
CreateDeltaV(string SatName, DateTimeOffset Time, double DeltaV [, string Description]) : bool
CreateDeltaV(string SatName, SatellitePathChange PathChange [, string Description]) : bool

CreateThrust

Creates a long-duration thrust (acceleration over time). The scalar overloads apply acceleration in the direction of (positive) or against (negative) the spacecraft velocity. The Vector3 overloads apply acceleration in a specified ECI direction.

CreateThrust(string SatName, TimeSpan TS, double Acceleration, double Angle, TimeSpan Period [, string Description]) : bool
CreateThrust(string SatName, DateTimeOffset Time, double Acceleration, double Angle, TimeSpan Period [, string Description]) : bool
CreateThrust(string SatName, TimeSpan TS, Vector3 Acceleration, TimeSpan Period [, string Description]) : bool
CreateThrust(string SatName, DateTimeOffset Time, Vector3 Acceleration, TimeSpan Period [, string Description]) : bool

TargetApsisRadius

Iteratively solves for a prograde/retrograde burn at BurnTime that produces a required apogee or perigee radius under the full propagated physics model (including Moon gravity, J2 oblateness, atmospheric drag, etc.). Uses the Hohmann analytical delta-V as the initial guess and converges via the secant method.

Returns an OrbitChange with the converged delta-V vector. The tolerance defaults to 100 metres if not specified.

TargetApsisRadius(string SatName, DateTimeOffset|TimeSpan BurnTime, string Apsis, double RequiredRadius [, double ToleranceMetres]) : OrbitChange
  • BurnTime: Absolute time (DateTimeOffset) or offset from simulation start (TimeSpan)
  • Apsis: "apogee" or "perigee"
  • RequiredRadius: Target apsis radius in metres
  • ToleranceMetres: Convergence tolerance in metres (default: 100)

Example — GEO transfer with targeted Burn 1:

gsoRadius = GetGsoDistance()
burn1Change = TargetApsisRadius("SAT", burn1Time, "apogee", gsoRadius)
CreateDeltaV("SAT", burn1Time, burn1Change.DeltaV, "Burn 1 - target GSO apogee")

Note: Each iteration propagates the full orbit, so this function is slower than analytical helpers. Typically converges in 4–6 iterations. The function checks that the simulation window is long enough to reach the target apsis and will report an error with the required minimum time if not.

FindApogeePerigee

Finds the next (or previous) apogee or perigee for a satellite. Automatically triggers Newtonian simulation calculation if the satellite’s state has changed since the last calculation.

FindApogeePerigee(string SatName, DateTimeOffset|TimeSpan FromTime) : SatelliteState
FindApogeePerigee(string SatName, DateTimeOffset|TimeSpan FromTime, string Apsis) : SatelliteState
FindApogeePerigee(string SatName, DateTimeOffset|TimeSpan FromTime, string Apsis, string Direction) : SatelliteState
  • FromTime: Absolute time (DateTimeOffset) or offset from simulation start (TimeSpan)
  • Apsis: "apogee", "perigee", or "either" (default: "either")
  • Direction: "forward" or "backward" (default: "forward")

FindNode

Finds the next (or previous) ascending or descending node for a satellite. Automatically triggers Newtonian simulation calculation if the satellite’s state has changed since the last calculation.

FindNode(string SatName, DateTimeOffset|TimeSpan FromTime) : SatelliteState
FindNode(string SatName, DateTimeOffset|TimeSpan FromTime, string Node) : SatelliteState
FindNode(string SatName, DateTimeOffset|TimeSpan FromTime, string Node, string Direction) : SatelliteState
  • FromTime: Absolute time (DateTimeOffset) or offset from simulation start (TimeSpan)
  • Node: "ascending", "descending", or "either" (default: "either")
  • Direction: "forward" or "backward" (default: "forward")

FindAtTime

Returns the satellite’s state at a specific time. Automatically triggers Newtonian simulation calculation if the satellite’s state has changed since the last calculation.

FindAtTime(string SatName, DateTimeOffset|TimeSpan AtTime) : SatelliteState
  • AtTime: Absolute time (DateTimeOffset) or offset from simulation start (TimeSpan)

Automatic recalculation: FindApogeePerigee, FindNode, and FindAtTime automatically recalculate the satellite’s orbit using full Newtonian mechanics (including atmospheric drag, Moon gravity, solar radiation pressure, etc.) when the satellite has been modified by SetSatInitialConditions, SetSatBurnoutConditions, SetSatParkingOrbitConditions, SetSatLagrangeConditions, CreateDeltaV, CreateThrust, or ClearAllDeltaV. No explicit recalculation function is needed.

ClearLabels

Clears all labels in the scene. Should be called at the beginning of a script.

ClearLabels() : bool

CreateLabel

Creates a label pointing to a position in 3D space. FontSize and Color are optional.

CreateLabel(Vector3 Position, string Text [, int FontSize, string Color]) : bool
CreateLabel(StateVectors Position, string Text [, int FontSize, string Color]) : bool
CreateLabel(OrbitalElements Position, string Text [, int FontSize, string Color]) : bool
CreateLabel(SatellitePath Position, string Text [, int FontSize, string Color]) : bool
CreateLabel(SatellitePathChange Position, string Text [, int FontSize, string Color]) : bool

Active Helper Functions for Date and Time

CreateDateTime

Creates a DateTimeOffset object. Use ISO 8601 format for portability across locales.

Examples: "2024-01-18T12:30:00Z" (UTC), "2024-01-18T12:30:00-07:00" (with timezone offset).

CreateDateTime(string DateTimeStr) : DateTimeOffset

CreateTimeSpan

Creates a TimeSpan object. String format: "d.hh:mm:ss" or "hh:mm:ss".

CreateTimeSpan(string TimeSpanStr) : TimeSpan
CreateTimeSpan(double Seconds) : TimeSpan
CreateTimeSpan(int Seconds) : TimeSpan

AddTimeSpans

Adds time spans together, or adds time spans to a DateTimeOffset.

AddTimeSpans(TimeSpan TS1, TimeSpan TS2 [, TimeSpan TSn..]) : TimeSpan
AddTimeSpans(DateTimeOffset Time, TimeSpan TS1 [, TimeSpan TSn..]) : DateTimeOffset

SubtractTimeSpans

Subtracts time spans, or subtracts time spans from a DateTimeOffset.

SubtractTimeSpans(TimeSpan TS1, TimeSpan TS2 [, TimeSpan TSn..]) : TimeSpan
SubtractTimeSpans(DateTimeOffset Time, TimeSpan TS1 [, TimeSpan TSn..]) : DateTimeOffset

GetTimeNow

Returns the current date and time when the script is run.

GetTimeNow() : DateTimeOffset

CreateOrbit

Creates a basic orbit record from periapsis and apoapsis radii. This orbit is not positioned in ECI space or time.

CreateOrbit(double Periapsis, double Apoapsis) : Orbit

CreateOrbitalElements

Creates an orbital elements record that describes an orbit in ECI (or MCI) space. Combines orbital elements with state vectors and keeps them in sync. CoordinateSystem defaults to ECI if not provided.

CreateOrbitalElements(double SemiMajorAxis, double Eccentricity, double Inclination, double LonOfAscendingNode, double ArgOfPeriapsis, double TrueAnomaly [, CoordinateSystem CoordinateSystem]) : OrbitalElements
CreateOrbitalElements(OrbitalElements OE) : OrbitalElements
CreateOrbitalElements(StateVectors StateVector) : OrbitalElements
CreateOrbitalElements(Vector3 Position, Vector3 Velocity [, CoordinateSystem CoordinateSystem]) : OrbitalElements
CreateOrbitalElements(Orbit Orbit, double Inclination, double LonOfAscendingNode, double ArgOfPeriapsis, double TrueAnomaly) : OrbitalElements
CreateOrbitalElements(PointOnOrbit PointOnOrbit, double Inclination, double LonOfAscendingNode, double ArgOfPeriapsis) : OrbitalElements

CreateSatellitePath

Creates a satellite path record from an epoch and orbital elements. Optionally specify how the path ends (final true anomaly and number of orbits).

CreateSatellitePath(DateTimeOffset Epoch, OrbitalElements OE [, double FinalTrueAnomaly, int NumberOfOrbits]) : SatellitePath

Active Helper Functions for State Vectors

CreateStateVectors

Creates a state vectors record. CoordinateSystem defaults to ECI if not provided.

CreateStateVectors(double SemiMajorAxis, double Eccentricity, double Inclination, double LonOfAscendingNode, double ArgOfPeriapsis, double TrueAnomaly [, CoordinateSystem CoordinateSystem]) : StateVectors
CreateStateVectors(OrbitalElements OE) : StateVectors
CreateStateVectors(Vector3 Position, Vector3 Velocity [, CoordinateSystem CoordinateSystem]) : StateVectors

CreateVector

Creates a 3D vector. Used for position, velocity, and delta-V.

CreateVector(double X, double Y, double Z) : Vector3

Built-in Language Functions

format

Formats a string.

format("{0} * {1} = {2}", arg0, arg1, arg2) : string

Example: format("{0} * {1} = {2}", 3, 4, 3 * 4) returns "3 * 4 = 12".

Standard C# format specifiers can also be used, example: format("{0:0.00} * {1:e} = 0x{2:X2} (Hex)", 3, 4, 3 * 4) returns "3.00 * 4.000000e+000 = 0x0C (Hex)". See: Standard Numeric Format Strings

iif

Inline if — returns one of two values based on a condition.

iif(bool Condition, object TrueValue, object FalseValue) : object

Example: iif(x > 0, "positive", "non-positive").


Other Script Functions

CallScript

Calls a named sub-script defined at the end of the main script. If the sub-script declares output variables, returns a dynamic object with those variables as properties. Otherwise, returns the sub-script’s last expression value.

CallScript(string ScriptName [, object VariableValue...]) : object

Example — using a return value:

doubled = CallScript("Double", 21)
Say(format("Result: {0}", doubled))

<"Double" n>
n * 2

Example — using output variables:

result = CallScript("Compute", 3, 4)
Say(format("Sum: {0}, Product: {1}", result.Sum, result.Product))

<"Compute" a, b : Sum, Product>
Sum = a + b
Product = a * b

CallScriptIf

Conditionally calls one of two sub-scripts based on a boolean condition. If the condition is true, calls TrueScriptName. If false and FalseScriptName is provided, calls that instead. Returns the called script’s result, or null if no script was called.

CallScriptIf(bool Condition, string TrueScriptName [, string FalseScriptName] [, object InputVars...]) : object

The condition accepts true/false, integers (non-zero = true), or any value (null = false).

Input variables can be passed after the false script name. The same variables are forwarded to whichever script is called. If you need input variables but no false script, use "_" as the false script name placeholder.

Examples:

isHighOrbit = oe.SemiMajorAxis > 20000000
setupResult = CallScriptIf(isHighOrbit, "High Orbit Setup", "Low Orbit Setup")

With input variables:

result = CallScriptIf(needsBigBurn, "LargeBurn", "SmallBurn", satellite, targetAlt)

With input variables and no false branch (use "_" placeholder):

result = CallScriptIf(isReady, "Launch", "_", satellite, inclination)

CallScriptSwitch

Calls one of several sub-scripts based on a zero-based integer index. The index selects which of the following script name arguments to call. Returns the called script’s result.

CallScriptSwitch(int Index, string ScriptName... [, "_", object InputVars...]) : object

Input variables can be passed after the script names by adding a "_" separator followed by the variables. The variables are forwarded to whichever script is selected.

Examples:

factor = CallScriptSwitch(mode, "Mode A Script", "Mode B Script", "Mode C Script")
Say(format("Factor: {0}", factor))

With input variables (note the "_" separator):

result = CallScriptSwitch(mode, "Low", "Med", "High", "_", satellite, targetAlt)

If mode is 0, calls “Low”; if 1, calls “Med”; if 2, calls “High” — each receiving satellite and targetAlt as input variables. Reports an error if the index is out of range.

CallScriptAtTime

Registers a sub-script to be called by the simulator at a specified time offset from the simulation start. Used for timed scripts that change the simulation as it runs.

CallScriptAtTime(TimeSpan|DateTimeOffset AtTime, string ScriptName [, object VariableValue...]) : bool
  • AtTime: Offset from simulation start (TimeSpan) or absolute time (DateTimeOffset, which is converted to an offset)

CreateObject

Creates a .NET object of the specified type with optional constructor arguments.

CreateObject(string ObjectType [, object ConstructorArg...]) : object

Say

Outputs messages and values to the Mission Planner output panel. Useful for debugging. You can use the format function to format numbers and strings before output, e.g. Say(format("Altitude: {0:0.00} m", altitude)). Returns the string that has been output, for information.

Say(object ItemToOutput [, object ItemToOutput..]) : string

Stop

Stops script execution. With a boolean argument, stops only if the expression is true.

Stop() : void
Stop(bool StopIfTrue) : void

Records

Records are structured types returned by script functions. Access properties using dot notation, e.g. earthInfo.AverageRadius.

DateTimeOffset

Represents a date and time with timezone information. Used by many functions.

Built-in methods: .Add(TimeSpan), .Subtract(TimeSpan), .ToUniversalTime().

TimeSpan

Represents a duration of time with no date. Format: "d.hh:mm:ss".

Built-in methods: .Add(TimeSpan), .Subtract(TimeSpan).

Properties: Days, Hours, Minutes, Seconds, TotalDays, TotalHours, TotalMinutes, TotalSeconds.

Vector3

A 3D vector with X, Y, Z components.

Property Type Description
X double X component
Y double Y component
Z double Z component
Magnitude double Vector length (read-only)
Unit Vector3 Unit vector in same direction (read-only)

StateVectors

Holds position and velocity vectors in a coordinate system.

Property Type Description
Position Vector3 Position vector (m)
Velocity Vector3 Velocity vector (m/s)
CoordinateSystem CoordinateSystem ECI or MCI

Methods: Convert(DateTimeOffset, CoordinateSystem) — converts between ECI and MCI.

EarthInfo

Returned by GetEarthInfo().

Property Type Description
RotationalPeriod TimeSpan Sidereal rotation period
AverageRadius double Average Earth radius (m)
GM double Gravitational parameter (m³/s²)
G double Surface gravity (9.81 m/s²)

Methods: GetRadiusAtLatitude(double Latitude) : double.

EarthExtendedInfo

Returned by GetEarthInfo(DateTimeOffset|TimeSpan). Inherits all EarthInfo properties plus:

Property Type Description
Time DateTimeOffset The requested time
AngleOfRotation double Earth’s rotation angle at Time (degrees)

MoonInfo

Returned by GetMoonInfo().

Property Type Description
OrbitalPeriod TimeSpan Moon’s orbital period
Radius double Moon radius (m)
GM double Lunar gravitational parameter (m³/s²)

MoonExtendedInfo

Returned by GetMoonInfo(DateTimeOffset|TimeSpan). Inherits all MoonInfo properties plus:

Property Type Description
Time DateTimeOffset The requested time
StateVectors StateVectors Moon’s ECI position and velocity at Time

LocationInfo

Returned by GetLocationInfo().

Property Type Description
Coord LatLon Latitude and longitude
Altitude double Altitude above MSL (m)
DistanceToEarthCenter double Distance from Earth center including bulge (m, read-only)

LocationInfoExtended

Returned by GetLocationInfo(DateTimeOffset|TimeSpan). Inherits all LocationInfo properties plus:

Property Type Description
Time DateTimeOffset The requested time
AngleOfRotation double Earth’s rotation angle at Time (degrees)
StateVectors StateVectors ECI position and velocity of the location at Time

HohmannTransferInfo

Returned by GetHohmannTransferInfo(). All velocities are scalar (m/s), radii are in metres.

Property Type Description
RadiusInitialOrbit double Initial circular orbit radius
RadiusFinalOrbit double Final circular orbit radius
GM double Gravitational parameter used
DeltaVInitial double Delta-V for first burn (m/s)
DeltaVFinal double Delta-V for second burn (m/s)
VelocityInitialHohmann double Velocity at start of transfer orbit
VelocityFinalHohmann double Velocity at end of transfer orbit
VelocityInitialOrbit double Circular velocity of initial orbit
VelocityFinalOrbit double Circular velocity of final orbit
Duration TimeSpan Transfer orbit duration (half period)

RaDec

Returned by GetRightAscensionAndDeclination().

Property Type Description
RightAscensionRad double Right ascension (radians)
DeclinationRad double Declination (radians)
Distance double Distance from origin (m)
RightAscensionDeg double Right ascension (degrees, read-only)
DeclinationDeg double Declination (degrees, read-only)

LatLon

Returned by GetLatitudeAndLongitude().

Property Type Description
Latitude double Latitude (degrees)
Longitude double Longitude (degrees)

SatelliteState

Returned by FindApogeePerigee(), FindNode(), and FindAtTime(). Contains the satellite’s full state at the found orbital event or specified time.

Property Type Description
Name string Satellite name
Event string Event type: "apogee", "perigee", "ascending", "descending", or "atTime"
DateTime DateTimeOffset Time of the event
StateVectors StateVectors Position and velocity at the event
OrbitalElements OrbitalElements Orbital elements at the event
InShadow bool Whether the satellite is in shadow at the event

SatInitialConditions

Returned by GetSatInitialConditions().

Property Type Description
Epoch DateTimeOffset Epoch when conditions are valid
StateVectors StateVectors Position and velocity at epoch

Orbit

Returned by CreateOrbit(). A basic orbit not positioned in ECI space or time.

Property Type Description
SemiMajorAxis double Semi-major axis (m)
SemiMinorAxis double Semi-minor axis (m)
Eccentricity double Orbital eccentricity (read-only)
Apoapsis double Apoapsis radius (m)
Periapsis double Periapsis radius (m)
Perimeter double Orbital perimeter (m, read-only)
OrbitalPeriod TimeSpan Orbital period (read-only)
GM double Gravitational parameter (defaults to Earth)

Methods: CreatePoint(double TrueAnomaly) : PointOnOrbit.

PointOnOrbit

Returned by Orbit.CreatePoint(). Describes a specific point on a basic orbit.

Property Type Description
Orbit Orbit Parent orbit record
TrueAnomaly double True anomaly at this point (degrees)
MeanAnomaly double Mean anomaly (degrees, read-only)
EccentricAnomaly double Eccentric anomaly (degrees, read-only)
Radius double Distance from focus (m, read-only)
Velocity double Orbital velocity (m/s, read-only)
PeriodFromPeriapsis TimeSpan Time since periapsis (read-only)

OrbitalElements

Returned by CreateOrbitalElements(). Describes an orbit in ECI/MCI space. Orbital elements and state vectors are kept in sync — changing one updates the other.

Property Type Description
SemiMajorAxis double Semi-major axis (m)
Eccentricity double Eccentricity
Inclination double Inclination (degrees)
LonOfAscendingNode double Longitude of ascending node (degrees)
ArgOfPeriapsis double Argument of periapsis (degrees)
TrueAnomaly double True anomaly (degrees)
CoordinateSystem CoordinateSystem ECI or MCI (read-only)
GM double Gravitational parameter (read-only)
Radius double Current distance from focus (m, read-only)
Velocity double Current orbital velocity (m/s, read-only)
Apoapsis double Apoapsis radius (m, read-only)
Periapsis double Periapsis radius (m, read-only)
MeanAnomaly double Mean anomaly (degrees, read-only)
EccentricAnomaly double Eccentric anomaly (degrees, read-only)
AscendingNodeTA double True anomaly at ascending node (read-only)
DescendingNodeTA double True anomaly at descending node (read-only)
OrbitalPeriod TimeSpan Orbital period (read-only)
PeriodFromPeriapsis TimeSpan Time since periapsis (read-only)
StateVectors StateVectors Equivalent state vectors
RaDec RaDec Right ascension and declination (read-only)

Methods:

ChangeOrbitToCircular() : OrbitChange
ChangeOrbitToRequiredRadius(double Radius) : OrbitChange
ChangeOrbitToRequiredInclination(double RequiredInclination) : OrbitChange
GetPeriodTo(double NewTrueAnomaly) : TimeSpan

OrbitChange

Returned by orbital change methods on OrbitalElements.

Property Type Description
NewOrbit OrbitalElements Orbital elements after the change
OldOrbit OrbitalElements Orbital elements before the change
DeltaV Vector3 Required delta-V vector (m/s)

SatellitePath

Returned by CreateSatellitePath(). Describes a section of an orbit in space and time. Paths can be chained together to build multi-maneuver missions.

Property Type Description
StartTime DateTimeOffset When this path section starts
OrbitalElements OrbitalElements Orbital elements for this path section
FinalTrueAnomaly double True anomaly where this path ends (settable)
NumberOfOrbits int Number of complete orbits in this section (settable)
InitialPathChange SatellitePathChange Path change at the start of this section
FinalPathChange SatellitePathChange Path change at the end of this section
PeriodToFinalTrueAnomaly TimeSpan Duration to reach FinalTrueAnomaly (read-only)
TimeOfFinalTrueAnomaly DateTimeOffset Absolute time at FinalTrueAnomaly (read-only)

Methods (each returns a new linked SatellitePath with automatic delta-V):

ChangeOrbitToCircular() : SatellitePath
ChangeOrbitToRequiredRadius(double Radius) : SatellitePath
ChangeOrbitToRequiredInclination(double RequiredInclination) : SatellitePath
ChangeCoordinates(CoordinateSystem CoordinateSystem) : SatellitePath

Changing the StartTime on a path correctly updates linked paths in the chain.

SatellitePathChange

Links two SatellitePath records together, representing a maneuver.

Property Type Description
PreviousPath SatellitePath The path before the maneuver
NextPath SatellitePath The path after the maneuver
DeltaV Vector3 Delta-V vector for this maneuver (m/s)
Time DateTimeOffset When the maneuver occurs (read-only)

SimProperties

Returned by GetSimProperties(). Allows reading and writing project and simulation display settings. Also automatically available in Timed Scripts.

Camera and view properties:

Property Type Description
SelectedLookAt string What the camera looks at
SelectedViewFrom string Camera view origin
SelectedCameraTrackingType string Camera tracking mode
CameraHorizontalAngle int Horizontal camera angle
CameraVerticalAngle int Vertical camera angle
CameraDistance double Camera distance
SelectedRotationPoint string Rotation center
SelectedCameraOrientation string Camera orientation
FieldOfView double Camera field of view
SimulationSpeed int Playback speed multiplier

Display properties (accept true/false or 1/0 for backward compatibility):

Property Type Description
ShowSatOrbitLines bool Satellite orbit lines
ShowSatOrbitSteps bool Satellite orbit step markers
ShowSatLabels bool Satellite name labels
ShowSatGroundLines bool Ground track lines
ShowSatGroundSteps bool Ground track step markers
ShowSatSkyLines bool Sky track lines
ShowMoonOrbitLine bool Moon orbit line
ShowMoonOrbitSteps bool Moon orbit step markers
ShowMoonSatelliteOrbitLines bool Lunar satellite orbit lines
ShowStarMap bool Star map background
ShowStarLabels bool Star name labels
ShowEclipticLine bool Ecliptic plane line
ShowEquatorialLine bool Equatorial plane line
ShowLocation bool Earth surface location marker
ShowSunShadows bool Sun shadow effects
ShowPlanets bool Solar system planets
NumberOfSteps int Number of orbit track steps
OrbitLineThickness double Orbit line thickness
OrbitTrackThickness double Orbit track thickness
DeltaT TimeSpan Integration time step
SimTimeSpan TimeSpan Simulation duration

Methods:

GetSatProperties(string SatName) : SimSatProperties
SetSetting(string SettingName, object Value) : void
GetSetting(string SettingName) : object
ClearSettings() : void

SimSatProperties

Returned by SimProperties.GetSatProperties(). Per-satellite display settings.

Property Type Description
Name string Satellite name
ShowSatelliteTrack bool Show orbit track
ShowGroundTrack bool Show ground track
ShowSkyTrack bool Show sky track
ShowDeltaV bool Show delta-V markers
SelectedSatelliteType string 3D model name
LineColour string Track line colour
TotalDeltaV double Total delta-V magnitude (read-only)

Callable Scripts

Sub-scripts are defined at the end of the main script. They act as reusable functions that can accept input variables and return values.

Function Scripts

Header format:

< "Script Name" [, InputVar [, ..] ] [ : OutputVar [, ..] ] >

Return Values

Sub-scripts can return values in two ways:

1. Last expression value — if no output variables are declared, the sub-script returns the value of its last expression:

radius = CallScript("ComputeRadius", 400000)
Say(format("Orbit radius: {0} m", radius))

<"ComputeRadius" altitude>
6371000 + altitude

2. Output variables — if output variables are declared after the : in the header, they are collected into a dynamic object with named properties:

result = CallScript("PolarToCartesian", 5.0, 45.0)
Say(format("x={0}, y={1}", result.X, result.Y))

<"PolarToCartesian" r, angleDeg : X, Y>
angleRad = angleDeg * PI / 180
X = r * Cos(angleRad)
Y = r * Sin(angleRad)

Return values work with all calling methods — CallScript, CallScriptIf, and CallScriptSwitch:

dv = CallScriptIf(needsBigBurn, "LargeBurn", "SmallBurn", satellite)
Say(format("Delta-V: {0} m/s", dv))

factor = CallScriptSwitch(mode, "GetLowFactor", "GetMedFactor", "GetHighFactor", "_", baseDv)
totalDv = baseDv * factor

Timed Scripts

Timed scripts are special sub-scripts that the simulator calls at a specified time during playback. They allow you to change the view, camera, display settings, and satellite properties dynamically as the simulation runs.

How Timed Scripts Work

  1. Define one or more timed sub-scripts at the end of the main script using the Timed keyword in the header.
  2. In the main script, register them with CallScriptAtTime specifying the simulation time offset.
  3. When the simulation reaches that time, the script is executed automatically.

Header Format

<"Script Name" [, InputVar [, ..]] : Timed>

Registration

Use CallScriptAtTime in the main script. The time can be a TimeSpan offset from the simulation start or a DateTimeOffset (which is converted to an offset). You can optionally pass input variables.

CallScriptAtTime("0:30:00", "My Script")
CallScriptAtTime("1:00:00", "My Script With Args", "ISS (ZARYA)", 500)

Note: CallScriptAtTime accepts a TimeSpan string directly (unlike CreateDeltaV which requires CreateTimeSpan), or a DateTimeOffset. Each time value must be unique — you cannot register two scripts at the same time offset.

The SimProperties Global Variable

Timed scripts automatically have a global variable called SimProperties which provides read/write access to simulator and display settings. In the main script, you can obtain it via GetSimProperties().

Restrictions

Timed scripts cannot call other scripts (CallScript and CallScriptAtTime are not available). Most other functions such as CreateDeltaV, FindApogeePerigee, etc. are also not available. Timed scripts are intended for changing the view and display settings during playback.

Calling a Timed Script from the Main Script

You can also call a timed script directly from the main script using CallScript("ScriptName"). This is useful for setting up the initial view before playback starts.

Complete Example

# Main script — set up and register timed scripts

sim = GetSimProperties()
sim.ShowSunShadows = false

sat = sim.GetSatProperties("ISS (ZARYA)")
sat.SelectedSatelliteType = "Orbital Station"

CallScript("Reset View")

CallScriptAtTime("0:00:00", "Reset View")
CallScriptAtTime("0:10:00", "Alter View")
CallScriptAtTime("0:20:00", "Named View", "The Moon")

<"Reset View" : Timed>
SimProperties.SimulationSpeed = 128
SimProperties.ShowSatOrbitLines = true
SimProperties.SelectedLookAt = "ISS (ZARYA)"
SimProperties.SelectedViewFrom = "A relative position"
SimProperties.CameraDistance = 10000000
SimProperties.SelectedCameraTrackingType = "Behind"
SimProperties.SelectedCameraOrientation = "Direction of Travel is down"

<"Alter View" : Timed>
SimProperties.SelectedCameraTrackingType = "Above & Behind"
SimProperties.ShowSatOrbitLines = false

<"Named View" inputName : Timed>
SimProperties.SelectedLookAt = inputName

SimProperties Reference

The SimProperties object controls simulator and display settings. Obtained in the main script via GetSimProperties(), and available automatically as SimProperties in timed scripts.

Boolean properties use 1 for true and 0 for false.

SimProperties Properties

Camera & View

Property Type Read/Write Description
SelectedLookAt string R/W What the camera looks at. Values: “Not controlled”, “The Earth”, “The Moon”, “Location on Earth”, “L1”–“L5”, or any satellite name.
SelectedViewFrom string R/W Where the camera views from. Values: “Not controlled”, “A relative position”, “The Earth”, “Location on Earth”, “The Moon”, “L1”–“L5”, or any satellite name.
SelectedCameraTrackingType string R/W Camera tracking mode. Values: “Behind”, “Above & Behind”, “Above”, “Above & In Front”, “In Front”, “Below”, “Left Side”, “Right Side”, “Above – Left Side”, “Above – Right Side”, “USER DEFINED”.
SelectedCameraOrientation string R/W Camera orientation. Values: “Not controlled”, “Direction of Travel is up”, “Direction of Travel is down”, “Direction of Travel is left”, “Direction of Travel is right”, “North is up”, “North is down”, “North is left”, “North is right”.
SelectedRotationPoint string R/W Camera rotation point. Values: “Not controlled”, “The Earth”, “Location on Earth”, “The Moon”, “L1”–“L5”, or any satellite name.
CameraDistance double R/W Distance from camera to look-at target (metres).
CameraHorizontalAngle int R/W Horizontal camera angle (degrees).
CameraVerticalAngle int R/W Vertical camera angle (degrees).
FieldOfView double R/W Camera field of view (degrees).
LookAt string[] Read only Array of available look-at directions.
ViewFrom string[] Read only Array of available view-from points.
CameraTrackingTypes string[] Read only Array of available camera tracking types.
RotationPoints string[] Read only Array of available rotation points.

Simulation

Property Type Read/Write Description
SimulationSpeed int R/W Playback speed multiplier. Ignored during real-time playback.
DeltaT TimeSpan R/W Physics time step.
SimTimeSpan TimeSpan R/W Total simulation duration.

Display Toggles (use true/false; 1/0 also accepted for backward compatibility)

Property Type Read/Write Description
ShowSatOrbitLines bool R/W Show satellite orbit path lines.
ShowSatLabels bool R/W Show satellite name labels.
ShowSatOrbitSteps bool R/W Show step markers on satellite orbits.
ShowSatGroundLines bool R/W Show satellite ground track lines.
ShowSatGroundSteps bool R/W Show step markers on ground tracks.
ShowSatSkyLines bool R/W Show satellite sky track lines.
ShowEclipticLine bool R/W Show ecliptic plane line.
ShowEquatorialLine bool R/W Show equatorial plane line.
ShowMoonOrbitLine bool R/W Show Moon orbit path.
ShowMoonOrbitSteps bool R/W Show step markers on Moon orbit.
ShowMoonSatelliteOrbitLines bool R/W Show Moon-relative satellite orbit lines.
ShowLocation bool R/W Show ground location marker.
ShowStarMap bool R/W Show star map background.
ShowStarLabels bool R/W Show star name labels.
ShowSunShadows bool R/W Show Sun shadow regions.
ShowPlanets bool R/W Show planet positions.
NumberOfSteps int R/W Number of step markers shown on orbit tracks.

Line Appearance

Property Type Read/Write Description
OrbitLineThickness double R/W Thickness of orbit path lines.
OrbitTrackThickness double R/W Thickness of orbit track lines.

SimProperties Functions

Function Returns Description
GetSatProperties(string SatName) SimSatProperties Get a satellite’s properties object by name. Case-insensitive.
SetSetting(string SettingName, object Value) void Store a custom key-value setting (persists during simulation).
GetSetting(string SettingName) object Retrieve a previously stored custom setting. Returns null if not found.
ClearSettings() void Remove all custom settings.

SimSatProperties Reference

Returned by SimProperties.GetSatProperties("SatName"). Provides read/write access to individual satellite display properties.

Property Type Read/Write Description
Name string R/W Satellite name.
ShowSatelliteTrack bool R/W Show this satellite’s orbit track.
ShowGroundTrack bool R/W Show this satellite’s ground track.
ShowSkyTrack bool R/W Show this satellite’s sky track.
ShowDeltaV bool R/W Show delta-V markers for this satellite.
SelectedSatelliteType string R/W 3D model. Values: “Red Ball”, “Satellite 1”, “Asteroid 1”, “Orbital Station”, “Spacecraft”.
LineColour string R/W Track line colour as a hex string, e.g. “#FF0000”.
TotalDeltaV double Read only Total delta-V applied to this satellite (m/s).
SatelliteTypesTypes string[] Read only Array of available satellite model names.

CoordinateSystem Enum

Value Description
ECI Earth-Centered Inertial (default)
MCI Moon-Centered Inertial

Use "ECI" or "MCI" as a string argument when creating orbital elements or state vectors in the MCI frame. Example:

orbit = CreateOrbitalElements(2000000, 0, 45, 90, 90, 180, "MCI")