From d758094174f54dd5faf4975111cd6c83846c8160 Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Tue, 27 Apr 2021 10:26:06 -0400 Subject: [PATCH 1/3] MAYA-108221 - As a user, on the prim AE template I'd like to see useful widgets for arrays Add Custom widget for array --- .../resources/ae/usdschemabase/ae_template.py | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py index c36731e4d5..37072351f6 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py @@ -184,6 +184,33 @@ def _onInstanceableChanged(self, value): with mayaUsdLib.UsdUndoBlock(): self.prim.SetInstanceable(value) +# Custom control for all array attribute. +class ArrayCustomControl(aecustom.CustomControl): + + def __init__(self, prim, attrName, *args, **kwargs): + self.prim = prim + self.attrName = attrName + super(ArrayCustomControl, self).__init__(args, kwargs) + + def buildControlUI(self): + attr = self.prim.GetAttribute(self.attrName) + typeName = attr.GetTypeName() + if typeName.isArray: + values = attr.Get() + hasValue = True if values and len(values) > 0 else False + + # build the array type string + # We want something like int[size] or int[] if empty + typeNameStr = str(typeName.scalarType) + typeNameStr += ("[" + str(len(values)) + "]") if hasValue else "[]" + + cmds.textFieldGrp(editable=False, label=getPrettyName(self.attrName), text=typeNameStr) + + if hasValue: + cmds.popupMenu() + cmds.menuItem( label="Copy Attribute Value", command=lambda *args: setClipboardData(str(values)) ) + cmds.menuItem( label="Print to Script Editor", command=lambda *args: print(str(values)) ) + class NoticeListener(object): # Inserted as a custom control, but does not have any UI. Instead we use # this control to be notified from USD when any metadata has changed @@ -229,6 +256,7 @@ def __init__(self, ufeSceneItem): # Get the UFE Attributes interface for this scene item. self.attrS = ufe.Attributes.attributes(self.item) + self.addedAttrs = [] self.suppressedAttrs = [] self.showArrayAttributes = False @@ -237,7 +265,7 @@ def __init__(self, ufeSceneItem): cmds.editorTemplate(beginScrollLayout=True) self.buildUI() - cmds.editorTemplate(addExtraControls=True) + self.createCustomExtraAttrs() self.createMetadataSection() cmds.editorTemplate(endScrollLayout=True) @@ -245,7 +273,12 @@ def __init__(self, ufeSceneItem): def addControls(self, controls): for c in controls: if c not in self.suppressedAttrs: - cmds.editorTemplate(addControl=[c]) + if self.isArrayAttribute(c): + arrayCustomControl = ArrayCustomControl(self.prim, c) + self.defineCustom(arrayCustomControl, c) + else: + cmds.editorTemplate(addControl=[c]) + self.addedAttrs.append(c) def suppress(self, control): cmds.editorTemplate(suppress=control) @@ -334,6 +367,13 @@ def createMetadataSection(self): self.defineCustom(metaDataControl) self.defineCustom(usdNoticeControl) + def createCustomExtraAttrs(self): + # We are not using the maya default "Extra Attributes" section + # because we are using custom widget for array type and it's not + # possible to inject our widget inside the maya "Extra Attributes" section. + extraAttrs = [attr for attr in self.attrS.attributeNames if attr not in self.addedAttrs] + self.createSection("Extra Attributes", extraAttrs, True) + def buildUI(self): usdSch = Usd.SchemaRegistry() From fa4b2409f5fc7b911740598f979d1c01b7543583 Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Tue, 27 Apr 2021 12:38:36 -0400 Subject: [PATCH 2/3] MAYA-108221 - As a user, on the prim AE template I'd like to see useful widgets for arrays - Add missing annotation on array widget - Use s_TPStemplateStrings.rExtraAttributes to get the "Extra Attribute string" - Make ArrayCustomControl hierit from object --- .../resources/ae/usdschemabase/ae_template.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py index fcb2d8c726..6e95740151 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py @@ -185,14 +185,14 @@ def _onInstanceableChanged(self, value): self.prim.SetInstanceable(value) # Custom control for all array attribute. -class ArrayCustomControl(aecustom.CustomControl): +class ArrayCustomControl(object): - def __init__(self, prim, attrName, *args, **kwargs): + def __init__(self, prim, attrName): self.prim = prim self.attrName = attrName - super(ArrayCustomControl, self).__init__(args, kwargs) + super(ArrayCustomControl, self).__init__() - def buildControlUI(self): + def onCreate(self, *args): attr = self.prim.GetAttribute(self.attrName) typeName = attr.GetTypeName() if typeName.isArray: @@ -204,12 +204,17 @@ def buildControlUI(self): typeNameStr = str(typeName.scalarType) typeNameStr += ("[" + str(len(values)) + "]") if hasValue else "[]" - cmds.textFieldGrp(editable=False, label=getPrettyName(self.attrName), text=typeNameStr) + cmds.textFieldGrp(editable=False, label=getPrettyName(self.attrName), text=typeNameStr, annotation=attr.GetDocumentation()) if hasValue: cmds.popupMenu() cmds.menuItem( label="Copy Attribute Value", command=lambda *args: setClipboardData(str(values)) ) cmds.menuItem( label="Print to Script Editor", command=lambda *args: print(str(values)) ) + else: + cmds.error(self.attrName + " must be an array!") + + def onReplace(self, *args): + pass class NoticeListener(object): # Inserted as a custom control, but does not have any UI. Instead we use @@ -379,7 +384,8 @@ def createCustomExtraAttrs(self): # because we are using custom widget for array type and it's not # possible to inject our widget inside the maya "Extra Attributes" section. extraAttrs = [attr for attr in self.attrS.attributeNames if attr not in self.addedAttrs] - self.createSection("Extra Attributes", extraAttrs, True) + sectionName = mel.eval("uiRes(\"s_TPStemplateStrings.rExtraAttributes\");") + self.createSection(sectionName, extraAttrs, True) def createAppliedSchemasSection(self): # USD version 0.21.2 is required because of From 44283b8d1d958b46dc1cfafc0c55428bd705cc16 Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Tue, 27 Apr 2021 13:20:48 -0400 Subject: [PATCH 3/3] MAYA-108221 - As a user, on the prim AE template I'd like to see useful widgets for arrays -Add comments --- lib/mayaUsd/resources/ae/usdschemabase/ae_template.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py index 6e95740151..b5b378c6bd 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py @@ -383,6 +383,11 @@ def createCustomExtraAttrs(self): # We are not using the maya default "Extra Attributes" section # because we are using custom widget for array type and it's not # possible to inject our widget inside the maya "Extra Attributes" section. + + # The extraAttrs will contains suppressed attribute but this is not a big deal as + # long as the suppressed attributes are suppressed by suppress(self, control). + # This function will keep all suppressed attributes into a list which will be use + # by addControls(). So any suppressed attributes in extraAttrs will be ignored later. extraAttrs = [attr for attr in self.attrS.attributeNames if attr not in self.addedAttrs] sectionName = mel.eval("uiRes(\"s_TPStemplateStrings.rExtraAttributes\");") self.createSection(sectionName, extraAttrs, True)