Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Set boolean mode from expression?

Set boolean mode from expression?

DavidHenion
Enthusiast Enthusiast
774 Views
10 Replies
Message 1 of 11

Set boolean mode from expression?

DavidHenion
Enthusiast
Enthusiast

I'd like to override the boolean mode (ie: difference vs intersect) for a certain render layer, but can't see to find the right attribute to change from an expression.

polyBoolean1.booleanMode seems to be only 0 or 1 - not the mode I'm looking for.

polyBoolean1.inputPoly may get to what I need but can't find details on how to access.

I saw a post here referencing polyCBoolOp but I'm not sure what that is?

If I look in the attribute editor for a boolean output object - I can change the boolean operation there for one of the input meshes - just trying to find out how to do that via mel.

Any ideas?

0 Likes
775 Views
10 Replies
Replies (10)
Message 2 of 11

Kahylan
Advisor
Advisor

Hi!

 

What you are looking for is the "operation" attribute on the "polyCBoolOp" object that is responsible for creating the boolean. You can find this object by going over the connection of the "outMesh" on one of the shapeNodes used to create the boolean.

 

Here is an example of how to set all booleans connected to selected object to intersection:

proc changeBoolType(){
  string $sel[] = `ls -sl`;

  for ($s in $sel){
      string $rel[] = `listRelatives -ad -type "mesh" $s`;
      for ($r in $rel){
          
          string $bools[] = `listConnections -t "polyCBoolOp" -s 1 ($r + ".outMesh") `;
          if (size($bools) > 0){
              setAttr ($bools[0] + ".operation") 3;
          }
      }
      
  }  
}


changeBoolType()

 

Ofcourse there are also other ways to find the "polyCBoolOp" object, if you are creating the boolean via code you can store the output of the "polyBoolOp" command in a string Array and the item with index 1 should be your "polyCBoolOp" node.

 

I hope it helps!

Message 3 of 11

DavidHenion
Enthusiast
Enthusiast

Thank you - I think this is what I'm looking for, however I can't get the listConnections command to find the BoolOp node, testing here with a torus and cube:

 

listConnections pCubeShape1;
// Result: polyBoolean1 initialShadingGroup groupId3 initialShadingGroup groupParts2 polyBoolean1 initialShadingGroup groupId4
listConnections pCubeShape1.outMesh;
// Result: polyBoolean1
listConnections -s 1 pCubeShape1.outMesh;
// Result: polyBoolean1
listConnections -t "polyCBoolOp" -s 1 pCubeShape1.outMesh;

 

Any ideas?
Thank you

0 Likes
Message 4 of 11

Kahylan
Advisor
Advisor

What is the result if you run the following line in the same Scene?

objectType("polyBoolean1")
0 Likes
Message 5 of 11

DavidHenion
Enthusiast
Enthusiast

Have been poking at the polyBoolean1 node - seems to do the trick, but I'm kinda guessing at what I'm setting:

 

getAttr polyBoolean1.operation;
// Result: 2 2     # currently in difference mode
setAttr polyBoolean1.operation -type Int32Array 2 2 0 0;
// Error: Cannot perform boolean operation.
setAttr polyBoolean1.operation -type Int32Array 2 2 1 1;    # sets to union
setAttr polyBoolean1.operation -type Int32Array 2 2 3 3;   # sets to interect

 

Don't know why getAttr returns 2 values but setting it requires 4, and the operation value for the polyBoolOp command is a single value.....    The first value seems to be the number of objects (set first value to 1 and it expects 3 total args, setting first value to 2 it expects 4 total args, etc.) but not sure really what I'm setting 🙂

 

Can't find docs on this - any links?

 

0 Likes
Message 6 of 11

DavidHenion
Enthusiast
Enthusiast

objectType("polyBoolean1");
// Result: polyBoolean

0 Likes
Message 7 of 11

Kahylan
Advisor
Advisor

Hmm, are you using maya 2023? Because MEL in 2022.3 doesn't even seem to know the objectType "polyBoolean"

0 Likes
Message 8 of 11

DavidHenion
Enthusiast
Enthusiast

Yes, 2023.1

 

The bigger problem I'm having is when one of the input meshes is animated, maya either constantly recalculates it driving up high cpu, or spits out non-stop can't perfrom bool op messages - when just sitting there with the bool fine and dandy on screen, not playing or scrubbing the timeline.  I switched to 2023 hoping that was fixed, but alas no.  Sometimes when I open a scene with an animated boolean its fine for a bit, but soon starts acting up.  😞

0 Likes
Message 9 of 11

DavidHenion
Enthusiast
Enthusiast
PS: Its not too late in the project to switch back to 2022 if that would be better - the animated bool recalculating issue may be worse though.
0 Likes
Message 10 of 11

Kahylan
Advisor
Advisor

If you work a lot with booleans, I think Maya 2023 will give you better results from looking at the way they handle in the new version. Sadly I can't really try out code for you or analyse the node network myself, since I'm currently obligated by my employer to stick with 2022.

 

The performance issue sounds like a problem, but There seems to be a discussion going on about that in the Modelling forum so I thinks the Devs should be aware of that problem.

As to how you set your attributes. Looking at the differences in how booleans work from 2022 to 2023, I'm assuming, that the difference in amounts of values you need to set stems from the fact that some operations like difference allow you to dynamically change operation order between the objects which doesn't matter for other operations like combine or intersect where the result is always the same. Also I could imagine that some of the new numbers that need to be set refere to the shading mode and smoothmesh settings that the new boolen node brings with it.

But that is just pure speculation, sadly I can't really help you any further with this since I don't know how the node functions in your Maya version
Out of curiosity, could you make a screenshot of the polyBoolean Node with all the Attributes extended in the Node Editor?

0 Likes
Message 11 of 11

DavidHenion
Enthusiast
Enthusiast

Thank you very much for your help - this definitely saved me a ton of time.

 

Screenshot attached of the polyBoolean node.