How to set defaultPrim in API?

I’m creating some synthetic prims to use in Replicator. Works fine if I manually go in and set the root prim as defaultPrim. Otherwise the prim doesn’t show if not defaultPrim.

Is there a way using the API to mark the root as ‘defaultPrim’ ?

Thanks! (Sorry if this is a num-num)

i.e., if marked as defaultPrim - my replicator works nicely.

work around
start with a template stage where defaultPrim is set. then modify that to create a new object and save that.

Hello @peter.gaston, I apologize for the extensive delay in getting back to you. A proposed workaround is to create a replicator function that will identify whether the referenced USD has a missing default prim and make a reasonable choice (here, choosing the first prim as the default)

import omni.replicator.core as rep
from typing import List, Tuple

@rep.utils.ReplicatorWrapper
def from_usd_no_default_prim(usd: str, semantics: List[Tuple[str, str]] = None, count: int = 1) -> rep.utils.ReplicatorItem:
    stage = omni.usd.get_context().get_stage()
    xform_paths = []
    
    # Check to see if default prim is set
    # If no default prim is set, use the first prim under root
    usd_stage = Usd.Stage.Open(usd)
    default_prim = ""
    if not usd_stage.HasDefaultPrim():
        top_level_prims = usd_stage.GetPseudoRoot().GetChildren()
        if len(top_level_prims) == 0:
            raise ValueError(f"Asset at {usd} appears to be empty")
        default_prim = str(top_level_prims[0].GetPath())
    print(usd, default_prim)
    
    for _ in range(count):
        xform_path = omni.usd.get_stage_next_free_path(stage, f"{rep.create.REPLICATOR_SCOPE}/Ref_Xform", False)
        stage.DefinePrim(xform_path, "Xform")
        prim_path = f"{xform_path}/Ref"
        ref = stage.DefinePrim(prim_path)
        ref.GetReferences().AddReference(usd, default_prim)
        if semantics:
            utils._set_semantics(ref, semantics)
        xform_paths.append(xform_path)
    node = rep.create.group(xform_paths)
    return node

rep.create.register(from_usd_no_default_prim)

rep.create.from_usd_no_default_prim("/path/to/my/asset.usd")