Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Best way is to steal somebody else's model and improve it to your taste. That is the main use of Blender in 3D-printing, because parametric modelling is not the best property in Blender. Although it is almost feasible to define OpenSCAD model and ask AI to redefine in blender-python.

Hey ChatGPT, how you define an empty box in Blender Python?

  import bpy 
  empty = bpy.data.objects.new("Empty_Box", None)
  empty.empty_display_type = 'CUBE'
  empty.empty_display_size = 1.0
  bpy.context.collection.objects.link(empty)


It seems to be "empty" in name only. Lets try again.

ChatGPT: The OpenSCAD statement difference(){ cube(11); cube(10); } creates a shape by subtracting a smaller cube (10x10x10) from a larger cube (11x11x11). Here's how you can create the same effect in Blender using its Python API:

  import bpy 
  import bmesh

  # Create the larger cube 
  bpy.ops.mesh.primitive_cube_add(size=11, location=(0, 0, 0))
  cube1 = bpy.context.object

  # Create the smaller cube
  bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 0))
  cube2 = bpy.context.object

  # Add a Boolean modifier to subtract the smaller cube from the larger cube
  mod_bool = cube1.modifiers.new(name="Boolean", type='BOOLEAN')
  mod_bool.operation = 'DIFFERENCE'
  mod_bool.object = cube2

  # Apply the Boolean modifier
  bpy.context.view_layer.objects.active = cube1
  bpy.ops.object.modifier_apply(modifier=mod_bool.name)

  # Remove the smaller cube from the scene
  bpy.data.objects.remove(cube2)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: