import(path)
The import()
function loads and evaluates OSL code from another file, making its contents available to the current script. This function supports importing both local files and package files.
Syntax
Parameters
filename
: String - The name or path of the file to import. If the filename doesn't contain a '.', the '.osl' extension will be added automatically.
Return Value
Returns the exported data from the imported file, which can be any valid OSL value (object, array, function, etc.).
Description
The import()
function loads and executes OSL code from an external file, allowing you to:
Organize your code into modules
Reuse code across multiple scripts
Share functionality between different parts of your application
Load dynamically selected scripts at runtime
The function supports two main import paths:
Local files in the current workspace
Package files from the packages directory
Examples
Basic Usage
Importing Without Extension
Importing from Packages
Conditional Importing
Using Imported Data
Notes
Imported files are executed in their own scope
If a file doesn't exist or can't be loaded, an empty object is returned
The import path is resolved relative to the current script's location
For package imports, the file is loaded from the user's packages directory
The function handles path resolution automatically, using the
parseFilePath
function internally
Last updated
Was this helpful?