Clipboard

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts

The Clipboard API enables you to export and import entities to and from JSON files.

Methods

Name Return Value Summary
exportEntities boolean

Exports specified entities to a JSON file.

exportEntities boolean

Exports all entities that have centers within a cube to a JSON file.

getClipboardContentsLargestDimension number

Gets the largest dimension of the extents of the entities held in the clipboard.

getContentsDimensions Vec3

Gets the extents of the entities held in the clipboard.

importEntities boolean

Imports entities from a JSON file into the clipboard.

pasteEntities Array.<Uuid>

Pastes the contents of the clipboard into the domain.

Method Details

(static) exportEntities( filename, entityIDs ) → {boolean}
Returns: true if entities were found and the file was written, otherwise false.

Exports specified entities to a JSON file.

Parameters

Name Type Description
filename string

Path and name of the file to export the entities to. Should have the extension ".json".

entityIDs Array.<Uuid>

The IDs of the entities to export.

Example

Create and export a cube and a sphere.

// Create entities.
var box = Entities.addEntity({
    type: "Box",
    position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: -0.2, y: 0, z: -3 })),
    lifetime: 300 // Delete after 5 minutes.
});
var sphere = Entities.addEntity({
    type: "Sphere",
    position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0.2, y: 0, z: -3 })),
    lifetime: 300 // Delete after 5 minutes.
});

// Export entities.
var filename = Window.save("Export entities to JSON file", Paths.resources, "*.json");
if (filename) {
    Clipboard.exportEntities(filename, [box, sphere]);
}
(static) exportEntities( filename, x, y, z, scale ) → {boolean}
Returns: true if entities were found and the file was written, otherwise false.

Exports all entities that have centers within a cube to a JSON file.

Parameters

Name Type Description
filename string

Path and name of the file to export the entities to. Should have the extension ".json".

x number

X-coordinate of the cube center.

y number

Y-coordinate of the cube center.

z number

Z-coordinate of the cube center.

scale number

Half dimension of the cube.

(static) getClipboardContentsLargestDimension( ) → {number}
Returns: The largest dimension of the extents of the content held in the clipboard.

Gets the largest dimension of the extents of the entities held in the clipboard.

(static) getContentsDimensions( ) → {Vec3}
Returns: The extents of the content held in the clipboard.

Gets the extents of the entities held in the clipboard.

Example

Import entities to the clipboard and report their overall dimensions.

var filename = Window.browse("Import entities to clipboard", "", "*.json");
if (filename) {
    if (Clipboard.importEntities(filename)) {
        print("Clipboard dimensions: " + JSON.stringify(Clipboard.getContentsDimensions()));
    }
}
(static) importEntities( filename, isObservableopt, callerIDopt ) → {boolean}
Returns: true if the import was successful, otherwise false.

Imports entities from a JSON file into the clipboard.

Parameters

Name Type Attributes Default Value Description
filename string

The path and name of the JSON file to import.

isObservable boolean <optional>
true

true if the ResourceRequestObserver can observe this request, false if it can't.

callerID number <optional>
-1

An integer ID that is passed through to the ResourceRequestObserver.

Example

Import entities and paste into the domain.

var filename = Window.browse("Import entities to clipboard", "", "*.json");
if (filename) {
    if (Clipboard.importEntities(filename)) {
        pastedEntities = Clipboard.pasteEntities(Vec3.sum(MyAvatar.position,
            Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -3 })));
        print("Entities pasted: " + JSON.stringify(pastedEntities));
    }
}
(static) pasteEntities( position, entityHostTypeopt ) → {Array.<Uuid>}
Returns: The IDs of the new entities that were created as a result of the paste operation. If entities couldn't be created then an empty array is returned.

Pastes the contents of the clipboard into the domain.

Parameters

Name Type Attributes Default Value Description
position Vec3

The position to paste the clipboard contents at.

entityHostType Entities.EntityHostType <optional>
"domain"

The type of entities to create.