Skip to content
Merged
Changes from 1 commit
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
83 changes: 51 additions & 32 deletions lib/usd/ui/layerEditor/mayaCommandHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,35 @@
#include <QtCore/QStringList>

#include <cassert>
#include <iomanip>
#include <sstream>
#include <string>

#define STR(x) std::string(x)

namespace {

std::string quote(const std::string& string) { return STR(" \"") + string + STR("\""); }
std::string quoteForCommand(const std::string& string)
{
std::ostringstream oss;
oss << " " << std::quoted(string);
return oss.str();
}

std::string quoteLayerIdentifierForCommand(const PXR_NS::SdfLayerRefPtr& usdLayer)
{
if (!usdLayer) {
return "";
}

return quoteForCommand(usdLayer->GetIdentifier());
}

std::string quoteFilePathForCommand(const std::string& path)
{
// Note: C++ std::quoted() already handles backslashes.
return quoteForCommand(path);
}

std::string getProxyShapeName(const std::string& proxyShapePath)
{
Expand Down Expand Up @@ -90,8 +112,8 @@ std::string MayaCommandHook::proxyShapePath()
void MayaCommandHook::setEditTarget(UsdLayer usdLayer)
{
std::string cmd;
cmd = STR("mayaUsdEditTarget -edit -editTarget ") + quote(usdLayer->GetIdentifier());
cmd += " " + quote(proxyShapePath());
cmd = STR("mayaUsdEditTarget -edit -editTarget ") + quoteLayerIdentifierForCommand(usdLayer);
cmd += quoteForCommand(proxyShapePath());
executeMel(cmd);
}

Expand All @@ -118,8 +140,8 @@ void MayaCommandHook::insertSubLayerPath(UsdLayer usdLayer, Path path, int index
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -insertSubPath ";
cmd += std::to_string(index);
cmd += quote(path);
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteFilePathForCommand(path);
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -131,8 +153,8 @@ void MayaCommandHook::removeSubLayerPath(UsdLayer usdLayer, Path path)
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -removeSubPath ";
cmd += std::to_string(index);
cmd += quote(proxyShapePath());
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteForCommand(proxyShapePath());
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -144,10 +166,10 @@ void MayaCommandHook::moveSubLayerPath(
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -moveSubPath ";
cmd += quote(path);
cmd += quote(newParentUsdLayer->GetIdentifier());
cmd += std::to_string(index);
cmd += quote(oldParentUsdLayer->GetIdentifier());
cmd += quoteFilePathForCommand(path);
cmd += quoteLayerIdentifierForCommand(newParentUsdLayer);
cmd += " " + std::to_string(index);
cmd += quoteLayerIdentifierForCommand(oldParentUsdLayer);
executeMel(cmd);
}

Expand All @@ -156,9 +178,9 @@ void MayaCommandHook::replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -replaceSubPath ";
cmd += quote(oldPath);
cmd += quote(newPath);
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteFilePathForCommand(oldPath);
cmd += quoteFilePathForCommand(newPath);
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -167,7 +189,7 @@ void MayaCommandHook::discardEdits(UsdLayer usdLayer)
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -discardEdits ";
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);

refreshLayerSystemLock(usdLayer);
Expand All @@ -178,7 +200,7 @@ void MayaCommandHook::clearLayer(UsdLayer usdLayer)
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -clear ";
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -187,7 +209,7 @@ void MayaCommandHook::flattenLayer(UsdLayer usdLayer)
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -flatten ";
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -196,8 +218,8 @@ UsdLayer MayaCommandHook::addAnonymousSubLayer(UsdLayer usdLayer, std::string ne
{
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -addAnonymous ";
cmd += quote(newName);
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteFilePathForCommand(newName);
cmd += quoteLayerIdentifierForCommand(usdLayer);
std::string result = executeMel(cmd);
if (result.size() > 0)
return PXR_NS::SdfLayer::FindOrOpen(result);
Expand All @@ -211,8 +233,8 @@ void MayaCommandHook::muteSubLayer(UsdLayer usdLayer, bool muteIt)
std::string cmd;
cmd = "mayaUsdLayerEditor -edit -muteLayer ";
cmd += muteIt ? "1" : "0";
cmd += quote(proxyShapePath());
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteForCommand(proxyShapePath());
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -231,8 +253,8 @@ void MayaCommandHook::lockLayer(
cmd = "mayaUsdLayerEditor -edit -skipSystemLocked -lockLayer ";
cmd += std::to_string(lockState);
cmd += includeSubLayers ? " 1" : " 0";
cmd += quote(proxyShapePath());
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteForCommand(proxyShapePath());
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd);
}

Expand All @@ -249,10 +271,9 @@ void MayaCommandHook::refreshLayerSystemLock(UsdLayer usdLayer, bool refreshSubL

std::string cmd;
cmd = "mayaUsdLayerEditor -edit -refreshSystemLock ";
cmd += quote(shapePath);
cmd += " ";
cmd += std::to_string(refreshSubLayers);
cmd += quote(usdLayer->GetIdentifier());
cmd += quoteForCommand(shapePath);
cmd += refreshSubLayers ? " 1" : " 0";
cmd += quoteLayerIdentifierForCommand(usdLayer);
executeMel(cmd, false);
}

Expand All @@ -269,14 +290,12 @@ void MayaCommandHook::stitchLayers(const std::vector<PXR_NS::SdfLayerRefPtr>& la
continue;

cmd += "-stitchLayers ";
cmd += quote(proxyShape);
cmd += " ";
cmd += quote(layer->GetIdentifier());
cmd += " ";
cmd += quoteForCommand(proxyShape);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't we need cmd += " "; after this line and line 298 similar to the old code? I don't see quoteForCommand adding a space after its command.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Every "quote" function adds a prefix space, so we don't need to add extra spaces.

@AramAzhari-adsk AramAzhari-adsk Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

all except -stichLayers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ie in the for loop that's on line 288 the cmd -stichLayers is being added without a space, and the quote command isn't adding a space at the end.

End of iter 1: ... "proxy" "id1"
Iter 2 starts with cmd += "-stitchLayers "; → ... "id1"-stitchLayers

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that one the original code put teh space AFTER stitchLayer and I missed it, good catch.

cmd += quoteLayerIdentifierForCommand(layer);
}

// Target layer isn't actually used, but needed for the command syntax.
cmd += quote(layers[0]->GetIdentifier());
cmd += quoteLayerIdentifierForCommand(layers[0]);
executeMel(cmd);
}

Expand Down
Loading