Prim size, extents?

If I am adding usda files to a stage like:

    stage = context.get_stage()

    for i in range(10):
        path = "/World/prim{}".format(i)
        prim = stage.DefinePrim(path, "Xform")
        
        prim.GetReferences().AddReference("omniverse://localhost/Projects/test/cube.usda")

        obj = stage.GetPrimAtPath(path)
        sizeAttr_ref = obj.CreateAttribute('size', )

        sizeAttr_ref.Set(100)

I added this part to set the size as the object isnt visible on the stage.

Simple cube:

#usda 1.0
(
    defaultPrim = "cube"
)

def Cube "cube"
{
}

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)

Well, redundant for sure, I meant to just load the usda, whatever it is…

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:

#usda 1.0
(
    defaultPrim = "root"
)

def Xform "root"
{

  def Cube "cube" {
  }

}

And then create the Xforms that reference it, but change the size on prim#/cube:

context  = omni.usd.get_context()
stage = context.get_stage()

for i in range(10):
    path = "/World/prim{}".format(i)
    prim = stage.DefinePrim(path, "Xform")
    
    prim.GetReferences().AddReference("C:/tmp/cube.usda") # path changed from original

    obj = stage.GetPrimAtPath(path + "/cube") # note the extra /cube
    sizeAttr_ref = obj.CreateAttribute('size', Sdf.ValueTypeNames.Double )

    sizeAttr_ref.Set(50 * (i+1))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.