Using Tools from Scripts
Boxshot provides a number of tools and you can use them from scripts, too. Click the link below to jump to the code:
- Fit to View
- Put on the Floor
- Center Camera on Selection
- Group Selection
- Align
- Distribute
- Stack
- Step and Repeat
- Copy Materials
- Convert to Embedded Model
Fit to View
var params = {
padding : 0.1,
keepAspect : false
};
tools.fitToView(params);
Put on the Floor
tools.putOnTheFloor();
Center Camera on Selection
tools.centerCameraOnSelection();
Group Selection
tools.groupSelection();
Alignment Tool
var params = {
alignment: 1,
keyObject: 0,
actionX: 1,
actionY: 0,
actionZ: 0,
};
tools.align(scene.selection, params);
You pass indices in all the parameters, the indices must match the dropdown options you see in the tool window. For alignment these are:
- 0 — align to selection;
- 1 — align to key object;
- 2 — align to scene.
For actions the options are:
- 0 — leave as is;
- 1 — align minimums;
- 2 — align centers;
- 3 — align maximums.
Key object index must be a valid index inside the objects list passed as the first parameter to the align() method.
Distribution Tool
var params = {
distribute: 3,
axis: 0,
alignment: 2,
distance: 3
};
tools.distribute(scene.selection, params);
You pass indices in most of the parameters, the indices must match the dropdown options you see in the tool window. For distribute these are:
- 0 — distribute minimums;
- 1 — distribute centers;
- 2 — distribute maximums;
- 3 — distribute free space.
For axis these are obvious:
- 0 — X axis;
- 1 — Y axis;
- 2 — Z axis.
Finally, for alignment these are:
- 0 — distribute in selection bounds;
- 1 — distribute in scene bounds;
- 2 — distribute using the distance specified.
Stack Tool
tools.stack(scene.selection, {});
It gives you a stack of 3 items of the currently selected object, if the object supports stacking. The first parameter is a node (or array of nodes), while the second parameter is a dictionary of stack properties:
- repeats
- seed
- twistStep
- twistDisorder
- offsetX
- offsetY
- offsetDisorder
All the properties work exactly as in the user interface. Here is a more detailed sample:
var params = {
repeats: 5,
twistStep: 2,
offsetDisorder: 0.1
};
tools.stack(scene.selection, params);
Step and Repeat
tools.stepAndRepeat(scene.selection, {});
It clones the selected shape with default settings. You can adjust the settings, if you like by providing them in the dictionary passed as a second parameter. Here is the list of properties:
- repeatsLeft
- repeatsRight
- repeatsFront
- repeatsBack
- repeatsUp
- repeatsDown
- offsetX
- offsetY
- offsetZ
All the properties work exactly as in the user interface. Here is a more detailed sample:
var params = {
repeatLeft: 0,
repeatRight: 0,
repeatsFront: 0,
repeatsBack: 1,
repeatsUp: 2,
repeatsDown: 1,
offsetX: 0,
offsetY: 0,
offsetZ: 1
};
tools.stepAndRepeat(scene.selection, params);
Copy Materials
var src = scene.selection[0]
var mtls = ["Front", "Back"];
var targets = [scene.selection[1], scene.selection[2]]
tools.copyMaterials(src, mtls, targets);
The first parameter is the source node, then goes the array of material names to copy and finally comes the array of target nodes to apply the materials.
Convert to Embedded Model
var src = scene.selection[0]
tools.convertToEmbeddedModel(src);
More Scripting Tutorials
- Scripting Overview — basic information about Boxshot scripting;
- Managing Objects — navigating and manipulating Boxshot scene;
- Special Objects — working with cameras, lights, materials etc;
- Shapes — configuring built–in shapes;
- Tools — using Boxshot tools from scripts;
- Using Command Line — running Boxshot scripts from command line.