Script that performs a boolean union of all selected objects in a Blender scene
#!BPY
"""
Name: 'Booleall'
Blender: 248
Group: 'Object'
Tooltip: 'Performs boolean union on all selected objects'
__author__ = 'Kasper Jordaens"'
__version__ = '0.1 2008/12/02'
__url__ = ["http://kaos.ashrae.be/project/booleall/"]
__email__ = ["e-mail: kaos*ashrae.be"]
__bpydoc__ =
it still needs some polishing
credits: some of the button code comes from http://infohost.nmt.edu/~jberg/blender/button_demo by Jonathan Berg
"""\
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright 2008 (C) Kasper Jordaens
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
import Blender
import bpy
from Blender import *
global currentfile
currentfile = Blender.Get('filename')
print currentfile
savename = currentfile.replace('.blend','backup.blend')
print savename
scn = Scene.GetCurrent()
t = sys.time()
Window.SetCursorPos(0,0,0)
Window.Redraw
evtPushGO = 0
evtNumSAV = 1
# Set initial values of buttons
numberSAVE = Draw.Create(10)
boolobjects = Blender.Object.GetSelected()
booleall = len(boolobjects)
cyclesincesave = 0
#####init done
def gui():
global evtPushGO, evtNumSAV
global savename, numberSAVE, booleall
BGL.glRasterPos2i(10,150) # position the cursor to write text
Draw.Text("Press Q or ESC to quit.")
BGL.glRasterPos2i(10,135)
Draw.Text("Press GO to perform a boolean union of all selected objects")
BGL.glRasterPos2i(10,120)
Draw.Text("Setting the slider to 0 disables intermediate saving")
BGL.glRasterPos2i(10,95)
Draw.Text("FIRST set cursor to 0,0,0 and center cursor ALL selected objects")
#Draw.Text("intermeditate savefilename is " savename)
#Draw.Text(booleall)
Draw.Button("GO", evtPushGO, 10, 60, 160, 18, "perform Bool union")
numberSAVE = Draw.Number("SaveInterval", evtNumSAV, 10, 40, 160, 18, numberSAVE.val, 0, 100, "number between saves, set to 0 to disable")
BGL.glRasterPos2i(10,15)
#Draw.Text("2008 (C) Kasper Jordaens" )
def main():
global cyclesincesave, numberSAVE, savename
if len(boolobjects) >=2:
booleall = len(boolobjects)
while len(boolobjects)>=2:
ob1 = boolobjects.pop()
ob2 = boolobjects.pop()
obunion = ob1.modifiers
mod = obunion.append(Modifier.Types.BOOLEAN)
mod[Modifier.Settings.OPERATION] = 1
mod[Modifier.Settings.OBJECT] = ob2
ob1.makeDisplayList()
me = Mesh.New()
me.getFromObject(ob1,0,0)
ob = scn.objects.new(me)
boolobjects.append(ob)
#print boolobjects
scn.objects.unlink(ob1)
scn.objects.unlink(ob2)
print booleall - len(boolobjects), 'objects of ', booleall, 'done'
cyclesincesave = cyclesincesave + 1
if cyclesincesave == numberSAVE:
if numberSAVE > 0:
Blender.Save(savename,1)
cyclesincesave = 0
print cyclesincesave
print 'done'
# Timing the script is a good way to be aware on any speed hits when scripting
print 'Booleall finished in %.2f seconds' % (sys.time()-t)
Window.WaitCursor(0)
def event(evt, val): # function that handles keyboard and mouse events
if evt == Draw.ESCKEY or evt == Draw.QKEY:
stop = Draw.PupMenu("OK?%t|Stop script %x1")
if stop == 1:
Draw.Exit()
return
def buttonEvt(evt): # function that handles button events
global evtPush, evtNumSAVE
if evt == evtPushGO:
main()
exit
Draw.Register(gui, event, buttonEvt)
###TODO
# centercursor on all selected obj
#