Maya sets -forceElement fail cases that related to renderPartition node

Hi all :slight_smile:

So I have bumped into a few rare cases in Maya these days… lucky I guess.

I was using the command sets -forceElement in my script to assign shaders,
and in some cases I got RuntimeError without clear reason.

> cmds.sets("some_geo.f[0]", forceElement="some_ShadingGroup")
# Error: RuntimeError: file <maya console> line 1: Error while parsing arguments.

Or like this

> cmds.sets("some_geo.f[0]", forceElement="some_ShadingGroup")
# Warning: line 1: Node 'some_geo.instObjGroups[0]': cannot make assignment to 'some_ShadingGroup' shader. # 
# Error: RuntimeError: file <maya console> line 1: Connection not made: 'some_geo.instObjGroups[0]' -> 'some_ShadingGroup.dagSetMembers[-1]'.  Source node will not allow the connection.
# Error: RuntimeError: file <maya console> line 1: Error while parsing arguments.

After hours and hours investigation, I finally able to reproduce them and sort
things out.

Reproducible code (3 cases)

  • Case 1: Duplicaed set member
  • Case 2 & 3: Shader not connected to renderPartition node

In the test, you should have a cube that has assigned a red phong
shader, and in case 2 & 3, you can not re-assign the cube into other shader.

Set & Partition

So based on the tests result and what Maya document says about the partition node

A partition is a collection of related sets. Partitions prevent the sets in them from having any overlapping members. Maya uses partitions to keep sets separate where overlapping members could cause problems.

I guess in the case 1, that duplicated connection actually made Maya thinks that there are overlapping members, so the command failed.
But you could run the command again without error, because the connections actually has been removed.

For case 2 & 3, in my speculation, since the shader has no related partition to calculate member overlapping, so the command failed.

What do you think ? Did I misunderstand it ?
Hoping someone could explain the reason better. :slight_smile: