To indicate that you wish to use the JavaScript Scripting Engine you need to put '//javascript' at the first line of the script. JavaScript is also the default language that tutorials and macros are recorded in. Then, the easiest way to write the skeleton of a script is to use 'Record Macro Script' in the 'Tools' menu and run K-3D as user: all actions will be recorded and shown in the 'Macro Recorder' window.
A script can be executed in one of three different "contexts":
global : Application Window > Tools > Play Script
a script executed in global context is not "associated" with any specific document. In order to work with a specific document, such a script would have to: 1) create a new document 2) open an existing document 3) choose from amongst the current set of open documents, would could be zero-to-many.
document : Document Window > Tools > Play Script
a script executed in document context *is* associated with a specific document. In the current JavaScript engine, a script running in document context can access its document as "MyDocument", which is a property of the global object.
object : Document Window > Hierarchy Tab > Object Context Menu > Play Script
a script executed in object context is associated with a specific object. In the current JavaScript engine, this object will be accessible as "MyObject", again a property of the global object. Same story as above for other engines. Note: the ultimate purpose for having object context is so we can "embed" scripts in objects and give them scripted behavior.
Here follows a list of available objects:
The JavaScript File I/O objects add rudimentary file I/O capabilities to the JavaScript object model. They are designed to provide a subset of the iostreams capabilities from the C++ standard library:
Wraps an input file stream.
The Documents property returns an array containing the set of open Document objects.
Displays an informational message in a non-modal dialog box.
Displays an error message in a non-modal dialog box.
Prompts the user to choose from an array of selections in a modal dialog box.
Prompts the user for a filepath, checking for old choices, and storing the current choice for reuse. The following are common arguments to Type, although any string is valid:
- renderfarm
- script
- document
- geometry
- log
- font
- renderframe
Imports a geometry file into the document, using the given file format.
Exports the document to a geometry file, using the given file format.
Render a single frame.
maincamera = Document.Objects.Create("Camera"); maincameraobject = maincamera.Camera; maincameraobject.RenderFrame("/tmp/myimage.tiff", true);
Property to set and get object orientation. Array has four (4) elements. The first is the angle and the rest XYZ values.