How to obtain a list of Single or Multi-apply API Schemas?

Hello,

Is it possible to query all available single/multi-apply API schemas?
I’m having a hard time finding how to obtain such a list, been looking at SchemaRegistry but can’t figure it out.

Workflow is to allow a user to browse a list, select one, and apply it to a prim (if it can apply).

Thanks!
Scott

Hi @ScottRenaud , you’re right there’s no API on UsdSchemaRegistry for enumeration. It makes sense that you’d expect such API there, though I’m a little hesitant about us adding such before we have tackled the “per-stage schemas” project, which may result in schemas unknown to the SchemaRegistry singleton.

What we do in Presto and other apps is rely on the TfType system for enumeration. Fetch the TfType for UsdSchemaBase, and then call GetAllDerivedTypes() on the returned object, whic hwill get you the TfTypes of all registered schema classes. You can segregate just the API schemas by instead using UsdAPISchemaBase

Thanks for the pointer @spiff, got it to work!

from pxr import Usd, Tf
schema_reg = Usd.SchemaRegistry()
single_apply_list = []
multiple_apply_list = []
for t in Tf.Type.FindByName("UsdAPISchemaBase").GetAllDerivedTypes():
    if not (schema_reg.IsAppliedAPISchema(t) or schema_reg.IsMultipleApplyAPISchema(t)):        
        continue
    
    if (schema_reg.IsAppliedAPISchema(t) and not schema_reg.IsMultipleApplyAPISchema(t)):
        single_apply_list.append(str(t).split("'")[1::2][0])
        
    if (schema_reg.IsMultipleApplyAPISchema(t)):
        multiple_apply_list.append(str(t).split("'")[1::2][0])
        

# Sort and print
print("Single-apply API Schemas:")
for x in sorted(single_apply_list):
    print(x)
print("\nMulti-apply API Schemas:")
for x in sorted(multiple_apply_list):
    print(x)

Running this in Maya gives me:
Single-apply API Schemas:
UsdArnoldBoxAPI
UsdArnoldCameraAPI
UsdArnoldConeAPI
UsdArnoldCurvesAPI
UsdArnoldCylinderAPI
UsdArnoldDiskLightAPI
UsdArnoldDistantLightAPI
UsdArnoldLightAPI
UsdArnoldMeshLightAPI
UsdArnoldOrthoCameraAPI
UsdArnoldPerspCameraAPI
UsdArnoldPointLightAPI
UsdArnoldPointsAPI
UsdArnoldPolymeshAPI
UsdArnoldQuadLightAPI
UsdArnoldShapeAPI
UsdArnoldSkydomeLightAPI
UsdArnoldSphereAPI
UsdGeomModelAPI
UsdGeomMotionAPI
UsdGeomVisibilityAPI
UsdHydraGenerativeProceduralAPI
UsdLuxLightAPI
UsdLuxLightListAPI
UsdLuxListAPI
UsdLuxMeshLightAPI
UsdLuxShadowAPI
UsdLuxShapingAPI
UsdLuxVolumeLightAPI
UsdMediaAssetPreviewsAPI
UsdPhysicsArticulationRootAPI
UsdPhysicsCollisionAPI
UsdPhysicsFilteredPairsAPI
UsdPhysicsMassAPI
UsdPhysicsMaterialAPI
UsdPhysicsMeshCollisionAPI
UsdPhysicsRigidBodyAPI
UsdRiMaterialAPI
UsdRiRenderPassAPI
UsdRiSplineAPI
UsdRiStatementsAPI
UsdShadeMaterialBindingAPI
UsdShadeNodeDefAPI
UsdSkelBindingAPI
UsdUINodeGraphNodeAPI
UsdUISceneGraphPrimAPI

Multi-apply API Schemas:
UsdCollectionAPI
UsdPhysicsDriveAPI
UsdPhysicsLimitAPI
UsdShadeCoordSysAPI

1 Like

Great, @ScottRenaud , though note that the multi-apply schemas are also showing up in your Single-Apply list, because IsAppliedSchema answers true for both. You probably want to additionally use the negation of IsMultipleApplySchema for the single-applies.

1 Like

Thanks I updated the script and output above!