def main(): """Run the main execution of the current script.""" print('Printing the export policies') for variant in UsdUtils.GetRegisteredVariantSets(): print(variant.name, variant.selectionExportPolicy) print('Done') stage = Usd.Stage.CreateInMemory() prim = stage.DefinePrim("/Foo") variant_set = prim.GetVariantSets().AddVariantSet("some_variant_set") variant_set.AddVariant("foo") variant_set.SetVariantSelection("foo") print( 'Notice that, unless we actually check the variant selections ourselves, they still get written to-disk.' ) print(stage.GetRootLayer().ExportToString())
def variantSets_Replace(nodeAttr, new): # Store the original parent and restore it below origParent = cmds.setParent(q=True) frameLayoutName = 'AEpxrUsdReferenceAssemblyTemplate_variantSets_Layout' if new == True: cmds.frameLayout(frameLayoutName, label='VariantSets', collapse=False) else: cmds.setParent(frameLayoutName) # Remove existing children of layout children = cmds.frameLayout(frameLayoutName, q=True, childArray=True) if children: for child in children: cmds.deleteUI(child) # Calculate some parameters node = nodeAttr.split('.', 1)[0] # Create variantSetsDict variantSetsDict = {} usdPrim = UsdMaya.GetPrim(node) from pxr import Usd, UsdUtils regVarSetNames = [ regVarSet.name for regVarSet in UsdUtils.GetRegisteredVariantSets() ] if usdPrim: variantSets = usdPrim.GetVariantSets() variantSetNames = variantSets.GetNames() for variantSetName in variantSetNames: if regVarSetNames and (variantSetName not in regVarSetNames): continue usdVariant = usdPrim.GetVariantSet(variantSetName) if not usdVariant: continue usdVariantChoices = usdVariant.GetVariantNames() usdVariantSelection = usdVariant.GetVariantSelection() variantSetsDict[variantSetName] = { 'variants': usdVariantChoices, 'selection': usdVariantSelection, } # Handle override variantAttrName = 'usdVariantSet_%s' % variantSetName if cmds.attributeQuery(variantAttrName, node=node, exists=True): variantSetPlgVal = cmds.getAttr('%s.%s' % (node, variantAttrName)) if variantSetPlgVal: variantSetsDict[variantSetName][ 'override'] = variantSetPlgVal variantSetsDict[variantSetName]['settable'] = cmds.getAttr( '%s.%s' % (node, variantAttrName), settable=True) # Construct the UI from the variantSetsDict for variantSetName, variantSetDict in variantSetsDict.items(): variantResolved = variantSetDict.get('selection', '') variantOverride = variantSetDict.get('override', '') variantSetChoices = [''] + variantSetDict['variants'] variantSettable = variantSetDict.get('settable', True) omg = cmds.optionMenuGrp(label=variantSetName, enable=variantSettable, extraLabel=variantResolved) for choice in variantSetChoices: cmds.menuItem(label=choice) try: cmds.optionMenuGrp(omg, e=True, value=variantOverride) except RuntimeError: cmds.warning('Invalid choice %r for %r' % (variantOverride, variantSetName)) cmds.optionMenuGrp(omg, e=True, changeCommand=functools.partial( variantSets_changeCommmand, omg=omg, node=node, variantSetName=variantSetName)) # Restore the original parent cmds.setParent(origParent)