The UI.Include() method allows you to include and execute code from external .cs files within your Launchpad scripts. This enables reuse code and organize your scripts more easily.
Methods
Use the following methods to include a script file (.cs) inside another script file.
UI.Include(filename)
Includes and executes a .cs file in the current script context.
Parameters:
filename (string): The path to the .cs file to include (relative or absolute)
Attempts to include a file and returns true if successful, false otherwise.
Parameters:
filename (string): The path to the .cs file to include
Returns:
bool: True if the file was successfully included, false otherwise
Example:
UI.SetIncludePath(directory)
Sets the default directory where UI.Include() will look for files when using relative paths. This is primarily used in Launchpad Command and Launchpad App where scripts don't have an associated file path.
Parameters:
directory (string): The directory path to use as the base for relative includes
Example:
UI.GetIncludePath()
Gets the current default include directory.
Returns:
string: The current include path, or null if not set
Example:
Usage
In Launchpad Explorer
When running scripts through Launchpad Explorer, the include system automatically knows the location of your script file. You can use simple relative paths.
In Launchpad Command or App
When typing code directly (not running from a file), you need to either:
if (UI.TryInclude("OptionalHelpers.cs"))
{
Console.WriteLine("Optional helpers loaded"); // Use optional helper methods
}
else
{
Console.WriteLine("Optional helpers not available, using defaults"); // Fall back to default behavior
}
UI.SetIncludePath(@"C:\MyScripts\Common");
UI.Include("Utils.cs"); // Will look in C:\MyScripts\Common\Utils.cs
// Your capsule structure:
// MyCapsule
/// Scripts
/// MainScript.cs <- You are here
// Utils.cs
// Helpers
/// GeometryHelpers.cs
// Include files in the same directory
UI.Include("Utils.cs");
// Include files in subdirectories
UI.Include("Helpers/GeometryHelpers.cs");
// Set the base directory for includes
UI.SetIncludePath(@"C:\MyScripts");
// Now use relative paths
UI.Include("Utils.cs");
UI.Include("Common/Constants.cs");