Scripting Functions

<< Previous: Scripting Overview

Next: Scripting Example >>


Cosmographia scripting interface provides functions for:
[4.0+] indicates features available in Cosmographia 4.0 or later.
[4.1+] indicates features available in Cosmographia 4.1 or later.
[OSX] indicates features available only on OSX.

Functions for Script Execution Timing and Annotations

The Cosmographia scripting interface provides the following functions for script execution timing and annotations:
Function
Description
wait(dur)
delays execution of the next script step by dur CPU seconds.
waitSim(simdur)
[4.1+] delays execution of the next script step by simdur simulation seconds passing either in the forward or reverse time direction. For example, following this call setting the simulation time rate to 1 hour in 1 CPU second, cosmo.setTimeRate(3600), this call cosmo.waitSim(15*3600) delays the next step by 15 simulation hours passing in 15 CPU seconds.
displayNote(text,dur)
displays text at the top of the screen for dur CPU seconds.

Functions for Time Manipulation

The Cosmographia scripting interface provides the following functions for time manipulation:
Function
Description
setTime(time)
sets the current simulation time to time given as a numeric Julian Date TDB (e.g. 2457267.500000), a UTC string (e.g. “2029-07-17 23:00:00.001 UTC”), or a TDB string (e.g. “2016-01-01 00:00:00.000 TDB”).
getTime()
[4.1+] returns the current simulation time as Barycentric Dynamical Time (TDB) seconds.
setTimeRate(rate)
sets time rate to the specified numeric rate in simulation seconds per 1 CPU second.
reverseTime()
reverses time direction.
pause()
pauses time.
unpause()
un-pauses time.
faster2x()
increases time rate 2 times.
slower2x()
decreases time rate 2 times.
faster10x()
increases time rate 10 times.
slower10x()
decreases time rate 10 times.
forwardDay()
jumps time 1 day forward.
backDay()
jumps time 1 day backward.
forwardYear()
jumps time 1 year forward.
backYear()
jumps time 1 year backward.

Functions for Selecting and Going to Objects

The Cosmographia scripting interface provides the following functions for selecting, setting as the center, and going to objects:
Function
Description
selectObject(name)
selects the object with name name.
deselectSelectedObject()
de-selects the currently selected object.
setCentralObject(name)
sets the object with name name as the central object.
gotoObject(name[,dur])
over dur CPU seconds, moves the camera to and points it at the object with the name name, sets this object as the center, and sets the rendering frame to ICRF. If dur is omitted, the default duration is used.
gotoHome(name[,dur])
over dur CPU seconds, moves the camera to the “home” position above the Solar System looking down on it, sets Sun as the center, and sets the rendering frame to inertial. If dur is omitted, the default duration is used.
moveToPov(name,vec1,vec2,vec3, dur)
over dur CPU seconds, sets the body with the name name as the center and its body-fixed frame as the rendering frame, moves the camera to the position vec1, in kilometers, relative to it in its body-fixed frame, and orients the camera to look along the direction vec2 while aligning the camera up direction with the direction vec3 with both vec2 and vec3 specified in the body’s body-fixed frame.
For example cosmo.moveToPov(“Mars”, [0.0,10000.0,0.0], [0.0,-1.0,0.0], [0.0,0.0,-1.0], 5.0) takes 5.0 CPU seconds to place the camera at [0.0,10000.0,0.0] relative to “Mars” in the Mars body-fixed frame while pointing the camera at Mars ([0.0,-1.0,0.0]) and aligning the Mars south pole ([0.0,0.0,-1.0]) with the camera up direction.
moveToPovSpiceFrame(name, frame,vec1,vec2,vec3,dur)
[4.1+] over dur CPU seconds, sets the body with the name name as the center and the SPICE frame frame as the rendering frame, moves the camera to the position vec1, in kilometers, relative to the body in this frame, and orients the camera to look along the direction vec2 while aligning the camera up direction with the direction vec3 with both vec2 and vec3 specified in the given frame.
For example cosmo.moveToPovSpiceFrame(“Sun”, “ECLIPJ2000”, [0,0,300000000], [0,0,-1], [-1,0,0], 5.0) takes 5.0 CPU seconds to place the camera at [0,0,300000000] relative to “Sun” in the “ECLIPJ2000” frame while pointing the camera at the Sun ([0,0,-1]) and aligning the “ECLIPJ2000” frames -X axis ([-1,0,0]) with the camera up direction.
setSceneFromUrl(url)
[4.1+] instantaneously sets the scene based on a provided Cosmographia state url, normally captured to the clipboard using the “Save URL” hot key or menu option.
For example cosmo.setSceneFromUrl(“cosmo:Mars? select=Mars&frame=icrf&jd=2458899.409773& x=707.461354&y=6862.689698&z=8215.439122& qw=0.007667&qx=0.032313&qy=0.340675& qz=0.939594&ts=0&fov=50”) sets a close up view of Mars.

Functions for Changing Camera Position and Orientation

The Cosmographia scripting interface provides the following functions for changing the camera position and orientation at the same time:
Function
Description
circleCenterLeft(ang,dur)
over dur CPU seconds, moves camera around the central object by ang degrees going left in the camera’s horizontal plane.
circleCenterRight(ang,dur)
over dur CPU seconds, moves camera around the central object by ang degrees going right in the camera’s horizontal plane.
circleCenterUp(ang,dur)
over dur CPU seconds, moves camera around the central object by ang degrees going up in the camera’s vertical plane.
circleCenterDown(ang,dur)
over dur CPU seconds, moves camera around the central object by ang degrees going down in the camera’s vertical plane.

Functions for Changing Only Camera Orientation

The Cosmographia scripting interface provides the following functions for changing just the camera orientation:
Function
Description
pointAtObject(name)
points the camera at the object with name name.
rollLeft(ang,dur)
over dur CPU seconds, rotates the camera counterclockwise (left) by ang degrees about the view direction.
rollRight(ang,dur)
over dur CPU seconds, rotates the camera clockwise (right) by ang degrees about the view direction.
rollToBodyFixedVector(name,vec,dur)
over dur CPU seconds, rotates the camera about the view direction to align its up direction with the vector vec in the body-fixed frame of the object with name name.
panLeft(ang,dur)
over dur CPU seconds, rotates the camera left by ang degrees about the vertical direction.
panRight(ang,dur)
over dur CPU seconds, rotates the camera right by ang degrees about the vertical direction.
tiltUp(ang,dur)
over dur CPU seconds, rotates the camera up by ang degrees about the horizontal direction.
tiltDown(ang,dur)
over dur CPU seconds, rotates the camera down by ang degrees about the horizontal direction.
rotateAboutVector(vec,ang,dur)
over dur CPU seconds, rotates the camera by ang degrees about the direction given by the vector vec in the rendering frame.
setCameraOrientation(quat)
sets the camera orientation relative to the rendering frame as specified by the SPICE-style quaternion quat.
getCameraOrientation()
returns the camera orientation relative the rendering frame as the SPICE-style quaternion (quat=cosmo.getCameraOrientation()).

Functions for Changing Only Camera Position

The Cosmographia scripting interface provides the following functions for changing just the camera position:
Function
Description
moveTowardsCenter(dist,dur)
over dur CPU seconds, moves the camera dist kilometers closer to the central object.
moveAwayFromCenter(dist,dur)
over dur CPU seconds, moves the camera dist kilometers farther from the central object.
dollyForward(dist,dur)
over dur CPU seconds, moves the camera dist kilometers forward along the view direction.
dollyBackward(dist,dur)
over dur CPU seconds, moves the camera dist kilometers backwards along the view direction.
truckLeft(dist,dur)
over dur CPU seconds, moves the camera dist kilometers left in the horizontal direction.
truckRight(dist,dur)
over dur CPU seconds, moves the camera dist kilometers right in the horizontal direction.
craneUp(dist,dur)
over dur CPU seconds, moves the camera dist kilometers up in the vertical direction.
craneDown(dist,dur)
over dur CPU seconds, moves the camera dist kilometers down in the vertical direction.
translateAlongVector(vec,dist,dur)
over dur CPU seconds, moves the camera dist kilometers along the direction vec in the rendering frame.
moveToDistanceFromCenter(dist,dur)
over dur CPU seconds, moves the camera to the location dist kilometers away from the central object on the camera-center line.
getDistanceFromCenter()
returns the distance from the central object in kilometers (dist=cosmo.getDistanceFromCenter()).
setCameraPosition(vec)
puts the camera at the location vec relative to the central object in the rendering frame.
For example cosmo.setCameraPosition([0.0,10000.0,0.0]) puts the camera at 10,000 kilometers away from the center on the rendering frame’s Y axis.
getCameraPosition()
returns the camera position vector relative to the central object in the rendering frame (vec=cosmo.getCameraPosition())

Functions for Changing Rendering Frame

The Cosmographia scripting interface provides the following functions for selecting various rendering frames:
Function
Description
setCameraToInertialFrame()
set the rendering frame to ICRF.
setCameraToBodyFixedFrame()
sets the rendering frame to the body-fixed frame of the central object.
setCameraToSynodicFrame()
sets the rendering frame to the synodic frame based on for the central object and the object that it orbits.
setCameraToLockedFrame(name)
sets the rendering frame to the locked frame based on the central object and the object with the name name.
trackObject(name)
sets the rendering frame to the locked frame based on the central object and the object with the name name.

Functions for Changing Objects’ Visual Attributes

The Cosmographia scripting interface provides the following functions for changing visual attributes of objects:
Function
Description
showObject(name)
shows the object with the name name.
hideObject(name)
hides the object with the name name.
showIcrfFrame(name)
shows the ICRF frame centered at the object with the name name.
hideIcrfFrame(name)
hides the ICRF frame centered at the object with the name name.
showBodyFixedFrame(name)
shows the body-fixed frame of the object with the name name centered at that object.
hideBodyFixedFrame(name)
hides the body-fixed frame of the object with the name name centered at that object.
showSpiceFrame(name,frame)
shows the SPICE frame with the name frame centered at the object with the name name.
hideSpiceFrame(name,frame)
hides the SPICE frame with the name frame centered at the object with the name name.
showVelocityVector(name)
shows the velocity direction of the object with the name name.
hideVelocityVector(name)
hides the velocity direction of the object with the name name.
showDirectionVector(name,target)
shows the direction from the object with the name name to the object with the name target.
hideDirectionVector(name,target)
hides the direction from the object with the name name to the object with the name target.
showTrajectory(name)
shows the trajectory of the object with the name name.
hideTrajectory(name)
hides the trajectory of the object with the name name.
trajectoryWidth(name,width)
sets the width of the line used to plot the trajectory of the object with the name name to width pixels.
showLatLongGrid(name)
shows the latitude-longitude grid on the object with the name name.
hideLatLongGrid(name)
hides the latitude-longitude grid on the object with the name name.
showTerminator(name)
shows the terminator line on the object with the name name.
hideTerminator(name)
hides the terminator line on the object with the name name.
labelFade(name,dist)
sets the distance dist at which the label of the object with the name name should fade.

Functions for Changing Visualization Settings

The Cosmographia scripting interface provides the following functions for changing visualization setting:
Function
Description
showAllObjects()
shows all objects.
hideAllObjects()
hides all objects.
showPlanetOrbits()
shows orbits of all planets.
hidePlanetOrbits()
hides orbits of all planets.
showEquatorialGrid()
shows the ICRF longitude-latitude grid on the sky.
hideEquatorialGrid()
hides the ICRF longitude-latitude grid from the sky.
showEcliptic()
shows the Ecliptic plane line marker on the sky.
hideEcliptic()
hides the Ecliptic plane line marker from the sky.
showCenterIndicator()
shows the central object indicator.
hideCenterIndicator()
hides the central object indicator.
showInfoText()
shows the info text in the top left and right corners of the window.
hideInfoText()
hides the info text.
showLabels()
shows object labels.
hideLabels()
hides object labels.
showLatLongLabels()
shows latitude-longitude grid labels.
hideLatLongLabels()
hides latitude-longitude grid labels.
showSurfaceFeatureLabels()
shows surface feature labels.
hideSurfaceFeatureLabels()
hides surface feature labels.
showObservationLabels()
shows observation labels.
hideObservationLabels()
hides observation labels.
showConstellationFigures()
shows constellation figures.
hideConstellationFigures()
hides constellation figures.
showConstellationNames()
shows constellation names.
hideConstellationNames()
hides constellation names.
showStarNames()
shows star names.
hideStarNames()
hides star names.
showStatusMessages()
shows default status messages.
hideStatusMessages()
hides default status messages.
showSpiceMessages()
shows missing SPICE data messages.
hideSpiceMessages()
hides missing SPICE data messages.
fadeOut(dur)
[4.0+] over dur CPU seconds, fades out the program window from normal visualization to black. If the script ends in the fade out state, the normal visualization is automatically restored.
fadeIn(dur)
[4.0+] over dur CPU seconds, fades in the program window from black to normal visualization.

Functions for Loading/Unloading Catalog Files

The Cosmographia scripting interface provides the following functions for loading and unloading catalog files:
Function
Description
loadCatalogFile(file)
loads the catalog file named file. The file name can be given with an absolute path or with a relative path to directory from which Cosmographia is launched.
unloadLastCatalog()
unloads the last loaded catalog file.
scriptDir()
[4.1+] returns the absolute path to the script directory, facilitating loading catalogs with a relative path.
For example a catalog file realpath/catalog.json with path relative to the script directory can be loaded using cosmo.loadCatalogFile( os.path.join( cosmo.scriptDir(), “realpath/catalog.json” ) ) or cosmo.oadCatalogFile( cosmo.scriptDir() + “/” + “realpath/catalog.json” ).

Functions for Capturing Screenshots and Videos

The Cosmographia scripting interface provides the following functions for capturing screenshots and recording videos:
Function
Description
saveScreenShot()
saves a screenshot to a file. The program will prompt the user to enter a file name when this function is invoked.
saveScreenShotToFile(file)
saves a screenshot to a file named file. The file name can be given with an absolute path or with a relative path to directory from which Cosmographia is launched.
setVideoRecordingResolution(res)
[4.0+] [OSX] sets the video recording resolution to res. The res can be “xga” (1024×768 pixels), “sxga” (1280×960 pixels), “720p” (1280×720 pixels), “1080p” (1920×1080 pixels), or “wqhd” (2560×1440 pixels). It is recommended to set the program window size to the same resolution using the setWindowResolution function.
startRecordingVideoToFile(file)
[4.0+] [OSX] starts recording video to a file named file. The file name can be given with an absolute path or with a relative path to the default directory for images and videos (e.g. ~/Pictures on OSX).
stopRecordingVideo()
[4.0+] [OSX] stops recording video.

Functions for Controlling Application/Window Settings

The Cosmographia scripting interface provides the following functions for controlling application and window settings:
Function
Description
set3DTextSize(size)
[4.1+] sets the 3D font size to “xsmall”, “small”, “medium”, “large”, or “xlarge”.
setFov(size,dur)
over dur CPU seconds, changes the camera FOV size (vertical extent) to be size degrees.
showToolBar()
shows the left toolbar.
hideToolBar()
hides the left toolbar.
minimizeWindow()
minimizes the Cosmographia window.
showFullScreen()
switches the Cosmographia window to the full screen mode.
showNormalWindow()
switches the Cosmographia window to the normal window mode.
setWindowResolution(res)
[4.0+] sets the program window size to res. The res can be “xga” (1024×768 pixels), “sxga” (1280×960 pixels), “720p” (1280×720 pixels), “1080p” (1920×1080 pixels), or “wqhd” (2560×1440 pixels). It is recommended to set the the video recording resolution to the same value using the setVideoRecordingResolution function.
quit()
makes the program quit.