Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

write me blender script for creating a simple car.

  1. User

    write me blender script for creating a simple car.

  2. Assistant

    Blender uses Python scripting for automation and creating add-ons. Here is a simple script that creates a basic car model in Blender:

    import bpy
    import math
    
    # Clear existing mesh objects
    bpy.ops.object.select_all(action='DESELECT')
    bpy.ops.object.select_by_type(type='MESH')
    bpy.ops.object.delete()
    
    # Create car body
    bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, align='WORLD', location=(0, 0, 1), scale=(1, 1, 1))
    bpy.ops.transform.resize(value=(2, 1, 0.5))
    car_body = bpy.context.object
    car_body.name = "Car_Body"
    
    # Create wheels
    wheel_radius = 0.5
    wheel_width = 0.3
    wheel_positions = [(-1.5, 1, 0), (-1.5, -1, 0), (1.5, 1, 0), (1.5, -1, 0)]
    wheels = []
    
    for position in wheel_positions:
        bpy.ops.mesh.primitive_cylinder_add(radius=wheel_radius, depth=wheel_width, enter_editmode=False, align='WORLD', location=position, rotation=(math.pi/2, 0, 0), scale=(1, 1, 1))
        wheel = bpy.context.object
        wheel.name = f"Wheel_{len(wheels) + 1}"
        wheels.append(wheel)
    
    # Group car body and wheels
    bpy.ops.object.select_all(action='DESELECT')
    car_body.select_set(True)
    
    for wheel in wheels:
        wheel.select_set(True)
    
    bpy.context.view_layer.objects.active = car_body
    bpy.ops.object.join()
    
    # Name the car object
    car_object = bpy.context.object
    car_object.name = "Car"
    

    This script creates a simple car model consisting of a box (car body) and four wheels (cylinders). You can run this script in Blender's text editor or paste it into a new text file and save it with a .py extension. Then, in Blender, you can run the script by selecting Scripting > Run Script.

    You can also adjust the script to your preferences, such as changing the size, location, and scale of the car body and wheels according to your requirements.