From MechJebWiki
Jump to: navigation, search

Run API commands in the command line or scripts


Command line

All the commands seen on this page can also be used within the commandline, this can be useful while trying out different functions

How to use Lua Files:

To use lua files place them in


and while in game just enter the command dofile("YOURSCRIPTNAMEHERE")

This loads your file and you can now use functions within it.

This can be done to refresh the file during debugging.


function FlyMeToTheMunDriver(lat, lon)
    print "Launching..."
    mechjeb.launchTo(125000, 0)
    print "TMI..."
    mechjeb.transfer("Mun", 200000)
    print "Warping to SoI..."
    print "Warping to Pe..."
    mechjeb.warpToEvent("pe", 30)
    print "Circularizing orbit..."
    print "Landing..."
    if (lat == nil or lon == nil) then
        mechjeb.landAt(0, 0)
        mechjeb.landAt(lat, lon)
    print "Landed!"

function FlyMeToTheMun(lat, lon)
    local co = coroutine.create(FlyMeToTheMunDriver)
    coroutine.resume(co, lat, lon)

print "Usage: FlyMeToTheMun(lat, lon)"

Coroutine function template

function MyFunDriver()
    -- your code here

function MyFun()
    local co = coroutine.create(MyFunDriver)

API Commands

mechjeb - General vessel control

mechjeb.landAt(double latitude, double longitude, optional boolean autoWarpOnDescent)

Activates the Landing Autopilot module, and land at the selected coordinates.

mechjeb.launchTo(double altitude, double inclination)

Activates the Ascent Autopilot module, and launches to the selected altitude and inclination.

mechjeb.transfer(string body, double final_periapsis)

Activates the Orbital Operations module, and perform a transfer operation to the selected body, at the specified final periapsis.

mechjeb.warpToEvent(string event, optional double lead_time)

Activates the Orbital Operations module, and perform a warp operation to the selected event ("Pe", "Ap", "SoI"), with an optional lead time in seconds.


Activates Autostaging


Deactivates Autostaging

mechjeb.attitudeTo(table/string direction, string reference)

Activates the Smart A.S.S. module, orienting the vessel to the selected direction on the selected reference.

direction can be either a string ("left", "right", "up", "down", "forward", "back") or a vector {x, y, z}

reference is one of:

  • "INERTIAL" - world coordinate system.
  • "ORBIT" - forward = prograde, left = normal plus, up = radial plus
  • "ORBIT_HORIZONTAL" - forward = surface projection of orbit velocity, up = surface normal
  • "SURFACE_NORTH" - forward = north, left = west, up = surface normal
  • "SURFACE_VELOCITY" - forward = surface frame vessel velocity, up = perpendicular component of surface normal
  • "TARGET" - forward = toward target, up = perpendicular component of vessel heading
  • "RELATIVE_VELOCITY" - forward = toward relative velocity direction, up = tbd
  • "TARGET_ORIENTATION" - forwad = direction target is facing, up = target up

boolean mechjeb.busy()

Returns true if MechJeb is currently busy, false otherwise.

mechjeb.changeAp(double apoapsis)

Activates the Orbital Operations module, and perform a Change Ap operation to the selected apoapsis.

mechjeb.changeApAndPe(double apoapsis, double periapsis)

Activates the Orbital Operations module, and perform a Change Ap and Pe operation to the selected apoapsis and periapsis.

mechjeb.changePe(double periapsis)

Activates the Orbital Operations module, and perform a Change Pe operation to the selected periapsis.


Activates the Orbital Operations module, and perform a Circularize operation.

The opposite of mechjeb.busy(). Returns true if MechJeb is currently not busy, false otherwise.

Land as soon as possible

vessel - Access to vessel information (direct access to VesselState)

Here is a current list of all available variables, documentation will follow soon.

  • vessel.time
  • vessel.deltaT
  • vessel.CoM
  • vessel.MoI
  • vessel.up
  • vessel.north
  • vessel.east
  • vessel.forward
  • vessel.rotationSurface
  • vessel.rotationVesselSurface
  • vessel.velocityMainBodySurface
  • vessel.velocityVesselSurface
  • vessel.velocityVesselSurfaceUnit
  • vessel.velocityVesselOrbit
  • vessel.velocityVesselOrbitUnit
  • vessel.angularVelocity
  • vessel.angularMomentum
  • vessel.upNormalToVelSurface
  • vessel.upNormalToVelOrbit
  • vessel.leftSurface
  • vessel.leftOrbit
  • vessel.gravityForce
  • vessel.localg
  • vessel.speedOrbital
  • vessel.speedSurface
  • vessel.speedVertical
  • vessel.speedHorizontal
  • vessel.vesselHeading
  • vessel.vesselPitch
  • vessel.vesselRoll
  • vessel.altitudeASL
  • vessel.altitudeTrue
  • vessel.altitudeBottom
  • vessel.orbitApA
  • vessel.orbitPeA
  • vessel.orbitPeriod
  • vessel.orbitTimeToAp
  • vessel.orbitTimeToPe
  • vessel.orbitLAN
  • vessel.orbitArgumentOfPeriapsis
  • vessel.orbitInclination
  • vessel.orbitEccentricity
  • vessel.orbitSemiMajorAxis
  • vessel.latitude
  • vessel.longitude
  • vessel.radius
  • vessel.mass
  • vessel.thrustAvailable
  • vessel.thrustMinimum
  • vessel.maxThrustAccel
  • vessel.minThrustAccel
  • vessel.torqueRAvailable
  • vessel.torquePYAvailable
  • vessel.torqueThrustPYAvailable
  • vessel.massDrag
  • vessel.atmosphericDensity