|
24 | 24 |
|
25 | 25 | from maya import cmds
|
26 | 26 | from maya import mel
|
27 |
| -from maya import standalone |
| 27 | +import maya.internal.common.ufe_ae.template as ufeAeTemplate |
28 | 28 |
|
29 | 29 | from mayaUsdLibRegisterStrings import getMayaUsdLibString
|
30 | 30 | import mayaUsd_createStageWithNewLayer
|
31 |
| - |
32 |
| -from pxr import Usd |
| 31 | +import mayaUsd.lib |
33 | 32 |
|
34 | 33 | import ufe
|
35 | 34 |
|
@@ -527,6 +526,80 @@ def testAEForLight(self):
|
527 | 526 | actualSectionLabels[-len(expectedFinalSectionLabels):],
|
528 | 527 | expectedFinalSectionLabels)
|
529 | 528 |
|
| 529 | + def testAECustomAttributeCallback(self): |
| 530 | + '''Test that the custm atribute callbacks work.''' |
| 531 | + |
| 532 | + # AE template UI callback function. |
| 533 | + self.templateUseCount = 0 |
| 534 | + customSectionName ='UnlikelySectionName' |
| 535 | + |
| 536 | + # Callback function which receives two params as input: callback context and |
| 537 | + # callback data (empty). |
| 538 | + def onBuildAETemplateCallback(context, data): |
| 539 | + # In the callback context you can retrieve the ufe path string. |
| 540 | + ufe_path_string = context.get('ufe_path_string') |
| 541 | + ufePath = ufe.PathString.path(ufe_path_string) |
| 542 | + ufeItem = ufe.Hierarchy.createItem(ufePath) |
| 543 | + self.assertTrue(ufeItem) |
| 544 | + |
| 545 | + # The callback data is empty. |
| 546 | + |
| 547 | + # Note: do not import this globally, because at unit test startup time |
| 548 | + # the Python search path is not setup to find it. Once Maya runs, |
| 549 | + # we can import it. |
| 550 | + from ufe_ae.usd.nodes.usdschemabase.ae_template import AETemplate as mayaUsd_AETemplate |
| 551 | + |
| 552 | + mayaUsdAETemplate = mayaUsd_AETemplate.getAETemplateForCustomCallback() |
| 553 | + self.assertTrue(mayaUsdAETemplate) |
| 554 | + if mayaUsdAETemplate: |
| 555 | + # Create a new section and add attributes to it. |
| 556 | + with ufeAeTemplate.Layout(mayaUsdAETemplate, customSectionName, collapse=False): |
| 557 | + pass |
| 558 | + |
| 559 | + self.templateUseCount = self.templateUseCount + 1 |
| 560 | + |
| 561 | + # Register your callback so it will be called during the MayaUsd AE |
| 562 | + # template UI building code. This would probably done during plugin loading. |
| 563 | + # The first param string 'onBuildAETemplate' is the callback operation and the |
| 564 | + # second is the name of your callback function. |
| 565 | + mayaUsd.lib.registerUICallback('onBuildAETemplate', onBuildAETemplateCallback) |
| 566 | + |
| 567 | + try: |
| 568 | + proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() |
| 569 | + proxyShapePath = ufe.PathString.path(proxyShape) |
| 570 | + proxyShapeItem = ufe.Hierarchy.createItem(proxyShapePath) |
530 | 571 |
|
| 572 | + # Create a capsule prim. |
| 573 | + proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem) |
| 574 | + proxyShapeContextOps.doOp(['Add New Prim', 'Capsule']) |
| 575 | + fullPrimPath = proxyShape + ",/Capsule1" |
| 576 | + cmds.select(fullPrimPath) |
| 577 | + |
| 578 | + # Make sure the AE is visible. |
| 579 | + import maya.mel |
| 580 | + maya.mel.eval('openAEWindow') |
| 581 | + |
| 582 | + capsuleFormLayout = self.attrEdFormLayoutName('Capsule') |
| 583 | + self.assertTrue(cmds.formLayout(capsuleFormLayout, exists=True)) |
| 584 | + startLayout = cmds.formLayout(capsuleFormLayout, query=True, fullPathName=True) |
| 585 | + self.assertIsNotNone(startLayout, 'Could not get full path for Capsule formLayout') |
| 586 | + |
| 587 | + # Augment the maixmum diff size to get better error message when comparing the lists. |
| 588 | + self.maxDiff = 2000 |
| 589 | + |
| 590 | + actualSectionLabels = self.findAllFrameLayoutLabels(startLayout) |
| 591 | + |
| 592 | + # Verify we got the custom section. |
| 593 | + self.assertIn(customSectionName, actualSectionLabels) |
| 594 | + self.assertGreater(self.templateUseCount, 0) |
| 595 | + except: |
| 596 | + # During your plugin unload you should unregister the callback (and any attribute |
| 597 | + # nice naming function you also added). |
| 598 | + mayaUsd.lib.unregisterUICallback('onBuildAETemplate', onBuildAETemplateCallback) |
| 599 | + raise |
| 600 | + else: |
| 601 | + mayaUsd.lib.unregisterUICallback('onBuildAETemplate', onBuildAETemplateCallback) |
| 602 | + |
| 603 | + |
531 | 604 | if __name__ == '__main__':
|
532 | 605 | fixturesUtils.runTests(globals())
|
0 commit comments