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-121450 - Error when attempting to add a Maya reference to a variant #2091

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions lib/mayaUsd/resources/scripts/mayaUsdAddMayaReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def createMayaReferencePrim(ufePathStr, mayaReferencePath, mayaNamespace,
groupPrim = Usd.Prim()
if not groupPrim.IsValid():
errorMsgFormat = getMayaUsdLibString('kErrorCreatingGroupPrim')
errorMsg = cmds.format(errorMsgFormat, stringArg=(ufePathStr))
errorMsg = cmds.format(errorMsgFormat, stringArg=(ufePathStr, groupPrimName))
om.MGlobal.displayError(errorMsg)
return Usd.Prim()
if groupPrimKind:
Expand All @@ -178,9 +178,16 @@ def createMayaReferencePrim(ufePathStr, mayaReferencePath, mayaNamespace,
# If we created a group prim add the variant set there, otherwise add it
# to the prim that corresponds to the input ufe path.
variantPrim = groupPrim if groupPrim else mayaUsd.ufe.ufePathToPrim(ufePathStr)
vset = variantPrim.GetVariantSet(validatedVariantSetName)
vset.AddVariant(validatedVariantName)
vset.SetVariantSelection(validatedVariantName)
try:
vset = variantPrim.GetVariantSet(validatedVariantSetName)
vset.AddVariant(validatedVariantName)
vset.SetVariantSelection(validatedVariantName)
except (Tf.ErrorException):
errorMsgFormat = getMayaUsdLibString('kErrorCreateVariantSet')
errorMsg = cmds.format(errorMsgFormat,
stringArg=(str(variantPrim.GetPrimPath()), validatedVariantName, str(variantPrim.GetName())))
om.MGlobal.displayError(errorMsg)
return Usd.Prim()
Comment on lines +181 to +190
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trap Usd exceptions while trying to create Variant set and Variant. Issue our own error message.

with vset.GetVariantEditContext():
# Now all of our subsequent edits will go "inside" the
# 'variantName' variant of 'variantSetName'.
Expand All @@ -189,7 +196,7 @@ def createMayaReferencePrim(ufePathStr, mayaReferencePath, mayaNamespace,
prim = createPrimAndAttributes(stage, primPath, mayaReferencePath, mayaNamespace, mayaAutoEdit)
if prim is None or not prim.IsValid():
errorMsgFormat = getMayaUsdLibString('kErrorCreatingMayaRefPrim')
errorMsg = cmds.format(errorMsgFormat, stringArg=(ufePathStr))
errorMsg = cmds.format(errorMsgFormat, stringArg=(ufePathStr, validatedPrimName))
om.MGlobal.displayError(errorMsg)
return Usd.Prim()

Expand Down
11 changes: 6 additions & 5 deletions lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ def mayaUsdLibRegisterStrings():
# Any python strings from MayaUsd lib go here.

# mayaUsdAddMayaReference.py
register('kErrorGroupPrimExists', 'Group prim name "^1s" already exists under "^2s".')
register('kErrorCannotAddToProxyShape', 'Cannot add Maya Reference node to ProxyShape with VariantSet unless Group prim is used.')
register('kErrorMayaRefPrimExists', 'Maya Reference prim name "^1s" already exists under "^2s".')
register('kErrorCreatingGroupPrim', 'Could not create Group prim under "^1s".')
register('kErrorCreatingMayaRefPrim', 'Could not create MayaReference prim under "^1s".')
register('kErrorGroupPrimExists', 'Group prim "^1s" already exists under "^2s". Choose prim name other than "^1s" to proceed.')
register('kErrorCannotAddToProxyShape', 'Cannot add Maya Reference node to ProxyShape with Variant Set unless grouped. Enable Group checkbox to proceed.')
register('kErrorMayaRefPrimExists', 'Maya Reference prim "^1s" already exists under "^2s". Choose Maya Reference prim name other than "^1s" to proceed.')
register('kErrorCreatingGroupPrim', 'Cannot create group prim under "^1s". Ensure target layer is editable and "^2s" can be added to "^1s".')
register('kErrorCreatingMayaRefPrim', 'Cannot create MayaReference prim under "^1s". Ensure target layer is editable and "^2s" can be added to "^1s".')
register('kErrorCreateVariantSet', 'Cannot create Variant Set on prim at path "^1s". Ensure target layer is editable and "^2s" can be added to "^3s".')
Comment on lines +34 to +39
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All error messages (plus new variant one) updated from doc.


# mayaUsdCacheMayaReference.py
register('kButtonNewChildPrim', 'New Child Prim')
Expand Down
15 changes: 15 additions & 0 deletions test/lib/mayaUsd/fileio/testAddMayaReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ def testDefineInVariant(self):
self.assertTrue(attr.IsValid())
self.assertEqual(attr.Get(),True)

# Test an error creating the Variant Set by disabling permission to edit on the
# edit target layer.
editTarget = self.stage.GetEditTarget()
editLayer = editTarget.GetLayer()
editLayer.SetPermissionToEdit(False)
badMayaRefPrim = mayaUsdAddMayaReference.createMayaReferencePrim(
primPathStr,
self.mayaSceneStr,
self.kDefaultNamespace,
mayaReferencePrimName='PrimVariantFail',
variantSet=('VariantFailSet', 'VariantNameFail'),
mayaAutoEdit=False)
self.assertFalse(badMayaRefPrim.IsValid())
editLayer.SetPermissionToEdit(True)

def testBadNames(self):
'''Test using bad prim and variant names.

Expand Down