Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-108221 - As a user, on the prim AE template I'd like to see usef… #1367

Merged
merged 4 commits into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions lib/mayaUsd/resources/ae/usdschemabase/ae_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ def _onInstanceableChanged(self, value):
with mayaUsdLib.UsdUndoBlock():
self.prim.SetInstanceable(value)

# Custom control for all array attribute.
class ArrayCustomControl(object):

def __init__(self, prim, attrName):
self.prim = prim
self.attrName = attrName
super(ArrayCustomControl, self).__init__()

def onCreate(self, *args):
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, 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
# this control to be notified from USD when any metadata has changed
Expand Down Expand Up @@ -229,6 +261,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
Expand All @@ -238,15 +271,20 @@ def __init__(self, ufeSceneItem):
cmds.editorTemplate(beginScrollLayout=True)
self.buildUI()
self.createAppliedSchemasSection()
cmds.editorTemplate(addExtraControls=True)
self.createCustomExtraAttrs()
self.createMetadataSection()
cmds.editorTemplate(endScrollLayout=True)


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)
Expand Down Expand Up @@ -340,6 +378,20 @@ 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.

# 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)

def createAppliedSchemasSection(self):
# USD version 0.21.2 is required because of
# Usd.SchemaRegistry().GetPropertyNamespacePrefix()
Expand Down Expand Up @@ -401,6 +453,7 @@ def createAppliedSchemasSection(self):
typeName = self.sectionNameFromSchema(typeName)
self.createSection(typeName, attrs, False)


def buildUI(self):
usdSch = Usd.SchemaRegistry()

Expand Down