Managing Annotation Objects

Below we will consider the commands that allow to add and remove annotation objects to/from a scene.

Adding Object

Example of adding a Comment object (TypeScript):

view.runCommand({
    name: "AddAnnotation",
    objs: [
        {
            type: C3DViewObjectTypes.Comment, // "Comment"
            uuid: '<UUID>',
            targetUuid: '<targetUUID>',
            points: {
                target: {
                    x: 10,
                    y: 10,
                    z: 0,
                },
                shelf: {
                    x: 120,
                    y: 10,
                    z: 0,
                },
            },
            options: {
                text: 'Comment text',
            },
        }
    ]
})

The command contains objs parameter which is an array of added objects. Each object type has its own type of representation. You can find all of them here.

The command returns a objects that contains a asynchronous property for a UUID list getting.

Add annotations result type (TypeScript):

type AddAnnotationResult = {
    name: api.ResultTypes.AnnotationUUID, // "AnnotationUUID"
    result: Promise<string[]>
}

This command may be used for a updating the objects if a used uuid already belongs other object.

Add the new sphere object with UUID receiving example code (TypeScript):

const command = view.runCommand({
    name: "AddAnnotation",
    objs: [
        {
            type: "Sphere",
            center: {x: 10, y: 0, z: 0},
            radius: 30,
            options: {
                fill: {r: 255, g: 0, b: 0},
            },
        }
    ]
})
if (command.name !== "AnnotationUUID")
    console.error("Invalid command result: ", command.name)
command.result.then((uuids: string[]) => {
    const uuid = uuids.pop()
    console.log(`Added a sphere with UUID "${uuid}".`)
})

New in version 1.6.0: uuid is optional parameter for objects. The new uuid will generate without it.

AddAnnotation command asynchronous returns a UUID list in the same order as received objs.

Removing Object

Example of removing annotation objects (TypeScript):

view.runCommand({
    name: "DeleteAnnotation",
    objs: ['<UUID1>', '<UUID2>', '<UUID3>']
})

The example command removes objects with UUIDs passed in the objs parameter.

Important

Running a command without objs parameter (even with just empty array) will delete all annotation objects from a scene.