Skip to content

attributes

attributes

Reading and writing attributes, with and without time.

Functions:

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

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

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

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