Skip to content

Commit

Permalink
Merge pull request #3488 from Autodesk/samuelliu-adsk/EMSUSD-835/expo…
Browse files Browse the repository at this point in the history
…rt_selected

EMSUSD-835 - Provide access to the Export Selected options
  • Loading branch information
seando-adsk authored Dec 5, 2023
2 parents 145bae2 + f057b22 commit be465cd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ MStatus MayaUSDExportCommand::doIt(const MArgList& args)
}

// Read all of the dictionary args first.
const VtDictionary userArgs = UsdMayaUtil::GetDictionaryFromArgDatabase(
VtDictionary userArgs = UsdMayaUtil::GetDictionaryFromArgDatabase(
argData, UsdMayaJobExportArgs::GetGuideDictionary());

// Now read all of the other args that are specific to this command.
Expand Down Expand Up @@ -370,7 +370,10 @@ MStatus MayaUSDExportCommand::doIt(const MArgList& args)
MSelectionList objSelList;
UsdMayaUtil::MDagPathSet dagPaths;
bool exportSelected = argData.isFlagSet(kSelectionFlag);
if (!exportSelected) {
if (exportSelected) {
userArgs[UsdMayaJobExportArgsTokens->exportSelected] = true;

} else {
argData.getObjects(objSelList);

if (objSelList.isEmpty()) {
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
{ UsdMayaJobExportArgsTokens->attributeOnly, UsdMayaJobExportArgsTokens->defaultToMesh }))
, exportRefsAsInstanceable(
extractBoolean(userArgs, UsdMayaJobExportArgsTokens->exportRefsAsInstanceable))
, exportSelected(extractBoolean(userArgs, UsdMayaJobExportArgsTokens->exportSelected))
, exportSkels(extractToken(
userArgs,
UsdMayaJobExportArgsTokens->exportSkels,
Expand Down Expand Up @@ -711,6 +712,7 @@ std::ostream& operator<<(std::ostream& out, const UsdMayaJobExportArgs& exportAr
<< "referenceObjectMode: " << exportArgs.referenceObjectMode << std::endl
<< "exportRefsAsInstanceable: " << TfStringify(exportArgs.exportRefsAsInstanceable)
<< std::endl
<< "exportSelected: " << TfStringify(exportArgs.exportSelected) << std::endl
<< "exportSkels: " << TfStringify(exportArgs.exportSkels) << std::endl
<< "exportSkin: " << TfStringify(exportArgs.exportSkin) << std::endl
<< "exportBlendShapes: " << TfStringify(exportArgs.exportBlendShapes) << std::endl
Expand Down Expand Up @@ -972,6 +974,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
= UsdMayaJobExportArgsTokens->none.GetString();
d[UsdMayaJobExportArgsTokens->exportRefsAsInstanceable] = false;
d[UsdMayaJobExportArgsTokens->exportRoots] = std::vector<VtValue>();
d[UsdMayaJobExportArgsTokens->exportSelected] = false;
d[UsdMayaJobExportArgsTokens->exportSkin] = UsdMayaJobExportArgsTokens->none.GetString();
d[UsdMayaJobExportArgsTokens->exportSkels] = UsdMayaJobExportArgsTokens->none.GetString();
d[UsdMayaJobExportArgsTokens->exportBlendShapes] = false;
Expand Down Expand Up @@ -1069,6 +1072,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetGuideDictionary()
d[UsdMayaJobExportArgsTokens->exportRefsAsInstanceable] = _boolean;
d[UsdMayaJobExportArgsTokens->exportRoots] = _stringVector;
d[UsdMayaJobExportArgsTokens->exportSkin] = _string;
d[UsdMayaJobExportArgsTokens->exportSelected] = _boolean;
d[UsdMayaJobExportArgsTokens->exportSkels] = _string;
d[UsdMayaJobExportArgsTokens->exportBlendShapes] = _boolean;
d[UsdMayaJobExportArgsTokens->exportUVs] = _boolean;
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ TF_DECLARE_PUBLIC_TOKENS(
(referenceObjectMode) \
(exportRefsAsInstanceable) \
(exportRoots) \
(exportSelected) \
(exportSkels) \
(exportSkin) \
(exportUVs) \
Expand Down Expand Up @@ -205,6 +206,7 @@ struct UsdMayaJobExportArgs
const TfToken exportRelativeTextures;
const TfToken referenceObjectMode;
const bool exportRefsAsInstanceable;
const bool exportSelected;
const TfToken exportSkels;
const TfToken exportSkin;
const bool exportBlendShapes;
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/python/wrapPrimWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ void wrapJobExportArgs()
.def_readonly("exportRelativeTextures", &UsdMayaJobExportArgs::exportRelativeTextures)
.def_readonly("referenceObjectMode", &UsdMayaJobExportArgs::referenceObjectMode)
.def_readonly("exportRefsAsInstanceable", &UsdMayaJobExportArgs::exportRefsAsInstanceable)
.def_readonly("exportSelected", &UsdMayaJobExportArgs::exportSelected)
.add_property(
"exportSkels",
make_getter(&UsdMayaJobExportArgs::exportSkels, return_value_policy<return_by_value>()))
Expand Down
4 changes: 3 additions & 1 deletion plugin/adsk/plugin/exportTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ MStatus UsdMayaExportTranslator::writer(
MSelectionList objSelList;
UsdMayaUtil::MDagPathSet dagPaths;
const bool exportSelected = (mode == MPxFileTranslator::kExportActiveAccessMode);
if (!exportSelected) {
if (exportSelected) {
userArgs[UsdMayaJobExportArgsTokens->exportSelected] = true;
} else {
if (userArgs.count(UsdMayaJobExportArgsTokens->exportRoots) > 0) {
const auto exportRoots = DictUtils::extractVector<std::string>(
userArgs, UsdMayaJobExportArgsTokens->exportRoots);
Expand Down
17 changes: 17 additions & 0 deletions test/lib/mayaUsd/fileio/testExportChaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class exportChaserTest(mayaUsdLib.ExportChaser):
NotCalled = False
ChaserNames = set()
ChaserArgs = {}
ExportSelected = False

def __init__(self, factoryContext, *args, **kwargs):
super(exportChaserTest, self).__init__(factoryContext, *args, **kwargs)
exportChaserTest.ChaserNames = factoryContext.GetJobArgs().chaserNames
exportChaserTest.ChaserArgs = factoryContext.GetJobArgs().allChaserArgs['test']
exportChaserTest.ExportSelected = factoryContext.GetJobArgs().exportSelected

def ExportDefault(self):
exportChaserTest.ExportDefaultCalled = True
Expand Down Expand Up @@ -85,5 +87,20 @@ def testSimpleExportChaser(self):
self.assertTrue('test' in exportChaserTest.ChaserNames)
self.assertEqual(exportChaserTest.ChaserArgs,{'bar': 'ometer', 'foo': 'tball'})

# test exportSelected
self.assertFalse(exportChaserTest.ExportSelected)
selection = ['apple']
cmds.select(selection)

cmds.usdExport(mergeTransformAndShape=True, selection=True,
file=usdFilePath,
chaser=['test'],
chaserArgs=[
('test', 'foo', 'tball'),
('test', 'bar', 'ometer'),
],
shadingMode='none')
self.assertTrue(exportChaserTest.ExportSelected)

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

0 comments on commit be465cd

Please sign in to comment.