Skip to content

Commit

Permalink
Merge pull request #1896 from Autodesk/boudrey/MAYA-114711/EditAsMaya…
Browse files Browse the repository at this point in the history
…InSessionLayer

MAYA-114711 As a user, when clicking on 'Edit as Maya Data' I'd like …
  • Loading branch information
seando-adsk authored Dec 16, 2021
2 parents a07ceef + 6a828cc commit b31a6c9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <pxr/base/tf/diagnostic.h>
#include <pxr/base/tf/instantiateSingleton.h>
#include <pxr/usd/sdf/copyUtils.h>
#include <pxr/usd/usd/editContext.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/primRange.h>

Expand Down Expand Up @@ -160,8 +161,12 @@ bool writePullInformation(
fnPullSet.addMember(path);
}

// Store metadata on the prim.
VtValue value(path.fullPathName().asChar());
// Store metadata on the prim in the Session Layer.
auto stage = pulledPrim.GetStage();
if (!stage)
return false;
UsdEditContext editContext(stage, stage->GetSessionLayer());
VtValue value(path.fullPathName().asChar());
pulledPrim.SetCustomDataByKey(kPullPrimMetadataKey, value);

// Store medata on DG node
Expand Down Expand Up @@ -191,6 +196,10 @@ bool writePullInformation(
void removePullInformation(const Ufe::Path& ufePulledPath)
{
UsdPrim prim = MayaUsd::ufe::ufePathToPrim(ufePulledPath);
auto stage = prim.GetStage();
if (!stage)
return;
UsdEditContext editContext(stage, stage->GetSessionLayer());
prim.ClearCustomDataByKey(kPullPrimMetadataKey);
}

Expand Down
33 changes: 32 additions & 1 deletion test/lib/mayaUsd/fileio/testEditAsMaya.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import mayaUtils
import mayaUsd.ufe

from pxr import UsdGeom, Gf
from pxr import Usd, UsdGeom, Gf

from maya import cmds
from maya import standalone
Expand Down Expand Up @@ -135,5 +135,36 @@ def testIllegalEditAsMaya(self):
# self.assertFalse(mayaUsd.lib.PrimUpdaterManager.canEditAsMaya(scopePathStr))
# self.assertFalse(mayaUsd.lib.PrimUpdaterManager.editAsMaya(scopePathStr))

@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3006', 'Test only available in UFE preview version 0.3.6 and greater')
def testSessionLayer(self):
'''Verify that the edit gets on the sessionLayer instead of the editTarget layer.'''

import mayaUsd_createStageWithNewLayer

proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
stage = mayaUsd.lib.GetPrim(proxyShapePathStr).GetStage()
sessionLayer = stage.GetSessionLayer()
prim = stage.DefinePrim('/A', 'Xform')

primPathStr = proxyShapePathStr + ',/A'

self.assertTrue(stage.GetSessionLayer().empty)

self.assertTrue(mayaUsd.lib.PrimUpdaterManager.canEditAsMaya(primPathStr))
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.editAsMaya(primPathStr))

self.assertFalse(stage.GetSessionLayer().empty)

kPullPrimMetadataKey = "Maya:Pull:DagPath"
self.assertEqual(prim.GetCustomDataByKey(kPullPrimMetadataKey), "|__mayaUsd__|AParent|A")

# Discard Maya edits, but there is nothing to discard.
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.discardEdits("A"))

# Now Session Layer should be empty, but it is not, it has an empty content
self.assertFalse(stage.GetSessionLayer().empty)

self.assertEqual(prim.GetCustomDataByKey(kPullPrimMetadataKey), None)

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit b31a6c9

Please sign in to comment.