Basic API Usage

Here are some examples of performing common tasks.

Defining a Prim

Here’s how to define a mesh prim in a layer:

usg::Path path("/path/to/my/mesh");
usg::Layer* layer = editLayer();
usg::MeshPrim prim = usg::MeshPrim::defineInLayer(layer, path);

Overriding an existing prim is similar:

usg::MeshPrim prim = usg::MeshPrim::overrideInLayer(layer, prim);

Getting a prim from a node:

node = NodegraphAPI.GetNode("MyNodeName")
stage = NodesUsdAPI.GetStage(node)
prim = stage.getPrimAtPath("/path/to/my/prim")

Getting and Setting Attributes

Creating an attribute:

usg::Attribute attr = prim.createAttr("outputs:surface", usg::Value::Token);
usg::Attribute attr = prim.createAttr("wobbliness", usg::Value::Float, true);

Getting an attribute in C++:

usg::Attribute attr  = Prim::getAttr(usg::GeomTokens.points);
usg::Vec3fArray points;
attr.getValue(points, time);

Getting an attribute in Python:

attr = prim.getAttr("points")
points = attr.get()

Setting an attribute in C++:

attr.setValue(points, time);

Setting an attribute in Python:

usgValue = usg.Value(usg.Vec3fArray([usg.Vec3f(1.1111), usg.Vec3f(2.2222)]), usg.Value.Float3Array)


It’s possible to get to the underlying wrapped USD values for these objects. For example, you can get the raw UsdStageRefPtr for a stage and manipulate it in C++ or Python.