Skip to content

Commit c114b4b

Browse files
author
Krystian Ligenza
authored
Merge pull request #1844 from Autodesk/t_gamaj/MAYA-114374/no_parenting_to_instances
MAYA-114374 Prevent parenting under an instance
2 parents 3afdefe + ef73801 commit c114b4b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lib/mayaUsd/ufe/UsdUndoInsertChildCommand.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ UsdUndoInsertChildCommand::UsdUndoInsertChildCommand(
7676
throw std::runtime_error(err.c_str());
7777
}
7878

79+
// Reparenting directly under an instance prim is disallowed
80+
if (parentPrim.IsInstance()) {
81+
std::string err = TfStringPrintf(
82+
"Parenting geometric prim [%s] under instance prim [%s] is not allowed.",
83+
childPrim.GetName().GetString().c_str(),
84+
parentPrim.GetName().GetString().c_str());
85+
throw std::runtime_error(err.c_str());
86+
}
87+
7988
// Apply restriction rules
8089
ufe::applyCommandRestriction(childPrim, "reparent");
8190
ufe::applyCommandRestriction(parentPrim, "reparent");
@@ -115,6 +124,7 @@ UsdUndoInsertChildCommand::Ptr UsdUndoInsertChildCommand::create(
115124
if (parent->path().startsWith(child->path())) {
116125
return nullptr;
117126
}
127+
118128
return std::make_shared<MakeSharedEnabler<UsdUndoInsertChildCommand>>(parent, child, pos);
119129
}
120130

test/lib/ufe/testParentCmd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,15 @@ def testAlreadyChild(self):
939939
self.assertIn("pSphere1", childrenNames(children))
940940
self.assertIn("pCylinderShape1", childrenNames(children))
941941

942+
def testIllegalInstance(self):
943+
'''Parenting an object to an instance must report an error.'''
944+
945+
with OpenFileCtx("simpleHierarchy.ma"):
946+
with self.assertRaises(RuntimeError):
947+
cmds.parent(
948+
"|mayaUsdProxy1|mayaUsdProxyShape1,/hierarchy_instance2",
949+
"|mayaUsdProxy1|mayaUsdProxyShape1,/hierarchy_instance1")
950+
942951
def testUnparentUSD(self):
943952
'''Unparent USD node.'''
944953

test/testSamples/parentCmd/simpleHierarchy.usda

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,23 @@ def Xform "pCylinder1" (
109109
}
110110
}
111111

112+
def "hierarchy_instance1" (
113+
instanceable = true
114+
kind = "component"
115+
prepend references = </pCylinder1>
116+
)
117+
{
118+
double3 xformOp:translate = (9.056107292292669, -3, 0)
119+
uniform token[] xformOpOrder = ["xformOp:translate"]
120+
}
121+
122+
def "hierarchy_instance2" (
123+
instanceable = true
124+
kind = "component"
125+
prepend references = </pCylinder1>
126+
)
127+
{
128+
double3 xformOp:translate = (9.056107292292669, -6, 0)
129+
uniform token[] xformOpOrder = ["xformOp:translate"]
130+
}
131+

0 commit comments

Comments
 (0)