LayerUtils

class omni.kit.widget.layers.LayerUtils

Bases: object

LayerUtils provides utilities for operating layers.

Methods

create_checkpoint(layer_identifier, comment)

create_checkpoint_async(layer_identifier, ...)

create_checkpoint_for_stage_async(stage, comment)

create_sublayer(layer, sublayer_position, ...)

Creates new sublayer at specific position.

get_all_sublayers(stage[, ...])

get_custom_layer_name(layer)

Gets the custom name of layer.

get_dirty_layers(stage[, ...])

get_edit_target(stage)

get_layer_global_muteness(root_layer, ...)

get_layer_lock_status(root_layer, ...)

get_sublayer_identifier(layer_identifier, ...)

Gets the sublayer identifier at specific postion with validality.

get_sublayer_position_in_parent(...)

Gets the sublayer position in the parent layer.

has_prim_spec(layer_identifier, prim_spec_path)

insert_sublayer(layer, sublayer_position, ...)

Inserts new sublayer at specific position.

is_layer_writable(layer_identifier)

Checks if layer is a writable format or writable on the file system.

move_layer(from_parent_layer_identifier, ...)

Move sublayer from source parent to position of target parent.

reload_all_layers(layer_identifiers)

Reloads all layers in batch.

remove_layer_global_muteness(root_layer, ...)

remove_layer_lock_status(root_layer, ...)

remove_prim_spec(layer, prim_spec_path)

Utility to remove prim spec from layer.

remove_sublayer(layer, position)

replace_sublayer(layer, sublayer_position, ...)

Replaces new sublayer at specific position.

resolve_paths(base_layer, target_layer[, ...])

Resolve all paths from References, Sublayers and AssetPaths of target layer based on source layer.

restore_authoring_layer_from_custom_data(stage)

restore_muteness_from_custom_data(stage)

save_authoring_layer_to_custom_data(stage)

set_custom_layer_name(layer, name)

Sets the custom name of layer, or clear it if name is empty or None.

set_edit_target(stage, layer_identifier)

set_layer_global_muteness(root_layer, ...)

set_layer_lock_status(root_layer, ...)

transfer_layer_content(source_layer, ...[, ...])

Transfer layer content from source layer to target layer with re-pathing all external dependencies.

Attributes

LAYER_AUTHORING_LAYER_CUSTOM_KEY

LAYER_LOCK_STATUS_CUSTOM_KEY

LAYER_MUTENESS_CUSTOM_KEY

LAYER_NAME_CUSTOM_KEY

LAYER_OMNI_CUSTOM_KEY

__init__()
static create_sublayer(layer: Layer, sublayer_position: int, layer_identifier: str)

Creates new sublayer at specific position.

Parameters
  • layer (Sdf.Layer) – Layer handle.

  • sublayer_position – Position to create the new layer. Position should be -1 (the last position) or above 0. If position == -1 or position > len(layer.subLayerPaths), it will create the sublayer at the end. Any other position will be treated as invalid index.

  • layer_identifier – New layer path. If it’s empty or None, it will create anonymous layer.

Returns

New sublayer handle or None if sublayer_position is not valid.

static get_custom_layer_name(layer: Layer)

Gets the custom name of layer. This name is saved inside the custom data of layer.

static get_sublayer_identifier(layer_identifier: str, sublayer_position: int)

Gets the sublayer identifier at specific postion with validality.

Parameters
  • layer_identifier (str) – Parent layer identifier.

  • sublayer_position (int) – Position of sublayer. It must be -1, which means to

  • 0. (return the last item. Or it should be equal or above) –

Returns

None if sublayer_position is invalid or overflow. Or sublayer identifier otherwise.

static get_sublayer_position_in_parent(parent_layer_identifier: str, layer_identifier: str)

Gets the sublayer position in the parent layer.

Parameters
  • parent_layer_identifier (str) – Parent layer identifier.

  • layer_identifier (str) – layer identifier to query.

Returns

Position of layer in the subLayerPaths of the parent, or -1 if it cannot be found.

static insert_sublayer(layer: Layer, sublayer_position: int, layer_identifier: str, check_empty_layer=True)

Inserts new sublayer at specific position.

Parameters
  • layer (Sdf.Layer) – Layer handle.

  • sublayer_position – Position to insert the new layer. Position should be -1 (the last position) or above 0. If position == -1 or position > len(layer.subLayerPaths), it will insert the sublayer at the end. Any other position will be treated as invalid index.

  • layer_identifier – New layer path.

Returns

Sublayer handle or None if sublayer_position is not valid or layer_identifier is empty or inserted layer is not existed.

static is_layer_writable(layer_identifier) bool

Checks if layer is a writable format or writable on the file system.

static move_layer(from_parent_layer_identifier, from_sublayer_position, to_parent_layer_identifier, to_sublayer_position, remove_source=False)

Move sublayer from source parent to position of target parent.

Parameters
  • from_parent_layer_identifier – The parent of source sublayer.

  • from_sublayer_position – The sublayer position to be moved.

  • to_parent_layer_identifier – The parent of target sublayer.

  • to_sublayer_position – The sublayer position in target parent that source moves to.

  • remove_source – Removes the source sublayer or not from source parent after move. If from_parent_layer_identifier == to_parent_layer_layer_identifier, it will always be True.

Returns

True if it’s successful, False otherwise,

static reload_all_layers(layer_identifiers: Union[str, List[str]])

Reloads all layers in batch.

static remove_prim_spec(layer: Layer, prim_spec_path: Union[str, Path])

Utility to remove prim spec from layer.

Parameters
  • layer (Sdf.Layer) – Layer handle.

  • prim_spec_path (Union[str, Sdf.Path]) – Path of prim spec.

Returns

True if success, or False otherwise.

static replace_sublayer(layer: Layer, sublayer_position: int, layer_identifier: str)

Replaces new sublayer at specific position.

Parameters
  • layer (Sdf.Layer) – Layer handle.

  • sublayer_position – Position to insert the new layer. Position should be less than len(layer.subLayerPaths). Any other position will be treated as invalid index.

  • layer_identifier – New layer path.

Returns

Sublayer handle or None if sublayer_position is not valid or layer_identifier is empty or replaced layer is not existed.

static resolve_paths(base_layer: Layer, target_layer: Layer, store_relative_path=True, relative_to_base_layer=False, copy_sublayer_offsets=False)

Resolve all paths from References, Sublayers and AssetPaths of target layer based on source layer. This function is used normally when you transfer the content from source layer to target layer that are not in the same directory. So it needs to resolve all references so that they point to correct location.

Parameters
  • base_layer (Sdf.Layer) – Source layer that references in target layer based on.

  • target_layer (Sdf.Layer) – Target layer to resolve.

  • store_relative_path (bool) – True to store relative path, or False to store absolute path. if relative path cannot be computed (like source layer and target are not in the same domain), it will save absolute paths.

  • relative_to_base_layer (bool) – True if the relative path is computed against the target_layer. False otherwise.

  • copy_sublayer_offsets (bool) – True to copy sublayer offsets and scales from base to target.

static set_custom_layer_name(layer: Layer, name: str)

Sets the custom name of layer, or clear it if name is empty or None. The name is saved inside the custom data of layer and can only be consumed by Kit application.

static transfer_layer_content(source_layer: Layer, target_layer: Layer, copy_custom_data=True, skip_sublayers=True)

Transfer layer content from source layer to target layer with re-pathing all external dependencies.

Parameters
  • source_layer (Sdf.Layer) – Source layer handle.

  • target_layer (Sdf.Layer) – Target layer handle.

  • copy_custom_data (bool) – Whether copying layer metadata or not.

  • skip_sublayers (bool) – Whether skipping to copy sublayers or not if copy_custom_data is True.