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

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:

For actions the options are:

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:

For axis these are obvious:

Finally, for alignment these are:


 

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:

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:

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