Skip to content

stage_settings

stage_settings

Metadata and settings of a stage: time, axis, units and the default prim.

Functions:

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()]

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_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_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_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