After running this code I get 10 prim - Xform objects on the stage, but they dont seem to have any size?
How can I set the size of the cube and move them into different positions ?
Hi Gavin. The main issue is that you’re referencing the Cube prim on an Xform prim. The Xform prim may show the Size attribute in the Raw USD Properties, but it doesn’t know what to do with it. Instead, you can define a “Cube” type and reference onto that. This of course makes your current example a bit redundant.
import omni.usd
from pxr import Sdf
stage = omni.usd.get_context().get_stage()
for i in range(10):
path = "/World/prim{}".format(i)
prim = stage.DefinePrim(path, "Cube")
prim.GetReferences().AddReference(r"omniverse://localhost/Projects/test/cube.usda")
# Don't forget to provide the data type on this line. Your example was missing it.
prim.CreateAttribute('size', Sdf.ValueTypeNames.Double).Set(100)
I think it’s because of this behavior that @mati-nvidia mentions - that the element where the reference is created being different than the referenced element - is also the cause why you’ll see most USD prims that are meant to be referenced, usually wrapped inside a “world” or “root” Xform.
In this manner there are no confusions with the referencing element and its target, because the direct target will sort of disappear, but not its descendants, and these can be freely referenced.
So another solution would be to wrap the cube inside a root Xform: