Skip to content

Commit

Permalink
Implement MDGModfifier::removeMultiInstance binding
Browse files Browse the repository at this point in the history
  • Loading branch information
yantor3d committed Jun 6, 2021
1 parent 79f223a commit fca84a0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MDGModifier.inl
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,12 @@ The attribute MObject passed in will be set to kNullObj.
There should be no function sets attached to the attribute at the time of the call as their behaviour may become unpredictable.)pbdoc")

.def("removeMultiInstance", [](MDGModifier & self, MPlug plug, bool breakConnections) {
throw std::logic_error{"Function not yet implemented."};
plug::assert_not_null(plug);
plug::assert_is_element(plug);

MStatus status = self.removeMultiInstance(plug, breakConnections);

CHECK_STATUS(status);
}, R"pbdoc(Adds an operation to the modifier to remove an element of a multi (array) plug.)pbdoc")

.def("renameAttribute", [](MDGModifier & self, MObject node, MObject attribute, std::string shortName, std::string longName) {
Expand Down
56 changes: 56 additions & 0 deletions tests/test_MDGModifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,62 @@ def test_removeExtensionAttribute_pass():



@nose.with_setup(teardown=new_scene)
def test_removeMultiInstance_pass():
"""Test MDGModfifier::removeMultiInstance binding."""

node = cmds.createNode('network')

cmds.addAttr(node, ln='pass', multi=True)

plug_obj = as_plug(node + '.pass')
null_obj = cmdc.Plug()

cmds.setAttr(node + '.pass[0]', 1.0)
cmds.setAttr(node + '.pass[1]', 1.0)
cmds.setAttr(node + '.pass[2]', 1.0)

index_obj = plug_obj.elementByLogicalIndex(1)

mod = cmdc.DGModifier()
mod.removeMultiInstance(index_obj, True)

mod.doIt()
assert plug_obj.getExistingArrayAttributeIndices() == [0, 2], 'DGMOdifier.removeMultiInstance doIt failed'

mod.undoIt()
assert plug_obj.getExistingArrayAttributeIndices() == [0, 1, 2], 'DGMOdifier.removeMultiInstance undoIt failed'




@nose.with_setup(teardown=new_scene)
def test_removeMultiInstance_fail():
"""Test MDGModfifier::removeMultiInstance binding error handling."""

node = cmds.createNode('network')

cmds.addAttr(node, ln='fail')

plug_obj = as_plug(node + '.fail')
null_obj = cmdc.Plug()

for exception, doc, plug_obj in (
[ValueError, 'a null plug', null_obj],
[TypeError, 'a non-element plug', plug_obj],
):
test_removeMultiInstance_fail.__doc__ = """Test MDGModifier::removeMultiInstance raises an error if called with {}.""".format(doc)

yield _removeMultiInstance_fail, exception, plug_obj


def _removeMultiInstance_fail(exception, plug_obj):
nose.tools.assert_raises(
exception,
cmdc.DGModifier().removeMultiInstance,
plug_obj, True
)


@nose.with_setup(teardown=new_scene)
def test_renameAttribute():
Expand Down

0 comments on commit fca84a0

Please sign in to comment.