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-107424 - On stage AE template load/reload a file as stage source #1218

Merged
merged 2 commits into from
Mar 5, 2021

Conversation

seando-adsk
Copy link
Collaborator

MAYA-107424 - On the stage AE template I'd like to load/reload a file as the stage source

  • Added debugging messages to template helpers (controlled from var).
  • New template helper method to deal with file path being changed from text field and file browser button.
  • New template helper method to refresh file path attribute.
  • Replace file path attribute with custom control containing: label, text field (for path), file browser button, file refresh button.

… as the stage source

* Added debugging messages to template helpers (controlled from var).
* New template helper method to deal with file path being changed
  from text field and file browser button.
* New template helper method to refresh file path attribute.
* Replace file path attribute with custom control containing:
  label, text field (for path), file browser button, file refresh button.
Copy link
Collaborator Author

@seando-adsk seando-adsk left a comment

Choose a reason for hiding this comment

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

There was only one minor change (to a string in the reload dialog) since my demo yesterday.

@seando-adsk seando-adsk added adsk Related to Autodesk plugin enhancement New feature or request labels Feb 26, 2021

# If we have a dirty layer stack, display dialog to confirm new loading.
if dirtyStack:
kTitleFormat = mel.eval('getMayaUsdString("kDiscardStageEditsTitle")')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pretty awkward that there is no way to do this from Python. Certainly getMayaUsdString() isn't doing much, and
https://git.autodesk.com/maya3d/maya/blob/master/Maya/src/OpenMaya/Commands/getPluginResource.mel
isn't doing much either... I guess we can just leave it as you have it, not a big deal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I looked at the MEL procs for register/get string resources and unfortunately they don't have python equivalents. But they are trivial, so I've implemented a python version of them in our plugin and now no longer need the mel.eval.

# Pop the file open dialog for user to load new usd file.
title = mel.eval('getMayaUsdString("kLoadUSDFile")')
okCaption = mel.eval('getMayaUsdString("kLoad")')
fileFilter = mel.eval('getMayaUsdString("kAllUsdFiles")') + ' (*.usd *.usda *.usdc *.usdz );;*.usd;;*.usda;;*.usdc;;*.usdz';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have the filter tokens available in Python? e.g. UsdMayaTranslatorTokens is what we use in c++ when we need filters like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see those in the C++ code, but I don't see anywhere they are wrapped into python. I also checked the USD repo and in their python code they just use the actual strings.

… as the stage source

* Created system to register/get localized strings from python.
  Used that in the AETemplateHelpers file.
Comment on lines +19 to +23
def register(key, value):
registerPluginResource('mayaUsdPlugin', key, value)

def getMayaUsdString(key):
return getPluginResource('mayaUsdPlugin', key)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Identical to the ones in the MEL file (of the same name).

Comment on lines +30 to +35
register("kButtonYes", "Yes")
register("kButtonNo", "No")
register("kDiscardStageEditsTitle", "Discard Edits on ^1s's Layers")
register("kDiscardStageEditsLoadMsg", "Are you sure you want to load in a new file as the stage source?\n\nAll edits on your layers in ^1s will be discarded.")
register("kDiscardStageEditsReloadMsg", "Are you sure you want to reload ^1s as the stage source?\n\nAll edits on your layers (except the session layer) in ^2s will be discarded.")
register("kLoadUSDFile", "Load USD File")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are the strings that are used exclusively from python. But they can also be loaded by MEL.

Comment on lines +37 to +70
def registerPluginResource(pluginId, stringId, resourceStr):
'''See registerPluginResource.mel in Maya.

Unfortunately there is no equivalent python version of this MEL proc
so we created our own version of it here.'''

fullId = 'p_%s.%s' % (pluginId, stringId)
if cmds.displayString(fullId, exists=True):
# Issue warning if the string is already registered.
msgFormat = mel.eval('uiRes("m_registerPluginResource.kNotRegistered")')
msg = cmds.format(msgFormat, stringArg=(pluginId, stringId))
cmds.warning(msg)
# Replace the string's value
cmds.displayString(fullId, replace=True, value=resourceStr)
else:
# Set the string's default value.
cmds.displayString(fullId, value=resourceStr)

def getPluginResource(pluginId, stringId):
'''See getPluginResource.mel in Maya.

Unfortunately there is no equivalent python version of this MEL proc
so we created our own version of it here.'''

# Form full id string.
# Plugin string id's are prefixed with "p_".
fullId = 'p_%s.%s' % (pluginId, stringId)
if cmds.displayString(fullId, exists=True):
dispStr = cmds.displayString(fullId, query=True, value=True)
return dispStr
else:
msgFormat = mel.eval('uiRes("m_getPluginResource.kLookupFailed")')
msg = cmds.format(msgFormat, stringArg=(pluginId, stringId))
cmds.error(msg)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Python ports of the MEL procs from Maya.

Copy link
Contributor

@fowlertADSK fowlertADSK left a comment

Choose a reason for hiding this comment

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

LGTM

@seando-adsk seando-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Mar 4, 2021
@kxl-adsk kxl-adsk merged commit 9a41854 into dev Mar 5, 2021
@kxl-adsk kxl-adsk deleted the donnels/MAYA-107424/load_reload_file_as_stage_source branch March 5, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adsk Related to Autodesk plugin enhancement New feature or request ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants