Developer Documentation
OpenFlipper Scripting and Batch Mode

OpenFlipper Batch mode

OpenFlipper can be started in batch mode without a graphical user interface by providing "-b" as a command line option. Furthermore you have to provide an OpenFlipper script (extension is .ofs), which will get executed. To get output to the command line, you also have to provide the command line switch "-c". Only plugins which support batch mode ( They implement an nogui() function ), will be loaded. For example, no renderers, postprocessors or other plugins providing only user interface or graphical functionality will be loaded. You can see on the command line (when "-c" is given), which plugins are activated and which are skipped in batch mode.

Iterating over objects

In the scripting system you can also iterate over objects in the scene.

// Get a list of all target triangle meshes in the scene
var list = datacontrol.getTargetObjects(DataType("TriangleMesh"));
// Print the names of all target objects
for( object in list )
{
print(datacontrol.getObjectName(list[object]))
}

DataTypes

In the scripting system the type DataType is already known. You can do for example

DataType("TriangleMesh");

You can get a string list with all available data types via

// Get the string list of data types via DataControl Plugin
var types = datacontrol.availableDataTypeNames();

Getting the DataType of an Object

// Set the object id
var object = 5;
// Get the DataTypes and print its name. the DataType is returned by the function
print(datacontrol.dataType(object))

Getting the Id of an Object

Openflipper provides functions gathering the id of an object. Also, some functions create an object and return its id. Some examples:

//Various ways of gathering id and or name of an object
var objectId = core.loadObject(QString) //generate an object and returns its Id
var objectId2 = core.getObjectId(QString) // returns Id by object name
var objectName = datacontrol.getObjectName(int) // returns object name by Id
var objectList = datacontrol.getTargetObjects(DataType) // returns IdList of all target objects
var objectId3 = primitivesgenerator.addPyramid() //generate an object and returns its Id
...

Vector data type

The Vec3d used in the C++ code is mapped to the scripting language. Details can be found here: Vector data type for scripting

Vector4 data type

The Vector4d data type is corresponding to the Vec4d type in C++. It is mostly used for colors. Details can be found here: Vector4d data type for scripting

Matrix data type

The Matrix4x4T type used in the C++ code is mapped to the scripting language. Details can be found here: Matrix data type used for scripting

IdList type

Some functions can perform the same operation on several objects or give multiple objects back. The Id's of these objects are saved in a IdList. This is a simple list of integer containing the id's. Example code:

//Assume, "Object 1" and "Object 2" are already created or loaded
var id1 = core.getObjectId("Object 1")
var id2 = core.getObjectId("Object 2")
var list = [id1,id2]
datacontrol.groupObjects(list)

QVariantMap type

The QVariantMap type is used by some function as input. A QVariantMap is similar to a map with key and value, where the types of the key and value is not defined. Mostly, the keys are strings describing the property where the value type is of type int. Example code:

// creating a scripting object
var constraints = new Object()
// filling the QVariantMap
constraints["decimater_type"] = 0
constraints["decimation_order"] = 0
constraints["vertices"] = 50
// load e.g. mesh object
var id = core.loadObject("MyTriangleMesh.obj")
// perform decimation
decimater.decimate(id,constraints)

Miscellaneous

How to get the path of the current script?

// The path of the currently executed script is stored in the ScriptPath variable.
print(ScriptPath)

Can i include additional script files?

Yes, just use the keyword include. You can also use paths relative to the current script. The scripts will be joined internally so variables are available across the scripts.

// Include with full path:
include <Path/script1.ofs>
// Relative to current script:
include <ScriptPath/script2.ofs>

Scripting Examples

Iterating over a QStringList

// Get the string list of data types via DataControl Plugin
var types = datacontrol.availableDataTypeNames();
// Iterate over the list and print to the console
for ( i = 0 ; i < types.length ; ++i ) {
print(types[i]);
}