[Bf-extensions-cvs] [0b4cfab5] master: Bool Tool: port to 2.80
Mikhail Rachinskiy
noreply at git.blender.org
Wed Jan 16 09:24:03 CET 2019
Commit: 0b4cfab541e330aadb02d61c149dfe4916d91531
Author: Mikhail Rachinskiy
Date: Wed Jan 16 12:12:27 2019 +0400
Branches: master
https://developer.blender.org/rBA0b4cfab541e330aadb02d61c149dfe4916d91531
Bool Tool: port to 2.80
Ported by Simon Appelt D4191
===================================================================
M object_boolean_tools.py
===================================================================
diff --git a/object_boolean_tools.py b/object_boolean_tools.py
index 71a62ff7..2410ed8f 100644
--- a/object_boolean_tools.py
+++ b/object_boolean_tools.py
@@ -20,18 +20,15 @@
bl_info = {
"name": "Bool Tool",
- "author": "Vitor Balbio, Mikhail Rachinskiy, TynkaTopi, Meta-Androcto",
- "version": (0, 3, 9),
- "blender": (2, 79, 2),
- "location": "View3D > Toolshelf",
+ "author": "Vitor Balbio, Mikhail Rachinskiy, TynkaTopi, Meta-Androcto, Simon Appelt",
+ "version": (0, 4, 0),
+ "blender": (2, 80, 0),
+ "location": "View3D > Sidebar",
"description": "Bool Tool Hotkey: Ctrl Shift B",
- "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
- "Scripts/Object/BoolTool",
"category": "Object",
}
import bpy
-from bpy.app.handlers import persistent
from bpy.types import (
AddonPreferences,
Operator,
@@ -41,7 +38,6 @@ from bpy.types import (
from bpy.props import (
BoolProperty,
StringProperty,
- EnumProperty,
)
@@ -50,12 +46,12 @@ from bpy.props import (
# Hide boolean objects
def update_BoolHide(self, context):
- ao = context.scene.objects.active
+ ao = context.view_layer.objects.active
objs = [i.object for i in ao.modifiers if i.type == 'BOOLEAN']
hide_state = context.scene.BoolHide
for o in objs:
- o.hide = hide_state
+ o.hide_viewport = hide_state
# Object is a Canvas
@@ -86,14 +82,14 @@ def isPolyBrush(_obj):
def BT_ObjectByName(obj):
- for ob in bpy.context.scene.objects:
+ for ob in bpy.context.view_layer.objects:
if isCanvas(ob) or isBrush(ob):
if ob.name == obj:
return ob
def FindCanvas(obj):
- for ob in bpy.context.scene.objects:
+ for ob in bpy.context.view_layer.objects:
if isCanvas(ob):
for mod in ob.modifiers:
if ("BTool_" in mod.name):
@@ -132,10 +128,10 @@ def isMakeBoundary():
def ConvertToMesh(obj):
- act = bpy.context.scene.objects.active
- bpy.context.scene.objects.active = obj
+ act = bpy.context.view_layer.objects.active
+ bpy.context.view_layer.objects.active = obj
bpy.ops.object.convert(target="MESH")
- bpy.context.scene.objects.active = act
+ bpy.context.view_layer.objects.active = act
# Do the Union, Difference and Intersection Operations with a Brush
@@ -152,7 +148,7 @@ def Operation(context, _operation):
selObj.hide_render = True
cyclesVis = selObj.cycles_visibility
"""
- for obj in bpy.context.scene.objects:
+ for obj in bpy.context.view_layer.objects:
if isCanvas(obj):
for mod in obj.modifiers:
if(mod.name == "BTool_" + selObj.name):
@@ -171,8 +167,8 @@ def Operation(context, _operation):
if _operation == "SLICE":
# copies instance_collection property(empty), but group property is empty (users_group = None)
clone = context.active_object.copy()
- # clone.select = True
- context.scene.objects.link(clone)
+ # clone.select_set(state=True)
+ context.collection.objects.link(clone)
sliceMod = clone.modifiers.new("BTool_" + selObj.name, "BOOLEAN") # add mod to clone obj
sliceMod.object = selObj
sliceMod.operation = "DIFFERENCE"
@@ -196,7 +192,7 @@ def Remove(context, thisObj_name, Prop):
# Restore the Brush
def RemoveThis(_thisObj_name):
- for obj in bpy.context.scene.objects:
+ for obj in bpy.context.view_layer.objects:
# if it's the brush object
if obj.name == _thisObj_name:
cyclesVis = obj.cycles_visibility
@@ -261,7 +257,7 @@ def EnableBrush(context, objList, canvas):
# Find the Canvas and Enable this Brush
def EnableThisBrush(context, set):
canvas = None
- for obj in bpy.context.scene.objects:
+ for obj in bpy.context.view_layer.objects:
if obj != bpy.context.active_object:
if isCanvas(obj):
for mod in obj.modifiers:
@@ -322,7 +318,7 @@ def ApplyAll(context, list):
bpy.ops.object.select_all(action='DESELECT')
for obj in objDeleteList:
- obj.select = True
+ obj.select_set(state=True)
bpy.ops.object.delete()
@@ -336,20 +332,20 @@ def ApplyThisBrush(context, brush):
# EXPERIMENTAL
if isMakeVertexGroup():
# Turn all faces of the Brush selected
- bpy.context.scene.objects.active = brush
+ bpy.context.view_layer.objects.active = brush
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.object.mode_set(mode='OBJECT')
# Turn off al faces of the Canvas selected
- bpy.context.scene.objects.active = canvas
+ bpy.context.view_layer.objects.active = canvas
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
"""
# Apply This Brush
- context.scene.objects.active = obj
+ context.view_layer.objects.active = obj
try:
bpy.ops.object.modifier_apply(modifier=mod.name)
except: # if fails the means it is multiuser data
@@ -371,31 +367,9 @@ def ApplyThisBrush(context, brush):
"""
# Garbage Collector
- brush.select = True
+ brush.select_set(state=True)
# bpy.ops.object.delete()
-
-def GCollector(_obj):
- if isCanvas(_obj):
- BTRoot = False
- for mod in _obj.modifiers:
- if ("BTool_" in mod.name):
- BTRoot = True
- if mod.object is None:
- _obj.modifiers.remove(mod)
- if not BTRoot:
- del _obj["BoolToolRoot"]
-
-
-# Handle the callbacks when modifying things in the scene
- at persistent
-def HandleScene(scene):
- if bpy.data.objects.is_updated:
- for ob in bpy.data.objects:
- if ob.is_updated:
- GCollector(ob)
-
-
# ------------------ Bool Tool OPERATORS --------------------------------------
class BTool_DrawPolyBrush(Operator):
@@ -426,7 +400,7 @@ class BTool_DrawPolyBrush(Operator):
self.count += 1
actObj = bpy.context.active_object
if self.count == 1:
- actObj.select = True
+ actObj.select_set(state=True)
bpy.ops.gpencil.draw('INVOKE_DEFAULT', mode="DRAW_POLY")
if event.type in {'RIGHTMOUSE'}:
@@ -441,9 +415,9 @@ class BTool_DrawPolyBrush(Operator):
for obj in context.selected_objects:
if obj.type == "CURVE":
obj.name = "PolyDraw"
- bpy.context.scene.objects.active = obj
+ bpy.context.view_layer.objects.active = obj
bpy.ops.object.select_all(action='DESELECT')
- obj.select = True
+ obj.select_set(state=True)
bpy.ops.object.convert(target="MESH")
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
@@ -460,12 +434,12 @@ class BTool_DrawPolyBrush(Operator):
obj["BoolToolPolyBrush"] = True
bpy.ops.object.select_all(action='DESELECT')
- bpy.context.scene.objects.active = actObj
- bpy.context.scene.update()
- actObj.select = True
- obj.select = True
+ bpy.context.view_layer.objects.active = actObj
+ bpy.context.view_layer.update()
+ actObj.select_set(state=True)
+ obj.select_set(state=True)
- bpy.context.scene.grease_pencil.clear()
+ bpy.context.view_layer.grease_pencil.clear()
bpy.ops.gpencil.data_unlink()
return {'FINISHED'}
@@ -496,7 +470,7 @@ class BTool_FastTransform(Operator):
bl_label = "Fast Transform"
bl_description = "Enable Fast Transform"
- operator = StringProperty("")
+ operator : StringProperty("")
count = 0
@@ -616,33 +590,32 @@ class Auto_Boolean:
def objects_prepare(self):
for ob in bpy.context.selected_objects:
if ob.type != 'MESH':
- ob.select = False
+ ob.select_set(state=False)
bpy.ops.object.make_single_user(object=True, obdata=True)
bpy.ops.object.convert(target='MESH')
def mesh_selection(self, ob, select_action):
- scene = bpy.context.scene
obj = bpy.context.active_object
- scene.objects.active = ob
+ bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.reveal()
bpy.ops.mesh.select_all(action=select_action)
bpy.ops.object.mode_set(mode='OBJECT')
- scene.objects.active = obj
+ bpy.context.view_layer.objects.active = obj
def boolean_operation(self):
obj = bpy.context.active_object
- obj.select = False
+ obj.select_set(state=False)
obs = bpy.context.selected_objects
self.mesh_selection(obj, 'DESELECT')
for ob in obs:
self.mesh_selection(ob, 'SELECT')
self.boolean_mod(obj, ob, self.mode)
- obj.select = True
+ obj.select_set(state=True)
def boolean_mod(self, obj, ob, mode, ob_delete=True):
md = obj.modifiers.new("Auto Boolean", 'BOOLEAN')
@@ -653,7 +626,7 @@ class Auto_Boolean:
bpy.ops.object.modifier_apply(modifier="Auto Boolean")
if not ob_delete:
return
- bpy.context.scene.objects.unlink(ob)
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list