1
$\begingroup$

I have a plane in blender, generated using a script with known coordinates. I'd like to cut multiple polygons out of the plane. The coordinates of the polygon vertices are already known with respect to the plane. What I've tried:

  1. Making multiple planes and removing them using boolean difference. This didn't work as the planes are 2D.
  2. Defining the vertices for the polygons to be removed and cutting them out, but I didn't see an obvious way to remove them.
  3. Adding a negligible thickness to the planes and performing the boolean operation. This seems like it will work, but seems fairly inefficient.

Any suggestions are appreciated. Thank you!

$\endgroup$
2
  • $\begingroup$ As 3a) you can add a solidify modifier before the boolean to get your thickness, then delete the solidify after the boolean is applied. $\endgroup$
    – Ron Jensen
    Commented Apr 9 at 19:50
  • $\begingroup$ @RonJensen, thank you for the comment, that sounds like a simple idea. I ended up sorting it out a different way. I'll add add the code here shortly. $\endgroup$
    – derekboase
    Commented Apr 10 at 18:46

1 Answer 1

0
$\begingroup$

I ended up creating the vertex points, adding the corresponding edges between them, going into edit mode, filling it then going back to object mode. This corresponds closely to 2. in my question. Here's the code:

import bpy

from os import system 
system('clear')

def create_custom_mesh(objname, trans, rot, myvertices, myedges):
    
    # Mesh and object instances
    mymesh = bpy.data.meshes.new(objname)
    myobject = bpy.data.objects.new(objname, mymesh)
    
    # Link and generate mesh data using the vertices and the defined edges 
    bpy.data.collections['Collection'].objects.link(myobject)
    mymesh.from_pydata(myvertices, myedges, [])
    
    # Set Location
    myobject.location.x, myobject.location.y, myobject.location.z = trans
    
    # Fill in the plane using the fill feature
    bpy.context.view_layer.objects.active = bpy.data.objects[objname] # Select the edges
    bpy.ops.object.mode_set(mode='EDIT') # Go to edit mode
    bpy.ops.mesh.fill() # Fill the shape
    bpy.ops.object.mode_set(mode='OBJECT') # Return to object mode

    return myobject


# Housekeeping namings 
plane_nm = "plane"

# Geometry definitions
trns = (0, 0, 0)
rot = (0, 0, 0)

# First four elements are the background plane vertices, the rest are vertices corresponding 
# to an arbitrary ordered polygon
myvertices_plane = [
    [0., 0., 0.], [4., 0., 0.],
    [4., 3., 0.], [0., 3., 0.], 
    [3.627, 2.685, 0.0], [3.624, 2.688, 0.0], 
    [3.623, 2.691, 0.0], [3.619, 2.696, 0.0], 
    [3.619, 2.698, 0.0], [3.617, 2.7, 0.0], 
    [3.618, 2.702, 0.0], [3.618, 2.706, 0.0], 
    [3.616, 2.708, 0.0], [3.617, 2.709, 0.0], 
    [3.617, 2.711, 0.0], [3.618, 2.712, 0.0], 
    [3.618, 2.714, 0.0], [3.619, 2.715, 0.0], 
    [3.619, 2.717, 0.0], [3.62, 2.718, 0.0], 
    [3.62, 2.72, 0.0], [3.621, 2.721, 0.0], 
    [3.621, 2.723, 0.0], [3.622, 2.724, 0.0], 
    [3.623, 2.729, 0.0], [3.625, 2.732, 0.0], 
    [3.625, 2.734, 0.0], [3.63, 2.738, 0.0], 
    [3.633, 2.746, 0.0], [3.638, 2.75, 0.0], [3.639, 2.75, 0.0], [3.643, 2.754, 0.0], [3.644, 2.754, 0.0], 
    [3.657, 2.765, 0.0], [3.659, 2.766, 0.0], [3.663, 2.766, 0.0], [3.666, 2.769, 0.0], [3.671, 2.769, 0.0], 
    [3.675, 2.773, 0.0], [3.685, 2.773, 0.0], [3.688, 2.769, 0.0], [3.69, 2.769, 0.0], [3.691, 2.768, 0.0], 
    [3.698, 2.768, 0.0], [3.698, 2.767, 0.0], [3.701, 2.764, 0.0], [3.704, 2.764, 0.0], [3.704, 2.762, 0.0], 
    [3.706, 2.76, 0.0], [3.706, 2.758, 0.0], [3.708, 2.756, 0.0], [3.71, 2.752, 0.0], [3.71, 2.749, 0.0], 
    [3.709, 2.748, 0.0], [3.709, 2.746, 0.0], [3.711, 2.744, 0.0], [3.711, 2.742, 0.0], [3.708, 2.736, 0.0], 
    [3.71, 2.733, 0.0], [3.71, 2.73, 0.0], [3.707, 2.724, 0.0], [3.706, 2.719, 0.0], [3.7, 2.714, 0.0], 
    [3.697, 2.706, 0.0], [3.693, 2.704, 0.0], [3.691, 2.699, 0.0], [3.688, 2.698, 0.0], [3.686, 2.695, 0.0], 
    [3.682, 2.695, 0.0], [3.68, 2.694, 0.0], [3.673, 2.688, 0.0], [3.669, 2.688, 0.0], [3.664, 2.685, 0.0], 
    [3.656, 2.685, 0.0], [3.652, 2.681, 0.0], [3.64, 2.681, 0.0], [3.637, 2.685, 0.0]
    ]

# Edges definition of the background plane
myedges_plane = [(0, 1), (1, 2), (2, 3), (3, 0)]

myedges_plane += [(idx, idx + 1) for idx in range(4, len(myvertices_plane) - 1)] + [(len(myvertices_plane) - 1, 4)]

# Create the background plane
if bpy.context.scene.objects.get(plane_nm):
    bpy.data.objects.remove(bpy.context.scene.objects.get(plane_nm))
create_custom_mesh(plane_nm, trns, rot, myvertices_plane, myedges_plane)

Hope this helps someone else!

DB

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .