Skip to content

ops

ops

USD operations run by Nyx nodes in an interpreter that has pxr.

Plain functions that take and return JSON data. Nothing here imports Nyx or the bridge, so the package works in any application shipping pxr (an OpenUSD build, Maya, Houdini, Blender).

A stage is identified by the identifier of its root layer, a string. The opened stages are kept in this package until they are closed, so one node can edit what the previous one opened. They stay open until close_stage or close_all, or the process ends.

The nodes call nyx_usd.ops.<name>, so every operation is imported here.

Attributes

__all__ = ['add_inherit', 'add_payload', 'add_prim', 'add_reference', 'add_sublayer', 'add_variant_set', 'bind_material', 'close_all', 'close_stage', 'copy_prim', 'create_cube', 'create_material', 'create_mesh', 'create_sphere', 'create_stage', 'export_to_string', 'find_prims', 'flatten_stage', 'get_attribute', 'get_attribute_at_time', 'get_bounding_box', 'get_children', 'get_parent', 'get_prim_metadata', 'get_prim_type', 'get_stage_info', 'get_stage_metadata', 'get_time_range', 'get_time_samples', 'get_transform', 'get_variants', 'get_world_transform', 'has_prim', 'list_attributes', 'list_prims', 'list_sublayers', 'move_prim', 'open_stage', 'remove_attribute', 'remove_prim', 'remove_sublayer', 'rename_prim', 'save_stage', 'set_active', 'set_attribute', 'set_attribute_at_time', 'set_default_prim', 'set_fps', 'set_kind', 'set_meters_per_unit', 'set_prim_metadata', 'set_purpose', 'set_stage_metadata', 'set_time_range', 'set_transform', 'set_up_axis', 'set_variant_selection', 'set_visibility'] module-attribute

Functions:

add_inherit(stage, prim_path, class_path)

Make a prim inherit from a class prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
class_path str

path of the class prim, like /_class_asset.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def add_inherit(stage: str, prim_path: str, class_path: str) -> str:
    """Make a prim inherit from a class prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        class_path (str): path of the class prim, like `/_class_asset`.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: handle of the stage.
    """
    get_prim(stage, prim_path).GetInherits().AddInherit(Sdf.Path(class_path))
    return stage

add_payload(stage, prim_path, asset_path, target_prim='')

Add a payload of a USD file to a prim, defining the prim if needed.

A payload is a reference that can be left unloaded.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
asset_path str

file to load.

required
target_prim str

prim of the file to load, its default prim if empty.

''

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def add_payload(
    stage: str, prim_path: str, asset_path: str, target_prim: str = ""
) -> str:
    """Add a payload of a USD file to a prim, defining the prim if needed.

    A payload is a reference that can be left unloaded.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        asset_path (str): file to load.
        target_prim (str): prim of the file to load, its default prim if empty.

    Returns:
        str: handle of the stage.
    """
    prim = get_stage(stage).DefinePrim(Sdf.Path(prim_path))
    if target_prim:
        prim.GetPayloads().AddPayload(asset_path, Sdf.Path(target_prim))
    else:
        prim.GetPayloads().AddPayload(asset_path)
    return stage

add_prim(stage, prim_path, type_name='Xform')

Define a prim, creating the prims above it as needed, without a type.

Define a parent first to give it a type, like Xform: an untyped prim can't be transformed.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim, like /World/cube.

required
type_name str

schema type of the prim, like Xform or Mesh.

'Xform'

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def add_prim(stage: str, prim_path: str, type_name: str = "Xform") -> str:
    """Define a prim, creating the prims above it as needed, without a type.

    Define a parent first to give it a type, like `Xform`: an untyped prim can't be
    transformed.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim, like `/World/cube`.
        type_name (str): schema type of the prim, like `Xform` or `Mesh`.

    Returns:
        str: handle of the stage.
    """
    get_stage(stage).DefinePrim(Sdf.Path(prim_path), type_name)
    return stage

add_reference(stage, prim_path, asset_path, target_prim='')

Reference a USD file on a prim, defining the prim if needed.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
asset_path str

file to reference.

required
target_prim str

prim of the file to reference, like /Thing. Its default prim if empty.

''

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def add_reference(
    stage: str, prim_path: str, asset_path: str, target_prim: str = ""
) -> str:
    """Reference a USD file on a prim, defining the prim if needed.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        asset_path (str): file to reference.
        target_prim (str): prim of the file to reference, like `/Thing`. Its default
            prim if empty.

    Returns:
        str: handle of the stage.
    """
    prim = get_stage(stage).DefinePrim(Sdf.Path(prim_path))
    if target_prim:
        prim.GetReferences().AddReference(asset_path, Sdf.Path(target_prim))
    else:
        prim.GetReferences().AddReference(asset_path)
    return stage

add_sublayer(stage, layer_path)

Add a layer file to the sublayers of the root layer, as the weakest one.

Parameters:

Name Type Description Default
stage str

stage handle.

required
layer_path str

layer file to add.

required

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
75
76
77
78
79
80
81
82
83
84
85
86
def add_sublayer(stage: str, layer_path: str) -> str:
    """Add a layer file to the sublayers of the root layer, as the weakest one.

    Args:
        stage (str): stage handle.
        layer_path (str): layer file to add.

    Returns:
        str: handle of the stage.
    """
    get_stage(stage).GetRootLayer().subLayerPaths.append(layer_path)
    return stage

add_variant_set(stage, prim_path, set_name, variants)

Add a variant set with variants to a prim. Existing variants are kept.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
set_name str

name of the variant set.

required
variants list[str]

names of the variants.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def add_variant_set(
    stage: str, prim_path: str, set_name: str, variants: list[str]
) -> str:
    """Add a variant set with variants to a prim. Existing variants are kept.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        set_name (str): name of the variant set.
        variants (list[str]): names of the variants.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: handle of the stage.
    """
    variant_set = get_prim(stage, prim_path).GetVariantSets().AddVariantSet(set_name)
    for variant in variants:
        variant_set.AddVariant(variant)
    return stage

bind_material(stage, prim_path, material_path)

Bind a material to a prim and what is below it.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
material_path str

path of the material prim.

required

Raises:

Type Description
ValueError

no prim at a path, or material_path is not a material.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def bind_material(stage: str, prim_path: str, material_path: str) -> str:
    """Bind a material to a prim and what is below it.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        material_path (str): path of the material prim.

    Raises:
        ValueError: no prim at a path, or `material_path` is not a material.

    Returns:
        str: handle of the stage.
    """
    prim = get_prim(stage, prim_path)
    material = UsdShade.Material(get_prim(stage, material_path))
    if not material:
        raise ValueError(f"{material_path} is not a Material")
    UsdShade.MaterialBindingAPI.Apply(prim).Bind(material)
    return stage

close_all()

Close every opened stage without saving.

Source code in src/nyx_usd/ops/stages.py
51
52
53
def close_all() -> None:
    """Close every opened stage without saving."""
    STAGES.clear()

close_stage(stage)

Close a stage without saving it. Does nothing if it is not open.

Parameters:

Name Type Description Default
stage str

stage handle.

required
Source code in src/nyx_usd/ops/stages.py
42
43
44
45
46
47
48
def close_stage(stage: str) -> None:
    """Close a stage without saving it. Does nothing if it is not open.

    Args:
        stage (str): stage handle.
    """
    STAGES.pop(stage, None)

copy_prim(stage, prim_path, new_path)

Copy a prim with everything below it, in the layer the stage edits.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
new_path str

path of the copy. The prims above it are created if missing.

required

Raises:

Type Description
ValueError

no prim at the path, or the layer has no spec to copy.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def copy_prim(stage: str, prim_path: str, new_path: str) -> str:
    """Copy a prim with everything below it, in the layer the stage edits.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        new_path (str): path of the copy. The prims above it are created if missing.

    Raises:
        ValueError: no prim at the path, or the layer has no spec to copy.

    Returns:
        str: handle of the stage.
    """
    get_prim(stage, prim_path)
    source, target = Sdf.Path(prim_path), Sdf.Path(new_path)
    layer = get_stage(stage).GetEditTarget().GetLayer()
    if not layer.GetPrimAtPath(source):
        raise ValueError(f"{prim_path} has no spec in {layer.identifier}")
    Sdf.CreatePrimInLayer(layer, target.GetParentPath())
    if not Sdf.CopySpec(layer, source, layer, target):
        raise ValueError(f"Can't copy {prim_path} to {new_path}")
    return stage

create_cube(stage, prim_path, size=1.0)

Define a cube prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
size float

length of an edge.

1.0

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
186
187
188
189
190
191
192
193
194
195
196
197
198
def create_cube(stage: str, prim_path: str, size: float = 1.0) -> str:
    """Define a cube prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        size (float): length of an edge.

    Returns:
        str: handle of the stage.
    """
    UsdGeom.Cube.Define(get_stage(stage), prim_path).GetSizeAttr().Set(float(size))
    return stage

create_material(stage, prim_path, diffuse_color=None)

Define a material with a UsdPreviewSurface shader.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the material. The shader is PreviewSurface below it.

required
diffuse_color list[float] | None

red, green and blue, [0.8, 0.8, 0.8] if omitted.

None

Raises:

Type Description
ValueError

the color doesn't have three numbers.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def create_material(
    stage: str, prim_path: str, diffuse_color: list[float] | None = None
) -> str:
    """Define a material with a UsdPreviewSurface shader.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the material. The shader is `PreviewSurface` below it.
        diffuse_color (list[float] | None): red, green and blue, `[0.8, 0.8, 0.8]` if
            omitted.

    Raises:
        ValueError: the color doesn't have three numbers.

    Returns:
        str: handle of the stage.
    """
    color = _vector([0.8, 0.8, 0.8] if diffuse_color is None else diffuse_color, "color")
    usd_stage = get_stage(stage)
    material = UsdShade.Material.Define(usd_stage, prim_path)
    shader = UsdShade.Shader.Define(usd_stage, f"{prim_path}/PreviewSurface")
    shader.CreateIdAttr("UsdPreviewSurface")
    shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).Set(Gf.Vec3f(*color))
    surface = shader.CreateOutput("surface", Sdf.ValueTypeNames.Token)
    material.CreateSurfaceOutput().ConnectToSource(surface)
    return stage

create_mesh(stage, prim_path, points, face_vertex_counts, face_vertex_indices)

Define a polygon mesh prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
points list[list[float]]

position of every vertex, as x, y and z.

required
face_vertex_counts list[int]

number of vertices of every face.

required
face_vertex_indices list[int]

vertex of every corner of every face.

required

Raises:

Type Description
ValueError

the counts and the indices don't fit, or an index is out of range.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def create_mesh(
    stage: str,
    prim_path: str,
    points: list[list[float]],
    face_vertex_counts: list[int],
    face_vertex_indices: list[int],
) -> str:
    """Define a polygon mesh prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        points (list[list[float]]): position of every vertex, as x, y and z.
        face_vertex_counts (list[int]): number of vertices of every face.
        face_vertex_indices (list[int]): vertex of every corner of every face.

    Raises:
        ValueError: the counts and the indices don't fit, or an index is out of range.

    Returns:
        str: handle of the stage.
    """
    if sum(face_vertex_counts) != len(face_vertex_indices):
        raise ValueError(
            f"The faces have {sum(face_vertex_counts)} corners, "
            f"there are {len(face_vertex_indices)} indices"
        )
    if face_vertex_indices and not 0 <= min(face_vertex_indices) <= max(
        face_vertex_indices
    ) < len(points):
        raise ValueError(f"An index is outside of the {len(points)} points")
    mesh = UsdGeom.Mesh.Define(get_stage(stage), prim_path)
    mesh.GetPointsAttr().Set(
        Vt.Vec3fArray([Gf.Vec3f(*_vector(p, "point")) for p in points])
    )
    mesh.GetFaceVertexCountsAttr().Set(Vt.IntArray([int(c) for c in face_vertex_counts]))
    mesh.GetFaceVertexIndicesAttr().Set(
        Vt.IntArray([int(i) for i in face_vertex_indices])
    )
    return stage

create_sphere(stage, prim_path, radius=1.0)

Define a sphere prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
radius float

radius of the sphere.

1.0

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
201
202
203
204
205
206
207
208
209
210
211
212
213
def create_sphere(stage: str, prim_path: str, radius: float = 1.0) -> str:
    """Define a sphere prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        radius (float): radius of the sphere.

    Returns:
        str: handle of the stage.
    """
    UsdGeom.Sphere.Define(get_stage(stage), prim_path).GetRadiusAttr().Set(float(radius))
    return stage

create_stage(path='')

Create a stage.

Parameters:

Name Type Description Default
path str

file the stage is saved to. In memory only if empty.

''

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stages.py
29
30
31
32
33
34
35
36
37
38
39
def create_stage(path: str = "") -> str:
    """Create a stage.

    Args:
        path (str): file the stage is saved to. In memory only if empty.

    Returns:
        str: handle of the stage.
    """
    stage = Usd.Stage.CreateNew(path) if path else Usd.Stage.CreateInMemory()
    return register(stage)

export_to_string(stage, flatten=False)

Get the USD text of a stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required
flatten bool

compose everything into one layer first, instead of giving the root layer as it is.

False

Returns:

Name Type Description
str str

USDA text.

Source code in src/nyx_usd/ops/composition.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def export_to_string(stage: str, flatten: bool = False) -> str:
    """Get the USD text of a stage.

    Args:
        stage (str): stage handle.
        flatten (bool): compose everything into one layer first, instead of giving the
            root layer as it is.

    Returns:
        str: USDA text.
    """
    usd_stage = get_stage(stage)
    layer = usd_stage.Flatten() if flatten else usd_stage.GetRootLayer()
    return layer.ExportToString()

find_prims(stage, name_pattern, type_name='')

Find prims by name.

Parameters:

Name Type Description Default
stage str

stage handle.

required
name_pattern str

regular expression searched in the name of the prims, not their whole path.

required
type_name str

only the prims of this schema type, all if empty.

''

Returns:

Type Description
list[str]

list[str]: paths of the prims that match.

Source code in src/nyx_usd/ops/prims.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def find_prims(stage: str, name_pattern: str, type_name: str = "") -> list[str]:
    """Find prims by name.

    Args:
        stage (str): stage handle.
        name_pattern (str): regular expression searched in the name of the prims, not
            their whole path.
        type_name (str): only the prims of this schema type, all if empty.

    Returns:
        list[str]: paths of the prims that match.
    """
    pattern = re.compile(name_pattern)
    return [
        str(prim.GetPath())
        for prim in get_stage(stage).Traverse()
        if pattern.search(prim.GetName())
        and (not type_name or prim.GetTypeName() == type_name)
    ]

flatten_stage(stage, path)

Compose a stage into one layer and write it to a file.

Parameters:

Name Type Description Default
stage str

stage handle.

required
path str

file to write.

required

Raises:

Type Description
ValueError

the file can't be written.

Returns:

Name Type Description
str str

the path of the file.

Source code in src/nyx_usd/ops/composition.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
def flatten_stage(stage: str, path: str) -> str:
    """Compose a stage into one layer and write it to a file.

    Args:
        stage (str): stage handle.
        path (str): file to write.

    Raises:
        ValueError: the file can't be written.

    Returns:
        str: the path of the file.
    """
    if not get_stage(stage).Flatten().Export(path):
        raise ValueError(f"Can't write {path!r}")
    return path

get_attribute(stage, prim_path, attr)

Get the value of an attribute.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
attr str

attribute name.

required

Raises:

Type Description
ValueError

no prim at the path, or no such attribute.

Returns:

Name Type Description
Any Any

JSON value, None if the attribute has no value.

Source code in src/nyx_usd/ops/attributes.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def get_attribute(stage: str, prim_path: str, attr: str) -> typing.Any:
    """Get the value of an attribute.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        attr (str): attribute name.

    Raises:
        ValueError: no prim at the path, or no such attribute.

    Returns:
        Any: JSON value, None if the attribute has no value.
    """
    attribute = get_attribute_of(get_prim(stage, prim_path), attr)
    return to_json(attribute.Get())

get_attribute_at_time(stage, prim_path, attr, time=0.0)

Get the value of an attribute at a time, interpolated between samples.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
attr str

attribute name.

required
time float

time code to read.

0.0

Raises:

Type Description
ValueError

no prim at the path, or no such attribute.

Returns:

Name Type Description
Any Any

JSON value, None if the attribute has no value.

Source code in src/nyx_usd/ops/attributes.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def get_attribute_at_time(
    stage: str, prim_path: str, attr: str, time: float = 0.0
) -> typing.Any:
    """Get the value of an attribute at a time, interpolated between samples.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        attr (str): attribute name.
        time (float): time code to read.

    Raises:
        ValueError: no prim at the path, or no such attribute.

    Returns:
        Any: JSON value, None if the attribute has no value.
    """
    attribute = get_attribute_of(get_prim(stage, prim_path), attr)
    return to_json(attribute.Get(Usd.TimeCode(time)))

get_bounding_box(stage, prim_path)

Get the bounds of a prim and what is below it, in the world.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Type Description
list[list[float]]

list[list[float]]: the minimum and maximum corner. Empty bounds have a minimum larger than the maximum.

Source code in src/nyx_usd/ops/geometry.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def get_bounding_box(stage: str, prim_path: str) -> list[list[float]]:
    """Get the bounds of a prim and what is below it, in the world.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        list[list[float]]: the minimum and maximum corner. Empty bounds have a
            minimum larger than the maximum.
    """
    cache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), [UsdGeom.Tokens.default_])
    box = cache.ComputeWorldBound(get_prim(stage, prim_path)).ComputeAlignedRange()
    return [list(box.GetMin()), list(box.GetMax())]

get_children(stage, prim_path)

List the paths of the children of a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Type Description
list[str]

list[str]: paths of the children.

Source code in src/nyx_usd/ops/prims.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def get_children(stage: str, prim_path: str) -> list[str]:
    """List the paths of the children of a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        list[str]: paths of the children.
    """
    return [str(child.GetPath()) for child in get_prim(stage, prim_path).GetChildren()]

get_parent(stage, prim_path)

Get the path of the parent of a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

path of the parent, / for a prim at the top, empty for the root.

Source code in src/nyx_usd/ops/prims.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def get_parent(stage: str, prim_path: str) -> str:
    """Get the path of the parent of a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: path of the parent, `/` for a prim at the top, empty for the root.
    """
    parent = get_prim(stage, prim_path).GetParent()
    return str(parent.GetPath()) if parent else ""

get_prim_metadata(stage, prim_path, key)

Get a metadata field of a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
key str

metadata key.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
Any Any

JSON value, None if the field is not set.

Source code in src/nyx_usd/ops/prims.py
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
def get_prim_metadata(stage: str, prim_path: str, key: str) -> typing.Any:
    """Get a metadata field of a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        key (str): metadata key.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        Any: JSON value, None if the field is not set.
    """
    return to_json(get_prim(stage, prim_path).GetMetadata(key))

get_prim_type(stage, prim_path)

Get the schema type of a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

type name like Xform, empty for a prim without a type.

Source code in src/nyx_usd/ops/prims.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def get_prim_type(stage: str, prim_path: str) -> str:
    """Get the schema type of a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: type name like `Xform`, empty for a prim without a type.
    """
    return str(get_prim(stage, prim_path).GetTypeName())

get_stage_info(stage)

Describe a stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: root_layer, default_prim (empty if there is none), up_axis, meters_per_unit, fps, start, end and prim_count.

Source code in src/nyx_usd/ops/stage_settings.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def get_stage_info(stage: str) -> dict[str, typing.Any]:
    """Describe a stage.

    Args:
        stage (str): stage handle.

    Returns:
        dict[str, Any]: `root_layer`, `default_prim` (empty if there is none),
            `up_axis`, `meters_per_unit`, `fps`, `start`, `end` and `prim_count`.
    """
    usd_stage = get_stage(stage)
    default_prim = usd_stage.GetDefaultPrim()
    root_layer: Sdf.Layer = usd_stage.GetRootLayer()
    return {
        "root_layer": root_layer.identifier,
        "default_prim": str(default_prim.GetPath()) if default_prim else "",
        "up_axis": str(UsdGeom.GetStageUpAxis(usd_stage)),
        "meters_per_unit": UsdGeom.GetStageMetersPerUnit(usd_stage),
        "fps": usd_stage.GetFramesPerSecond(),
        "start": usd_stage.GetStartTimeCode(),
        "end": usd_stage.GetEndTimeCode(),
        "prim_count": len(list(usd_stage.Traverse())),
    }

get_stage_metadata(stage, key)

Get a metadata field of the stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required
key str

metadata key.

required

Returns:

Name Type Description
Any Any

JSON value, None if the field is not set.

Source code in src/nyx_usd/ops/stage_settings.py
35
36
37
38
39
40
41
42
43
44
45
def get_stage_metadata(stage: str, key: str) -> typing.Any:
    """Get a metadata field of the stage.

    Args:
        stage (str): stage handle.
        key (str): metadata key.

    Returns:
        Any: JSON value, None if the field is not set.
    """
    return to_json(get_stage(stage).GetMetadata(key))

get_time_range(stage)

Get the first and last time code of the stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required

Returns:

Type Description
list[float]

list[float]: start and end time code.

Source code in src/nyx_usd/ops/stage_settings.py
70
71
72
73
74
75
76
77
78
79
80
def get_time_range(stage: str) -> list[float]:
    """Get the first and last time code of the stage.

    Args:
        stage (str): stage handle.

    Returns:
        list[float]: start and end time code.
    """
    usd_stage = get_stage(stage)
    return [usd_stage.GetStartTimeCode(), usd_stage.GetEndTimeCode()]

get_time_samples(stage, prim_path, attr)

List the times an attribute has a value at.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
attr str

attribute name.

required

Raises:

Type Description
ValueError

no prim at the path, or no such attribute.

Returns:

Type Description
list[float]

list[float]: time codes, empty for an attribute without animation.

Source code in src/nyx_usd/ops/attributes.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def get_time_samples(stage: str, prim_path: str, attr: str) -> list[float]:
    """List the times an attribute has a value at.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        attr (str): attribute name.

    Raises:
        ValueError: no prim at the path, or no such attribute.

    Returns:
        list[float]: time codes, empty for an attribute without animation.
    """
    return list(get_attribute_of(get_prim(stage, prim_path), attr).GetTimeSamples())

get_transform(stage, prim_path)

Get the local transform of a prim as a 4x4 matrix.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

no prim at the path, or it can't be transformed.

Returns:

Type Description
list[list[float]]

list[list[float]]: the matrix, as rows.

Source code in src/nyx_usd/ops/geometry.py
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def get_transform(stage: str, prim_path: str) -> list[list[float]]:
    """Get the local transform of a prim as a 4x4 matrix.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: no prim at the path, or it can't be transformed.

    Returns:
        list[list[float]]: the matrix, as rows.
    """
    matrix = _xformable(stage, prim_path).GetLocalTransformation(Usd.TimeCode.Default())
    return to_json(matrix)

get_variants(stage, prim_path)

Describe the variant sets of a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Type Description
dict[str, dict]

dict[str, dict]: by set name, its variants and the selection (empty if none).

Source code in src/nyx_usd/ops/composition.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def get_variants(stage: str, prim_path: str) -> dict[str, dict]:
    """Describe the variant sets of a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        dict[str, dict]: by set name, its `variants` and the `selection` (empty if
            none).
    """
    variant_sets = get_prim(stage, prim_path).GetVariantSets()
    return {
        name: {
            "variants": list(variant_sets.GetVariantSet(name).GetVariantNames()),
            "selection": variant_sets.GetVariantSet(name).GetVariantSelection(),
        }
        for name in variant_sets.GetNames()
    }

get_world_transform(stage, prim_path)

Get the transform of a prim in the world as a 4x4 matrix.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

no prim at the path, or it can't be transformed.

Returns:

Type Description
list[list[float]]

list[list[float]]: the matrix, as rows.

Source code in src/nyx_usd/ops/geometry.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def get_world_transform(stage: str, prim_path: str) -> list[list[float]]:
    """Get the transform of a prim in the world as a 4x4 matrix.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: no prim at the path, or it can't be transformed.

    Returns:
        list[list[float]]: the matrix, as rows.
    """
    matrix = _xformable(stage, prim_path).ComputeLocalToWorldTransform(
        Usd.TimeCode.Default()
    )
    return to_json(matrix)

has_prim(stage, prim_path)

Check whether a prim exists.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Returns:

Name Type Description
bool bool

there is a prim at the path.

Source code in src/nyx_usd/ops/prims.py
66
67
68
69
70
71
72
73
74
75
76
def has_prim(stage: str, prim_path: str) -> bool:
    """Check whether a prim exists.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Returns:
        bool: there is a prim at the path.
    """
    return bool(get_stage(stage).GetPrimAtPath(prim_path))

list_attributes(stage, prim_path)

List the names of the attributes of a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Type Description
list[str]

list[str]: attribute names, the ones of its schema included.

Source code in src/nyx_usd/ops/attributes.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def list_attributes(stage: str, prim_path: str) -> list[str]:
    """List the names of the attributes of a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        list[str]: attribute names, the ones of its schema included.
    """
    return [
        attribute.GetName() for attribute in get_prim(stage, prim_path).GetAttributes()
    ]

list_prims(stage, type_name='')

List the paths of the prims of a stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required
type_name str

only the prims of this schema type, all if empty.

''

Returns:

Type Description
list[str]

list[str]: prim paths.

Source code in src/nyx_usd/ops/prims.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def list_prims(stage: str, type_name: str = "") -> list[str]:
    """List the paths of the prims of a stage.

    Args:
        stage (str): stage handle.
        type_name (str): only the prims of this schema type, all if empty.

    Returns:
        list[str]: prim paths.
    """
    return [
        str(prim.GetPath())
        for prim in get_stage(stage).Traverse()
        if not type_name or prim.GetTypeName() == type_name
    ]

list_sublayers(stage)

List the sublayers of the root layer, the strongest first.

Parameters:

Name Type Description Default
stage str

stage handle.

required

Returns:

Type Description
list[str]

list[str]: layer paths.

Source code in src/nyx_usd/ops/composition.py
109
110
111
112
113
114
115
116
117
118
def list_sublayers(stage: str) -> list[str]:
    """List the sublayers of the root layer, the strongest first.

    Args:
        stage (str): stage handle.

    Returns:
        list[str]: layer paths.
    """
    return list(get_stage(stage).GetRootLayer().subLayerPaths)

move_prim(stage, prim_path, new_parent_path)

Move a prim under another parent, in the layer the stage edits.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
new_parent_path str

path of the new parent, / for the top.

required

Raises:

Type Description
ValueError

no prim at the path, or the layer can't move it.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def move_prim(stage: str, prim_path: str, new_parent_path: str) -> str:
    """Move a prim under another parent, in the layer the stage edits.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        new_parent_path (str): path of the new parent, `/` for the top.

    Raises:
        ValueError: no prim at the path, or the layer can't move it.

    Returns:
        str: handle of the stage.
    """
    prim = get_prim(stage, prim_path)
    _apply_edit(
        stage,
        Sdf.NamespaceEdit.ReparentAndRename(
            Sdf.Path(prim_path),
            Sdf.Path(new_parent_path),
            prim.GetName(),
            Sdf.NamespaceEdit.atEnd,
        ),
    )
    return stage

open_stage(path)

Open a USD file.

Parameters:

Name Type Description Default
path str

file to open.

required

Raises:

Type Description
ValueError

the file can't be opened.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stages.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def open_stage(path: str) -> str:
    """Open a USD file.

    Args:
        path (str): file to open.

    Raises:
        ValueError: the file can't be opened.

    Returns:
        str: handle of the stage.
    """
    try:
        stage = Usd.Stage.Open(path)
    except Exception as err:
        raise ValueError(f"Can't open USD file {path!r}: {err}") from err
    return register(stage)

remove_attribute(stage, prim_path, attr)

Remove an attribute from the layer the stage edits.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
attr str

attribute name.

required

Raises:

Type Description
ValueError

no prim at the path, or the attribute can't be removed.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/attributes.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def remove_attribute(stage: str, prim_path: str, attr: str) -> str:
    """Remove an attribute from the layer the stage edits.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        attr (str): attribute name.

    Raises:
        ValueError: no prim at the path, or the attribute can't be removed.

    Returns:
        str: handle of the stage.
    """
    if not get_prim(stage, prim_path).RemoveProperty(attr):
        raise ValueError(f"Can't remove attribute {attr!r} of {prim_path}")
    return stage

remove_prim(stage, prim_path)

Remove a prim.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def remove_prim(stage: str, prim_path: str) -> str:
    """Remove a prim.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: handle of the stage.
    """
    get_prim(stage, prim_path)
    get_stage(stage).RemovePrim(Sdf.Path(prim_path))
    return stage

remove_sublayer(stage, layer_path)

Remove a layer from the sublayers of the root layer.

Parameters:

Name Type Description Default
stage str

stage handle.

required
layer_path str

layer file to remove, as it was added.

required

Raises:

Type Description
ValueError

the layer is not a sublayer.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def remove_sublayer(stage: str, layer_path: str) -> str:
    """Remove a layer from the sublayers of the root layer.

    Args:
        stage (str): stage handle.
        layer_path (str): layer file to remove, as it was added.

    Raises:
        ValueError: the layer is not a sublayer.

    Returns:
        str: handle of the stage.
    """
    paths = get_stage(stage).GetRootLayer().subLayerPaths
    if layer_path not in paths:
        raise ValueError(f"{layer_path!r} is not a sublayer of {stage!r}")
    paths.remove(layer_path)
    return stage

rename_prim(stage, prim_path, new_name)

Rename a prim, in the layer the stage edits.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
new_name str

new name, without the path.

required

Raises:

Type Description
ValueError

no prim at the path, or the layer can't rename it.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def rename_prim(stage: str, prim_path: str, new_name: str) -> str:
    """Rename a prim, in the layer the stage edits.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        new_name (str): new name, without the path.

    Raises:
        ValueError: no prim at the path, or the layer can't rename it.

    Returns:
        str: handle of the stage.
    """
    get_prim(stage, prim_path)
    _apply_edit(stage, Sdf.NamespaceEdit.Rename(Sdf.Path(prim_path), new_name))
    return stage

save_stage(stage, path='')

Save a stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required
path str

file to export the stage to, its own file if empty.

''

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stages.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def save_stage(stage: str, path: str = "") -> str:
    """Save a stage.

    Args:
        stage (str): stage handle.
        path (str): file to export the stage to, its own file if empty.

    Returns:
        str: handle of the stage.
    """
    usd_stage = get_stage(stage)
    if path:
        usd_stage.Export(path)
    else:
        usd_stage.Save()
    return stage

set_active(stage, prim_path, active=True)

Activate or deactivate a prim. A deactivated prim is left out of traversals.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
active bool

whether the prim is active.

True

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
def set_active(stage: str, prim_path: str, active: bool = True) -> str:
    """Activate or deactivate a prim. A deactivated prim is left out of traversals.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        active (bool): whether the prim is active.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: handle of the stage.
    """
    get_prim(stage, prim_path).SetActive(bool(active))
    return stage

set_attribute(stage, prim_path, attr, value, type_name='')

Set the value of an attribute, creating the attribute if it is missing.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
attr str

attribute name.

required
value Any

JSON value. A list is turned into the vector, matrix or array the attribute type calls for.

required
type_name str

value type of the attribute to create, like float or float3. Needed only when the attribute doesn't exist.

''

Raises:

Type Description
ValueError

no prim at the path, or the attribute is missing and the type is unknown.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/attributes.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def set_attribute(
    stage: str, prim_path: str, attr: str, value: typing.Any, type_name: str = ""
) -> str:
    """Set the value of an attribute, creating the attribute if it is missing.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        attr (str): attribute name.
        value (Any): JSON value. A list is turned into the vector, matrix or array the
            attribute type calls for.
        type_name (str): value type of the attribute to create, like `float` or
            `float3`. Needed only when the attribute doesn't exist.

    Raises:
        ValueError: no prim at the path, or the attribute is missing and the type
            is unknown.

    Returns:
        str: handle of the stage.
    """
    attribute = get_attribute_of(get_prim(stage, prim_path), attr, type_name, True)
    attribute.Set(to_usd(value, attribute.GetTypeName()))
    return stage

set_attribute_at_time(stage, prim_path, attr, value, time=0.0, type_name='')

Set the value of an attribute at a time, creating the attribute if it is missing.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
attr str

attribute name.

required
value Any

JSON value, see set_attribute.

required
time float

time code the value is for.

0.0
type_name str

value type of the attribute to create, see set_attribute.

''

Raises:

Type Description
ValueError

no prim at the path, or the attribute is missing and the type is unknown.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/attributes.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def set_attribute_at_time(
    stage: str,
    prim_path: str,
    attr: str,
    value: typing.Any,
    time: float = 0.0,
    type_name: str = "",
) -> str:
    """Set the value of an attribute at a time, creating the attribute if it is missing.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        attr (str): attribute name.
        value (Any): JSON value, see `set_attribute`.
        time (float): time code the value is for.
        type_name (str): value type of the attribute to create, see `set_attribute`.

    Raises:
        ValueError: no prim at the path, or the attribute is missing and the type
            is unknown.

    Returns:
        str: handle of the stage.
    """
    attribute = get_attribute_of(get_prim(stage, prim_path), attr, type_name, True)
    attribute.Set(to_usd(value, attribute.GetTypeName()), Usd.TimeCode(time))
    return stage

set_default_prim(stage, prim_path)

Set the prim that is referenced when the file is referenced without a target.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim, a root prim.

required

Raises:

Type Description
ValueError

there is no prim at the path.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stage_settings.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
def set_default_prim(stage: str, prim_path: str) -> str:
    """Set the prim that is referenced when the file is referenced without a target.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim, a root prim.

    Raises:
        ValueError: there is no prim at the path.

    Returns:
        str: handle of the stage.
    """
    get_stage(stage).SetDefaultPrim(get_prim(stage, prim_path))
    return stage

set_fps(stage, fps=24.0)

Set the frames per second, and the time codes per second with it.

Parameters:

Name Type Description Default
stage str

stage handle.

required
fps float

frames per second.

24.0

Raises:

Type Description
ValueError

the rate is not positive.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stage_settings.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def set_fps(stage: str, fps: float = 24.0) -> str:
    """Set the frames per second, and the time codes per second with it.

    Args:
        stage (str): stage handle.
        fps (float): frames per second.

    Raises:
        ValueError: the rate is not positive.

    Returns:
        str: handle of the stage.
    """
    if fps <= 0:
        raise ValueError(f"Frames per second have to be positive, not {fps}")
    usd_stage = get_stage(stage)
    usd_stage.SetFramesPerSecond(fps)
    usd_stage.SetTimeCodesPerSecond(fps)
    return stage

set_kind(stage, prim_path, kind)

Set the kind of a prim, like component or assembly.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
kind str

kind to set.

required

Raises:

Type Description
ValueError

no prim at the path, or the kind can't be set.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def set_kind(stage: str, prim_path: str, kind: str) -> str:
    """Set the kind of a prim, like `component` or `assembly`.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        kind (str): kind to set.

    Raises:
        ValueError: no prim at the path, or the kind can't be set.

    Returns:
        str: handle of the stage.
    """
    if not Usd.ModelAPI(get_prim(stage, prim_path)).SetKind(kind):
        raise ValueError(f"Can't set kind {kind!r} on {prim_path}")
    return stage

set_meters_per_unit(stage, meters=1.0)

Set the size of a unit of the stage in meters, 0.01 for centimeters.

Parameters:

Name Type Description Default
stage str

stage handle.

required
meters float

meters per unit.

1.0

Raises:

Type Description
ValueError

the value is not positive.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stage_settings.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def set_meters_per_unit(stage: str, meters: float = 1.0) -> str:
    """Set the size of a unit of the stage in meters, 0.01 for centimeters.

    Args:
        stage (str): stage handle.
        meters (float): meters per unit.

    Raises:
        ValueError: the value is not positive.

    Returns:
        str: handle of the stage.
    """
    if meters <= 0:
        raise ValueError(f"Meters per unit have to be positive, not {meters}")
    UsdGeom.SetStageMetersPerUnit(get_stage(stage), meters)
    return stage

set_prim_metadata(stage, prim_path, key, value=None)

Set a metadata field of a prim, like documentation or customData.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
key str

metadata key.

required
value Any

JSON value.

None

Raises:

Type Description
ValueError

no prim at the path, or the value doesn't fit the key.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/prims.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def set_prim_metadata(
    stage: str, prim_path: str, key: str, value: typing.Any = None
) -> str:
    """Set a metadata field of a prim, like `documentation` or `customData`.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        key (str): metadata key.
        value (Any): JSON value.

    Raises:
        ValueError: no prim at the path, or the value doesn't fit the key.

    Returns:
        str: handle of the stage.
    """
    prim = get_prim(stage, prim_path)
    try:
        authored = prim.SetMetadata(key, value)
    except Exception as err:
        raise ValueError(f"Can't set metadata {key!r} of {prim_path}: {err}") from err
    if not authored:
        raise ValueError(f"Can't set metadata {key!r} of {prim_path} to {value!r}")
    return stage

set_purpose(stage, prim_path, purpose='default')

Set the purpose of a prim: what it is drawn for.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
purpose str

default, render, proxy or guide.

'default'

Raises:

Type Description
ValueError

no prim at the path, it has no purpose, or the purpose is unknown.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def set_purpose(stage: str, prim_path: str, purpose: str = "default") -> str:
    """Set the purpose of a prim: what it is drawn for.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        purpose (str): `default`, `render`, `proxy` or `guide`.

    Raises:
        ValueError: no prim at the path, it has no purpose, or the purpose is unknown.

    Returns:
        str: handle of the stage.
    """
    if purpose not in PURPOSES:
        raise ValueError(f"The purpose has to be one of {PURPOSES}, not {purpose!r}")
    imageable = UsdGeom.Imageable(get_prim(stage, prim_path))
    if not imageable:
        raise ValueError(f"{prim_path} has no purpose, it is not Imageable")
    imageable.GetPurposeAttr().Set(purpose)
    return stage

set_stage_metadata(stage, key, value=None)

Set a metadata field of the stage, like comment or documentation.

Parameters:

Name Type Description Default
stage str

stage handle.

required
key str

metadata key.

required
value Any

JSON value.

None

Raises:

Type Description
ValueError

the value doesn't fit the key.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stage_settings.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def set_stage_metadata(stage: str, key: str, value: typing.Any = None) -> str:
    """Set a metadata field of the stage, like `comment` or `documentation`.

    Args:
        stage (str): stage handle.
        key (str): metadata key.
        value (Any): JSON value.

    Raises:
        ValueError: the value doesn't fit the key.

    Returns:
        str: handle of the stage.
    """
    try:
        authored = get_stage(stage).SetMetadata(key, value)
    except Exception as err:
        raise ValueError(f"Can't set stage metadata {key!r}: {err}") from err
    if not authored:
        raise ValueError(f"Can't set stage metadata {key!r} to {value!r}")
    return stage

set_time_range(stage, start=0.0, end=100.0)

Set the first and last time code of the stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required
start float

first time code.

0.0
end float

last time code.

100.0

Raises:

Type Description
ValueError

the end is before the start.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stage_settings.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def set_time_range(stage: str, start: float = 0.0, end: float = 100.0) -> str:
    """Set the first and last time code of the stage.

    Args:
        stage (str): stage handle.
        start (float): first time code.
        end (float): last time code.

    Raises:
        ValueError: the end is before the start.

    Returns:
        str: handle of the stage.
    """
    if end < start:
        raise ValueError(f"The end {end} is before the start {start}")
    usd_stage = get_stage(stage)
    usd_stage.SetStartTimeCode(start)
    usd_stage.SetEndTimeCode(end)
    return stage

set_transform(stage, prim_path, translate=None, rotate=None, scale=None)

Set the local transform of a prim, replacing the transform operations it has.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
translate list[float] | None

x, y and z, [0, 0, 0] if omitted.

None
rotate list[float] | None

x, y and z rotation in degrees, [0, 0, 0] if omitted.

None
scale list[float] | None

x, y and z, [1, 1, 1] if omitted.

None

Raises:

Type Description
ValueError

no prim at the path, it can't be transformed, or a list doesn't have three numbers.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def set_transform(
    stage: str,
    prim_path: str,
    translate: list[float] | None = None,
    rotate: list[float] | None = None,
    scale: list[float] | None = None,
) -> str:
    """Set the local transform of a prim, replacing the transform operations it has.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        translate (list[float] | None): x, y and z, `[0, 0, 0]` if omitted.
        rotate (list[float] | None): x, y and z rotation in degrees, `[0, 0, 0]` if
            omitted.
        scale (list[float] | None): x, y and z, `[1, 1, 1]` if omitted.

    Raises:
        ValueError: no prim at the path, it can't be transformed, or a list doesn't
            have three numbers.

    Returns:
        str: handle of the stage.
    """
    translation = _vector([0, 0, 0] if translate is None else translate, "translate")
    rotation = _vector([0, 0, 0] if rotate is None else rotate, "rotate")
    scaling = _vector([1, 1, 1] if scale is None else scale, "scale")
    xformable = _xformable(stage, prim_path)
    xformable.ClearXformOpOrder()
    xformable.AddTranslateOp().Set(Gf.Vec3d(*translation))
    xformable.AddRotateXYZOp().Set(Gf.Vec3f(*rotation))
    xformable.AddScaleOp().Set(Gf.Vec3f(*scaling))
    return stage

set_up_axis(stage, axis='Y')

Set the up axis of the stage.

Parameters:

Name Type Description Default
stage str

stage handle.

required
axis str

Y or Z.

'Y'

Raises:

Type Description
ValueError

the axis is not Y or Z.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/stage_settings.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def set_up_axis(stage: str, axis: str = "Y") -> str:
    """Set the up axis of the stage.

    Args:
        stage (str): stage handle.
        axis (str): `Y` or `Z`.

    Raises:
        ValueError: the axis is not Y or Z.

    Returns:
        str: handle of the stage.
    """
    tokens = {"Y": UsdGeom.Tokens.y, "Z": UsdGeom.Tokens.z}
    if axis.upper() not in tokens:
        raise ValueError(f"The up axis has to be Y or Z, not {axis!r}")
    UsdGeom.SetStageUpAxis(get_stage(stage), tokens[axis.upper()])
    return stage

set_variant_selection(stage, prim_path, set_name, variant)

Select a variant of a variant set.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
set_name str

name of the variant set.

required
variant str

variant to select, empty to clear the selection.

required

Raises:

Type Description
ValueError

no prim at the path, or no such variant set or variant.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/composition.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def set_variant_selection(
    stage: str, prim_path: str, set_name: str, variant: str
) -> str:
    """Select a variant of a variant set.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        set_name (str): name of the variant set.
        variant (str): variant to select, empty to clear the selection.

    Raises:
        ValueError: no prim at the path, or no such variant set or variant.

    Returns:
        str: handle of the stage.
    """
    prim = get_prim(stage, prim_path)
    if not prim.HasVariantSets() or set_name not in prim.GetVariantSets().GetNames():
        raise ValueError(f"{prim_path} has no variant set {set_name!r}")
    variant_set = prim.GetVariantSet(set_name)
    if variant and variant not in variant_set.GetVariantNames():
        raise ValueError(f"Variant set {set_name!r} has no variant {variant!r}")
    if variant:
        variant_set.SetVariantSelection(variant)
    else:
        variant_set.ClearVariantSelection()
    return stage

set_visibility(stage, prim_path, visible=True)

Show or hide a prim and what is below it.

Parameters:

Name Type Description Default
stage str

stage handle.

required
prim_path str

path of the prim.

required
visible bool

whether the prim is visible.

True

Raises:

Type Description
ValueError

no prim at the path, or it has no visibility.

Returns:

Name Type Description
str str

handle of the stage.

Source code in src/nyx_usd/ops/geometry.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def set_visibility(stage: str, prim_path: str, visible: bool = True) -> str:
    """Show or hide a prim and what is below it.

    Args:
        stage (str): stage handle.
        prim_path (str): path of the prim.
        visible (bool): whether the prim is visible.

    Raises:
        ValueError: no prim at the path, or it has no visibility.

    Returns:
        str: handle of the stage.
    """
    imageable = UsdGeom.Imageable(get_prim(stage, prim_path))
    if not imageable:
        raise ValueError(f"{prim_path} has no visibility, it is not Imageable")
    if visible:
        imageable.MakeVisible()
    else:
        imageable.MakeInvisible()
    return stage