**New viewer version**

This article and the other ones in the Viewer category of this website concern the **version 2** of the ShapeDiver viewer API. We have since released a version 3 of the viewer API which is documented in the new help center. All the information below is still relevant if you are using version 2 for legacy purposes. Keep in mind that by the end of 2022, maintenance for the version 2 will stop and no more updates or patches will be rolled out to this version. Consider reading our migration guide to version 3.

Designers can include data outputs in their ShapeDiver models which result from the computation of specific input parameters. Typical examples include weight or price calculations or bills of materials.

ShapeDiver models can contain different types of data, from simple types like numbers and strings to specific geometry primitives like points, lines and NURBS objects.

All the data contained in a model can be listed by calling *api.scene.getData()*. Results can also be filtered using the output names.

The next sections lists all the types of data outputs available in ShapeDiver models. They can all be tested in this model, by opening the console and calling getData().

# Available data outputs

Each data output contained in a model have a unique *id*, a *name* (created by the designer), a *plugin* property which indicates the plugin that originated the output (by default "CommPlugin_1") and a *data* property which contains the actual data item. See an example of number output:

{

id: "8677745a6137d64743db88d88a1520f1",

name: "NumberOutput",

plugin: "CommPlugin_1",

data: 45

}

We describe below the contents of the *data* property for each supported type.

## Simple types

The three following simple data types can exist in a ShapeDiver model. The data property only contains the value, with no data hint:

### Number

data: 0.5

### String

data: "Hello, World!"

### Points

data: [7.262389847872138, 5.778105791372726, 0]

## Complex types

For complex types, the output item does not only contain the data, but instead has two top-level properties:

*type*: Hint about the type of data contained in this output.*data*: Contains the actual data.

Here are the following complex data types which can exist in a ShapeDiver model:

### Interval

An interval of floating numbers (called Domain in Grasshopper).

data: {

type: "interval",

data: [0, 1]

}

### Color

data: {

type: "color",

data: [0, 34, 255]

}

### Line

A line is described by its two end points.

data: {

type: "line",

data: [

[-11, 45, 0],

[9, 24, 0]

]

}

### Plane

A plane is described by an array of three points. The first point is the origin of the plane, the next two describe the two basis vectors.

data: {

type: "plane",

data: [

[0, 0, 0],

[0, 1, 0],

[1, 0, 0]

]

}

### Box

A box is described by a plane and three domains - *extents* (see above for those data types). The plane's center and axes define the location and orientation of the box, and the three domains define the sizes of the box along each axis.

data: {

type: "box",

data: {

plane: [

[1, 2, 3],

[1, 0, 0],

[0, 1, 0]

],

extents: [

[0, 3],

[0, 3],

[-2, 2]

]

}

}

## NURBS Curve

Contains the full NURBS representation of a curve.

data: {

type: "nurbscurve",

data: {

knots: [0, 0, 0, 16.3, 32.6, 32.6, 32.6]

order: 4

pointcount: 5

points: [Array(3), Array(3), Array(3), Array(3), Array(3)]

rational: false

}

}

## NURBS Surface

Contains the full NURBS representation of a surface.

data: {

type: "nurbssurface",

data: {

knots_u: [0, 0, 0, 16.3, 32.6, 32.6, 32.6],

knots_v: [0, 0, 21.2, 21.2]

order: [4,3]

pointcount: [5,3]

points: Array(15) // array of points

rational: true,

weights: Array(15)

}

}

## Tranformation

A transformation is described by a 4x4 matrix.

data: {

type: "xform",

data: [

[0.573137855448987, 0.7403488404607821, -0.35127851212351696, 0],

[-0.6090066421373934, 0.6716445041915284, 0.42190587791811224, 0],

[0.5482918096086, -0.027879282947946227, 0.8358222520957643, 0],

[0, 0, 0, 1]

]

}

# Data structure

In Grasshopper, data can be organized in simple lists or trees with multiple branches. The data outputs from ShapeDiver models respect the list and tree structure used in the model, such that complex data flows can be implemented between the model and the online application.

Consider a data output with a single point:

`data: [1,2,3]`

Now an output with a list of points will simply contain an array of points in the data property:

`data: [[1,2,3],[4,5,6],[7,8,9]]`

Trees are a little more intricate. The API respects the representation of trees in Grasshopper: each branch of the tree is described by an array of numbers, starting from the root down to the smallest branches:

(source)

For example, the index {0;2;1} describes the ancestry of the considered branch (top branch with index 0, child with index 2, grand-child with index 1). Each branch can contain a single data item or a list of items.

In the API, if a data asset contains a tree output, it is represented by a list of objects with two properties:

*path*: An array describing the path to the current branch. For example, the branch {0;2;1} considered above would have a path property containing the array [0,2,1].*branch*: A data item or a list therefore describing the contents of this branch.

## Comments

0 comments

Please sign in to leave a comment.