Skip to main content
Platform
Language

Lifecycle

In this example, we will show you how to use the CreativeEditor SDK's CreativeEngine to modify scenes through the block API.

Setup#

This example uses the headless CreativeEngine. See the Setup article for a detailed guide. To get started right away, you can also access the block API within a running CE.SDK instance via cesdk.engine.block. Check out the APIs Overview to see that illustrated in more detail.

Only blocks that are direct or indirect children of a page block are rendered. Scenes without any page child may not be properly displayed by the CE.SDK editor.

Functions#

create(type: DesignBlockType): DesignBlockId

Create a new block, fails if type is unknown.

  • type: The type of the block that shall be created.
  • Returns The created blocks handle.

By default, the following blocks are available:

  • Page: //ly.img.ubq/page or page
  • Graphic: //ly.img.ubq/graphic or graphic
  • Text: //ly.img.ubq/text or text
  • Audio: //ly.img.ubq/audio or audio
  • Cutout: //ly.img.ubq/cutout or cutout

To create a scene, use scene.create instead.

saveToString(blocks: DesignBlockId[], allowedResourceSchemes?: string[]): Promise<string>

Saves the given blocks into a string. If given the root of a block hierarchy, e.g. a page with multiple children, the entire hierarchy is saved.

  • blocks: The blocks to save
  • Returns A promise that resolves to a string representing the blocks or an error.
saveToArchive(blocks: DesignBlockId[]): Promise<Blob>

Saves the given blocks and all of their referenced assets into an archive. The archive contains all assets that were accessible when this function was called. Blocks in the archived scene reference assets relative from to the location of the scene file. These references are resolved when loading such a scene via loadSceneFromURL.

  • blocks: The blocks to save
  • Returns A promise that resolves with a Blob on success or an error on failure.
loadFromString(content: string): Promise<DesignBlockId[]>

Loads existing blocks from the given string. The blocks are not attached by default and won't be visible until attached to a page or the scene. The UUID of the loaded blocks is replaced with a new one.

  • content: A string representing the given blocks.
  • Returns A promise that resolves with a list of handles representing the found blocks or an error.
loadFromArchiveURL(url: string): Promise<DesignBlockId[]>

Loads existing blocks from the given URL. The blocks are not attached by default and won't be visible until attached to a page or the scene. The UUID of the loaded blocks is replaced with a new one.

  • url: The URL to load the blocks from.
  • Returns A promise that resolves with a list of handles representing the found blocks or an error.
getType(id: DesignBlockId): ObjectTypeLonghand

Get the type of the given block, fails if the block is invalid.

  • id: The block to query.
  • Returns The blocks type.
setName(id: DesignBlockId, name: string): void

Update a block's name.

  • id: The block to update.
  • name: The name to set.
getName(id: DesignBlockId): string

Get a block's name.

  • id: The block to query.
getUUID(id: DesignBlockId): string

Get a block's UUID.

  • id: The block to query.
duplicate(id: DesignBlockId): DesignBlockId

Duplicates a block including its children. Required scope: 'lifecycle/duplicate'

  • id: The block to duplicate.
  • Returns The handle of the duplicate.
destroy(id: DesignBlockId): void

Destroys a block. Required scope: 'lifecycle/destroy'

  • id: The block to destroy.
isValid(id: DesignBlockId): boolean

Check if a block is valid. A block becomes invalid once it has been destroyed.

  • id: The block to query.
  • Returns True, if the block is valid.