Home Technical Talk

MaxScript, Quick Boolean script.

polycounter lvl 13
Offline / Send Message
Fwap polycounter lvl 13
Yo,

I'm trying to write a script that booleans two meshes together, preferably subtraction, and then converts the mesh to editable poly.
I got as far as to do the boolean operation and it converts to a poly, all spicko and nice, trouble is if i try run the script again on the same mesh, but with a different boolean mesh, the results triangulate.

I think it might be because i'm using booleans instead of probooleans, but i've looked into that but i don't know how to code those.

Here's what i have, mostly kit bashed from stuff i've found online and the reference docs. 


(forgive me i don't know how to do the code thingo)

if selection.count < 2
then messageBox ("Please select at least 2 Objects. Thanks.")
else (
objectCount = 1
objectAll = selection.count
 
while objectCount < objectAll do (
objectCount = objectCount + 1
boolObj.createBooleanObject selection[2]
boolObj.setBoolOp selection[2] 4
boolObj.SetOperandB selection[2] selection[1] 4 3
)
GeomButNotPoly = $
ConvertTo GeomButNotPoly Editable_Poly
)

Replies

  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    select the meshs then run this (first mesh selected is the one that'll be kept):
    allSel = selection as array
    if allSel.count >= 2 then (
    keepMesh = allSel[1]
    delMeshs = deleteItem allSel 1
    ProBoolean.createBooleanObjects keepMesh delMeshs 2 0 0
    ConvertTo keepMesh Editable_Poly
    )
    else (messageBox ("Please select at least 2 Objects. Thanks."))
    Alternatively, if you decide that instead of converting to an Editable_Poly each time you want to keep the main mesh as a ProBoolean object, and just add more boolean meshs as you go (without relying on the UI), use this:
    allSel = selection as array
    if allSel.count >= 2 then (
    keepMesh = allSel[1]
    delMeshs = deleteItem allSel 1
    if (classOf keepMesh != ProBoolean) then (ProBoolean.createBooleanObjects keepMesh delMeshs 2 0 0)
    else (for node in delMeshs do ProBoolean.SetOperandB keepMesh node 0 0)
    )
    else (messageBox ("Please select at least 2 Objects. Thanks."))


Sign In or Register to comment.