Command

The command class allows you to interact with X-Plane via commands. The simple idea is that you create a Command object and then use it throughout your program to activate that command.

XPyDeck assumes that all your activations of the command will be for 0 seconds. In other words, the command will be activated without any duration, like the push of a button. However, this works for such a use case, as the command can be continuously called while, say, a button is pressed, and will thus function as though there was one call of the command for the duration the button was pressed.

Import

The Command class is in the XPyDeck library, so you import it in main.py with from XPyDeck import Command.

Constructor

ConstructorDescription
Command(net:Network,name:str)Creates a command object using the Network object you created earlier and the name of the command, eg sim/flight_controls/landing_gear_down.

Functions

All functions are non-static, so an example call would be: gearDown.activate().

MethodDescriptionOutput/Return
activate()Activates/performs the command.Returns True if the request to activate the command was successfully sent. Returns False if there was an exception in sending the request. The exception can be accessed with .latestException

Instance Variables

VariableDescription
latestExceptionThe latest exception in sending the request to activate the command. See above. None if there no exceptions have been encountered.
❗️

Note that even if there is no exception in sending the request to activate the command, the command can still fail to activate in X-Plane; no exception only means that the request was successfully sent to the script running on your computer, not X-Plane.

Example Code Snippet

from XPyDeck import Network, Command

net = Network() # See Network docs

gearDown = Command(net, "sim/flight_controls/landing_gear_down")

gearDown.activate() # True if successful

if gearDown.latestException == None:
  print("Request sent to activate command")
else:
	print(f"Exception in sending request: {gearDown.latestException}")
👍

You don't really need to ensure that the request to activate the command was sent successfully as most of the time you activate a command will be in a loop. However, if you need to make sure the command was sent or if the activate call is not in a loop, this may be handy.