2
$\begingroup$

So how would I script something that basically duplicated an object and took the last boolean modifier and reversed it while keeping the original modifier order? For example difference to intersect and vice versa?

$\endgroup$
2
$\begingroup$
import bpy
context = bpy.context
scene = context.scene

obj = context.object.copy()

bool_mods = [m for m in obj.modifiers if m.type == 'BOOLEAN']

if len(bool_mods):
    mod = bool_mods[-1]
    if mod.operation == 'DIFFERENCE':
        mod.operation = 'INTERSECT'
    elif mod.operation == 'INTERSECT':
        mod.operation = 'DIFFERENCE'

scene.objects.link(obj)
$\endgroup$
1
  • $\begingroup$ you are the best batfinger! This is exactly what I needed. Also in an understandable format! It works perfectly! Now I am dealing with this silly custom menu icon bs. Its driving me batty haha. $\endgroup$ – masterxeon1001 Nov 14 '15 at 7:34
1
$\begingroup$

Try this if x is the object you want to modify and copyX is the modified object:

import copy

copyX = copy.copy(x)
last = None

for i, val in enumerate(copyX):
    if type(val) == bool:
        last = i

if last is not None:
    copyX[last] = not copyX[last]
$\endgroup$
1
  • $\begingroup$ thats an interesting answer that also does the job! $\endgroup$ – masterxeon1001 Nov 14 '15 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.