Boolean Modifier gives unpredictable results when executed in a loop via Python API #66593

Closed
opened 2019-07-09 09:44:55 +02:00 by SagRU · 14 comments

System Information
Operating system: Windows-10-10.0.17763 64 Bits
Graphics card: Intel(R) HD Graphics 530 Intel 4.5.0 - Build 25.20.100.6373

Blender Version
Broken: version: 2.80 (sub 74), branch: master, commit date: 2019-07-08 23:33, hash: ac8c795429

Short description of error
When I try to use Boolean Modifier for a set of meshes in a loop via Python API I get some weird results. For instance, some meshes get joined with target object.

Exact steps for others to reproduce the error

  1. Open the attached *.blend file in Blender 2.8
  2. Switch to Scripting workspace
  3. Execute the code below in Python console
  4. See the upsetting result in 3D view

Code to execute:

planes_to_cut = []

for obj in bpy.data.objects:
	if "Cut_Me_" in obj.name:
		planes_to_cut.append(obj)
	
bpy.ops.object.select_all(action='DESELECT')

for i, plane in enumerate(planes_to_cut):
    bpy.ops.mesh.primitive_cube_add()
    wall_slicer = bpy.context.view_layer.objects.active
    wall_slicer.name = "Wall_Slicer_" + str(i)
    wall_slicer.dimensions = (500, 500, 70)
    wall_slicer.location[2] = 30
    bpy.ops.object.select_all(action='DESELECT')
    plane.select_set(True)
    bpy.context.view_layer.objects.active = plane
    boolean_mod = plane.modifiers.new(type="BOOLEAN", name="Boolean")
    boolean_mod.object = wall_slicer
    boolean_mod.operation = 'DIFFERENCE'
    bpy.ops.object.modifier_apply(apply_as='DATA', modifier=boolean_mod.name)
    bpy.ops.object.select_all(action='DESELECT')
    wall_slicer.select_set(True)
    bpy.context.view_layer.objects.active = wall_slicer
    bpy.data.objects.remove(wall_slicer, do_unlink = True)

Blend file:
Boolean_Bug.blend

Video of the problem:
Boolean_video.mp4

**System Information** Operating system: Windows-10-10.0.17763 64 Bits Graphics card: Intel(R) HD Graphics 530 Intel 4.5.0 - Build 25.20.100.6373 **Blender Version** Broken: version: 2.80 (sub 74), branch: master, commit date: 2019-07-08 23:33, hash: `ac8c795429` **Short description of error** When I try to use Boolean Modifier for a set of meshes in a loop via Python API I get some weird results. For instance, some meshes get joined with target object. **Exact steps for others to reproduce the error** 1) Open the attached *.blend file in Blender 2.8 2) Switch to Scripting workspace 3) Execute the code below in Python console 4) See the upsetting result in 3D view Code to execute: ``` planes_to_cut = [] for obj in bpy.data.objects: if "Cut_Me_" in obj.name: planes_to_cut.append(obj) bpy.ops.object.select_all(action='DESELECT') for i, plane in enumerate(planes_to_cut): bpy.ops.mesh.primitive_cube_add() wall_slicer = bpy.context.view_layer.objects.active wall_slicer.name = "Wall_Slicer_" + str(i) wall_slicer.dimensions = (500, 500, 70) wall_slicer.location[2] = 30 bpy.ops.object.select_all(action='DESELECT') plane.select_set(True) bpy.context.view_layer.objects.active = plane boolean_mod = plane.modifiers.new(type="BOOLEAN", name="Boolean") boolean_mod.object = wall_slicer boolean_mod.operation = 'DIFFERENCE' bpy.ops.object.modifier_apply(apply_as='DATA', modifier=boolean_mod.name) bpy.ops.object.select_all(action='DESELECT') wall_slicer.select_set(True) bpy.context.view_layer.objects.active = wall_slicer bpy.data.objects.remove(wall_slicer, do_unlink = True) ``` Blend file: [Boolean_Bug.blend](https://archive.blender.org/developer/F7578623/Boolean_Bug.blend) Video of the problem: [Boolean_video.mp4](https://archive.blender.org/developer/F7578758/Boolean_video.mp4)
Author

Added subscriber: @WannaBe

Added subscriber: @WannaBe

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

I can't reproduce this (Blender 516afd0162), for me the script doesn't do anything. Looking at the code, the 'wall slicer' doesn't intersect with any walls (I put a break in the code to stop it after the wall slicer was created):

image.png

So for me the script works as expected, I guess.

I can't reproduce this (Blender 516afd0162cd2e217ec50ce522f87317b73f0088), for me the script doesn't do anything. Looking at the code, the 'wall slicer' doesn't intersect with any walls (I put a `break` in the code to stop it after the wall slicer was created): ![image.png](https://archive.blender.org/developer/F7578701/image.png) So for me the script works as expected, I guess.

Added subscriber: @ZedDB

Added subscriber: @ZedDB

Exactly what do you expect the code to do? The walls are have zero width so they will probably now work nicely with any boolean operation.

Exactly what do you expect the code to do? The walls are have zero width so they will probably now work nicely with any boolean operation.
Author

I've attached the video that shows the problem. Two planes were cut as expected, whereas other two merged with their target object (wall_slicer).

I've attached the video that shows the problem. Two planes were cut as expected, whereas other two merged with their target object (wall_slicer).

Added subscriber: @capnm

Added subscriber: @capnm

I've attached the video that shows the problem. Two planes were cut as expected, whereas other two merged with their target object (wall_slicer).

It has nothing to do with the Python API. You get the same bad results when you try it in the UI.
AFAICT the solver in blender8 only gives much worse results here than in blender7:
boolean-diff-b8-b7.png

> I've attached the video that shows the problem. Two planes were cut as expected, whereas other two merged with their target object (wall_slicer). It has nothing to do with the Python API. You get the same bad results when you try it in the UI. AFAICT the solver in blender8 only gives much worse results here than in blender7: ![boolean-diff-b8-b7.png](https://archive.blender.org/developer/F7579457/boolean-diff-b8-b7.png)
Author

In #66593#716451, @capnm wrote:

I've attached the video that shows the problem. Two planes were cut as expected, whereas other two merged with their target object (wall_slicer).

It has nothing to do with the Python API. You get the same bad results when you try it in the UI.
AFAICT the solver in blender8 only gives much worse results here than in blender7:
boolean-diff-b8-b7.png

My bad... I thought that the problem was caused by looping. It seems that orientation in space matters for Boolean Modifier.

> In #66593#716451, @capnm wrote: >> I've attached the video that shows the problem. Two planes were cut as expected, whereas other two merged with their target object (wall_slicer). > > It has nothing to do with the Python API. You get the same bad results when you try it in the UI. > AFAICT the solver in blender8 only gives much worse results here than in blender7: > ![boolean-diff-b8-b7.png](https://archive.blender.org/developer/F7579457/boolean-diff-b8-b7.png) My bad... I thought that the problem was caused by looping. It seems that orientation in space matters for Boolean Modifier.

My bad... I thought that the problem was caused by looping. It seems that orientation in space matters for Boolean Modifier.

AFAICT the solver in blender8 only gives much worse results here than in blender7:

Ah right, I'll take this back, I accidentally rotated the view in Blender 2.7x, the results of the boolean-op are the same ...

> My bad... I thought that the problem was caused by looping. It seems that orientation in space matters for Boolean Modifier. >> AFAICT the solver in blender8 only gives much worse results here than in blender7: Ah right, I'll take this back, I accidentally rotated the view in Blender 2.7x, the results of the boolean-op are the same ...

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sebastian Parborg self-assigned this 2019-07-10 10:09:23 +02:00

Right, this is not a bug but a limitation of the boolean modifier. There are plans to make it better in the future, and we already have tasks for that. So I'll close this.

Right, this is not a bug but a limitation of the boolean modifier. There are plans to make it better in the future, and we already have tasks for that. So I'll close this.

https://developer.blender.org/T47030 ;-)

To make the current boolean operator work in a script or addon, you have to randomize/tweak the size or rotation of the 'cutter' mesh.
Peek19.gif

https://developer.blender.org/T47030 ;-) To make the current boolean operator work in a script or addon, you have to randomize/tweak the size or rotation of the 'cutter' mesh. ![Peek19.gif](https://archive.blender.org/developer/F7581108/Peek19.gif)
Author

In #66593#717159, @capnm wrote:
https://developer.blender.org/T47030 ;-)

To make the current boolean operator work in a script or addon, you have to randomize/tweak the size or rotation of the 'cutter' mesh.
Peek19.gif

Thanks for your hint!

> In #66593#717159, @capnm wrote: > https://developer.blender.org/T47030 ;-) > > To make the current boolean operator work in a script or addon, you have to randomize/tweak the size or rotation of the 'cutter' mesh. > ![Peek19.gif](https://archive.blender.org/developer/F7581108/Peek19.gif) Thanks for your hint!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#66593
No description provided.