Create Custom Schema

I would like to create a custom USD schema type. however the documents link in the USD Schema page seems to be broken ( USD Schema — kit-sdk 103.1 documentation ). Is there some tutorials related to USD Schema?

Hi @samcts

This is the code I used to create the custom schemas (RosControlFollowJointTrajectory and RosControlGripperCommand) for the ROS Control extension for example…

Hope that this code helps you in some ways:)

from pxr import Sdf
import omni.isaac.RosBridgeSchema as ROSSchema


class RosControlFollowJointTrajectory(ROSSchema.RosBridgeComponent):
    def __init__(self, prim):
        # RosBridgeComponent:
        # __init__(_object*, pxrInternal_v0_20__pxrReserved__::UsdSchemaBase schemaObj)
        # __init__(_object*, pxrInternal_v0_20__pxrReserved__::UsdPrim prim)
        # __init__(_object*)
        super().__init__(prim)
        
    def __bool__(self):
        return self.GetPrim().IsDefined()

    @staticmethod
    def Define(stage, path):
        prim = stage.DefinePrim(path, "RosControlFollowJointTrajectory")
        return RosControlFollowJointTrajectory(prim)

    def CreateArticulationPrimRel(self):
        self.GetPrim().CreateRelationship("articulationPrim")

    def CreateControllerNameAttr(self, value):
        self.GetPrim().CreateAttribute("controllerName", Sdf.ValueTypeNames.String, True).Set(value)

    def CreateActionNamespaceAttr(self, value):
        self.GetPrim().CreateAttribute("actionNamespace", Sdf.ValueTypeNames.String, True).Set(value)

    @staticmethod
    def Get(stage, path):
        # Get(pxrInternal_v0_19__pxrReserved__::TfWeakPtr<pxrInternal_v0_19__pxrReserved__::UsdStage> stage, pxrInternal_v0_19__pxrReserved__::SdfPath path)
        prim = stage.GetPrimAtPath(path)
        return RosControlFollowJointTrajectory(prim)

    def GetArticulationPrimRel(self):
        return self.GetPrim().GetRelationship("articulationPrim")

    def GetControllerNameAttr(self):
        return self.GetPrim().GetAttribute("controllerName")

    def GetActionNamespaceAttr(self):
        return self.GetPrim().GetAttribute("actionNamespace")

    @staticmethod
    def GetSchemaAttributeNames(includeInherited=True):
        names = []
        if includeInherited: 
            names = ROSSchema.RosBridgeComponent.GetSchemaAttributeNames(includeInherited)
        return names + ["controllerName", "actionNamespace"]


class RosControlGripperCommand(ROSSchema.RosBridgeComponent):
    def __init__(self, prim):
        # RosBridgeComponent:
        # __init__(_object*, pxrInternal_v0_20__pxrReserved__::UsdSchemaBase schemaObj)
        # __init__(_object*, pxrInternal_v0_20__pxrReserved__::UsdPrim prim)
        # __init__(_object*)
        super().__init__(prim)

    def __bool__(self):
        return self.GetPrim().IsDefined()
        
    @staticmethod
    def Define(stage, path):
        prim = stage.DefinePrim(path, "RosControlGripperCommand")
        return RosControlGripperCommand(prim)

    def CreateArticulationPrimRel(self):
        self.GetPrim().CreateRelationship("articulationPrim")

    def CreateControllerNameAttr(self, value):
        self.GetPrim().CreateAttribute("controllerName", Sdf.ValueTypeNames.String, False).Set(value)

    def CreateActionNamespaceAttr(self, value):
        self.GetPrim().CreateAttribute("actionNamespace", Sdf.ValueTypeNames.String, False).Set(value)

    @staticmethod
    def Get(stage, path):
        # Get(pxrInternal_v0_19__pxrReserved__::TfWeakPtr<pxrInternal_v0_19__pxrReserved__::UsdStage> stage, pxrInternal_v0_19__pxrReserved__::SdfPath path)
        prim = stage.GetPrimAtPath(path)
        return RosControlGripperCommand(prim)

    def GetArticulationPrimRel(self):
        return self.GetPrim().GetRelationship("articulationPrim")

    def GetControllerNameAttr(self):
        return self.GetPrim().GetAttribute("controllerName")

    def GetActionNamespaceAttr(self):
        return self.GetPrim().GetAttribute("actionNamespace")

    @staticmethod
    def GetSchemaAttributeNames(includeInherited=True):
        names = []
        if includeInherited: 
            names = ROSSchema.RosBridgeComponent.GetSchemaAttributeNames(includeInherited)
        return names + ["controllerName", "actionNamespace"]