Skip to content

Commit

Permalink
Implement MDGModifier::setNodeLockState binding
Browse files Browse the repository at this point in the history
  • Loading branch information
yantor3d committed Jun 5, 2021
1 parent d11c9c6 commit 7da6f80
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/MDGModifier.inl
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,18 @@ There should be no function sets attached to the attribute at the time of the ca
}, R"pbdoc(Adds an operation to the modifer to rename a node.)pbdoc")

.def("setNodeLockState", [](MDGModifier & self, MObject node, bool newState) {
throw std::logic_error{"Function not yet implemented."};
if (node.isNull())
{
throw std::invalid_argument("Cannot un/lock a null node.");
} else if (!node.hasFn(MFn::kDependencyNode)) {
MString error_msg("Cannot un/lock object - 'node' must be a 'kDependencyNode' object , not a '^1s' object.");
error_msg.format(error_msg, node.apiTypeStr());
throw pybind11::type_error(error_msg.asChar());
}

MStatus status = self.setNodeLockState(node, newState);

CHECK_STATUS(status)
}, R"pbdoc(Adds an operation to the modifier to set the lockState of a node.)pbdoc")

.def("undoIt", [](MDGModifier & self) {
Expand Down
25 changes: 24 additions & 1 deletion tests/test_MDGModifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,27 @@ def _removeAttribute_fail(exception, node, attr):
exception,
cmdc.DGModifier().removeAttribute,
node, attr
)
)


def test_setNodeLockState():
"""Test MDGModifier::setNodeLockState."""

node = cmds.createNode('network')
node_obj = as_obj(node)
null_obj = cmdc.Object()

mod = cmdc.DGModifier()
mod.setNodeLockState(node_obj, True)

mod.doIt()
assert cmds.lockNode(node, query=True, lock=True)[0], 'DGModifier.setNodeLockState doIt failed'

mod.undoIt()
assert not cmds.lockNode(node, query=True, lock=True)[0], 'DGModifier.setNodeLockState undo failed'

nose.tools.assert_raises(
TypeError,
cmdc.DGModifier().setNodeLockState,
null_obj
)

0 comments on commit 7da6f80

Please sign in to comment.