Script that gives a list of resulting faces


#1

I’m trying to figure out a solution where Maya will return a list of faces created from a Boolean operation so that I can then do things to those specific faces.

Imagine a flower pot sitting on a table. I want to Boolean out the table and close the resulting hole on the bottom of the flower pot (which I’m already doing), but I want a list of those new “hole closing” faces.

Any ideas?


#2

Looks to me like all of that info is hidden away in the polyBoolOp/polyCBoolOp node so I don’t think there’s a way to script this short of writing your own bool operation and exposing the data on your node and/or command.


#3

what command and what operation do you use?


#4

here is an example of how you can get faces made after a poly bool operation. the code of course need some checks but the idea should look clear:

## returns newly created faces

def polyBooleanOp(operation = 1, name = None):
    source, target = cmds.filterExpand(sm=12) ## cmds.ls(sl=1) might be not a polys
    temp_qs = cmds.sets(target + '.f[li]')
[/li]    result = cmds.polyBoolOp(source, target, operation = operation, name = name)
    cmds.select(temp_qs)
    ff = cmds.ls(sl=1)
    cmds.delete(temp_qs)
    ff = cmds.ls(ff)
    cmds.select(ff) # if you want a mesh use: cmds.select(result[0])
    return ff

polyBooleanOp(operation = 2) # bool difference for two polys selected  

#5

here is a test scene:

cmds.file(f=1, new=1)
t = cmds.polySphere(radius=1)
cmds.move(1,0,0)
s = cmds.polyCube(w=2,h=3,d=3)
cmds.select(t, add=1)

polyBooleanOp(operation = 2)