USD Data Types

The USD API Documentation has a list of USD Basic Data Types that are used for Attribute types. Type Name are provided by the Sdf.ValueTypeNames module, which is a useful resource for reference.

In order to pass a valid value for the type for the CreateAttribute(name, type) function, it needs to be a reference to a Sdf.ValueTypeNames.TypeName object. There are three ways of getting these:

  1. Using Python Objects

The current values and how to construct an object that will function as that value are in a table here for convenience, please refer to the USD Basic Data Types page for an explanation on explicit definitions. The Value Type Token column denotes how each Type Name appears in a .usda file.

Tip

Gf.Vec3d/f/h instances below can be constructed with just a (float, float, float) tuple (and Vec2d/f/h ``, ``Vec4d/f/h as well), but the explicit declaration is passed below for completeness.

Note

[] denotes a list of types. The left column of this list was generated with the method from 1) above.

Type Name

Value Type Token

Python Constructor

Asset

asset

string

AssetArray

asset[]

[string]

Bool

bool

bool

BoolArray

bool[]

[bool]

Color3d

color3d

Gf.Vec3d(float, float, float)

Color3dArray

color3d[]

[Gf.Vec3d(float, float, float)]

Color3f

color3f

Gf.Vec3f(float, float, float)

Color3fArray

color3f[]

[Gf.Vec3f(float, float, float)]

Color3h

color3h

Gf.Vec3h(float, float, float)

Color3hArray

color3h[]

[Gf.Vec3h(float, float, float)]

Color4d

color4d

Gf.Vec4d(float, float, float, float)

Color4dArray

color4d[]

[Gf.Vec4d(float, float, float, float)]

Color4f

color4f

Gf.Vec4f(float, float, float, float)

Color4fArray

color4f[]

[Gf.Vec4f(float, float, float, float)]

Color4h

color4h

Gf.Vec4h(float, float, float, float)

Color4hArray

color4h[]

[Gf.Vec4h(float, float, float, float)]

Double

double

float

Double2

double2

(float, float)

Double2Array

double2[]

[(float, float)]

Double3

double3

(float, float, float)

Double3Array

double3[]

[(float, float, float)]

Double4

double4

(float, float, float, float)

Double4Array

double4[]

[(float, float, float, float)]

DoubleArray

double[]

[float]

Float

float

float

Float2

float2

(float, float)

Float2Array

float2[]

[(float, float)]

Float3

float3

(float, float, float)

Float3Array

float3[]

[(float, float, float)]

Float4

float4

(float, float, float, float)

Float4Array

float4[]

[(float, float, float, float)]

FloatArray

float[]

[float]

Frame4d

frame4d

float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float

Frame4dArray

frame4d[]

[Gf.Matrix4d(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)]

Half

half

float

Half2

half2

(float, float)

Half2Array

half2[]

[(float, float)]

Half3

half3

(float, float, float)

Half3Array

half3[]

[(float, float, float)]

Half4

half4

(float, float, float, float)

Half4Array

half4[]

[(float, float, float, float)]

HalfArray

half[]

[float]

Int

int

int

Int2

int2

(int, int)

Int2Array

int2[]

[(int, int)]

Int3

int3

(int, int, int)

Int3Array

int3[]

[(int, int, int)]

Int4

int4

(int, int, int, int)

Int4Array

int4[]

[(int, int, int, int)]

Int64

int64

int (long in Python2)

Int64Array

int64[]

[int] ([long] in Python2)

IntArray

int[]

[int]

Matrix2d

matrix2d

float, float, float, float

Matrix2dArray

matrix2d[]

[Gf.Matrix2d(float, float, float, float)]

Matrix3d

matrix3d

float, float, float, float, float, float, float, float, float

Matrix3dArray

matrx3d[]

[Gf.Matrix3d(float, float, float, float, float, float, float, float, float)]

Matrix4d

matrix4d

float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float

Matrix4dArray

matrix4d[]

[Gf.Matrix4d(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)]

Normal3d

normal3d

Gf.Vec3d(float, float, float)

Normal3dArray

normal3d[]

[Gf.Vec3d(float, float, float)]

Normal3f

normal3f

Gf.Vec3f(float, float, float)

Normal3fArray

normal3f[]

[Gf.Vec3f(float, float, float)]

Normal3h

normal3h

Gf.Vec3h(float, float, float)

Normal3hArray

normal3h[]

[Gf.Vec3h(float, float, float)]

Point3d

point3d

Gf.Vec3d(float, float, float)

Point3dArray

point3d[]

[Gf.Vec3d(float, float, float)]

Point3f

point3f

Gf.Vec3f(float, float, float)

Point3fArray

point3f[]

[Gf.Vec3f(float, float, float)]

Point3h

point3h

Gf.Vec3h(float, float, float)

Point3hArray

point3h[]

[Gf.Vec3h(float, float, float)]

Quatd

quatd

Gf.Quatd(float, Gf.Vec3d(float, float, float))

QuatdArray

quatd[]

[Gf.Quatd(float, Gf.Vec3d(float, float, float))]

Quatf

quatf

Gf.Quatf(float, Gf.Vec3f(float, float, float))

QuatfArray

quatf[]

[Gf.Quatf(float, Gf.Vec3f(float, float, float))]

Quath

quath

Gf.Quath(float, Gf.Vec3h(float, float, float))

QuathArray

quath[]

[Gf.Quath(float, Gf.Vec3h(float, float, float))]

String

string

str

StringArray

string[]

[str]

TexCoord2d

texCoord2d

Gf.Vec2d(float, float)

TexCoord2dArray

texCoord2d[]

[Gf.Vec2d(float, float)]

TexCoord2f

texCoord2f

Gf.Vec2f(float, float)

TexCoord2fArray

texCoord2f[]

[Gf.Vec2f(float, float)]

TexCoord2h

texCoord2h

Gf.Vec2h(float, float)

TexCoord2hArray

texCoord2h[]

[Gf.Vec2h(float, float)]

TexCoord3d

texCoord3d

Gf.Vec3d(float, float, float)

TexCoord3dArray

texCoord3d[]

[Gf.Vec3d(float, float, float)]

TexCoord3f

texCoord3f

Gf.Vec3f(float, float, float)

TexCoord3fArray

texCoord3f[]

[Gf.Vec3f(float, float, float)]

TexCoord3h

texCoord3h

Gf.Vec3h(float, float, float)

TexCoord3hArray

texCoord3h[]

[Gf.Vec3h(float, float, float)]

TimeCode

timecode

float

TimeCodeArray

timecode[]

[float]

Token

token

str

TokenArray

token[]

string

UChar

uchar

ord(char) (where char is a single letter string)

UCharArray

uchar[]

[ord(char)] (where char is a single letter string)

UInt

uint

int

UInt64

uint64

int (long in Python2)

UInt64Array

uint64[]

[int] ([long] in Python2)

UIntArray

uint[]

[int]

Vector3d

vector3d

Gf.Vec3d(float, float, float)

Vector3dArray

vector3d[]

[Gf.Vec3d(float, float, float)]

Vector3f

vector3f

Gf.Vec3f(float, float, float)

Vector3fArray

vector3f[]

[Gf.Vec3f(float, float, float)]

Vector3h

vector3h

Gf.Vec3h(float, float, float)

Vector3hArray

vector3h[]

[Gf.Vec3h(float, float, float)]

  1. Get Reference From a String

    Use Sdf.ValueTypeNames.Find(string) to get the reference from a string (valid inputs are the left column in the table above)

  2. Exact Value

Look up the exact value for TypeName in the Sdf.ValueTypeNames module ( Sdf.ValueTypeNames.Color3h for example is valid):

from pxr import Sdf

print(dir(Sdf.ValueTypeNames))

# output is: ['Asset', 'AssetArray', 'Bool', 'BoolArray', 'Color3d', 'Color3dArray', 'Color3f', 'Color3fArray', 'Color3h', 'Color3hArray', 'Color4d', 'Color4dArray', 'Color4f', ... snipped ]

Working with Attributes

You can call the prim_ref.CreateAttribute(name, type) function to create the attribute, and we can use the information above to select a valid type. It returns a reference to the attribute created, which we can set with attribute_ref.Set(value), and again we can construct a valid value by looking up the constructor above.

from pxr import Usd, UsdGeom

stage_ref = Usd.Stage.Open('stage.usda')

# get a reference to the Xform instance, this works fine since it is also a Usd.Prim
xform_ref = UsdGeom.Xform.Define(stage, '/XformPrim')

# create an attribute reference, using an explicit reference to the type
weight_attr = xform_ref.CreateAttribute('weight', Sdf.ValueTypeNames.Float)

print(weight_attr.Get()) # prints empty string for default Float values, not 0!

print(weight_attr.Get() == None) # prints "True"
print(weight_attr.Get() == 0) # prints "False"

# to set an attribute we use the attribute_ref.Set(value) function
weight_attr.Set(42.3)

print(weight_attr.Get()) # prints "42.3"

# also, you can chain calls like so
print(xform_ref.GetPrim().GetAttribute('weight').Get()) # prints "42.3"