script to make a basic car model in blender

import bpy

def create_car():

  # Create the main car body

  bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 1))

  car_body = bpy.context.object

  car_body.name = “Car_Body”

  car_body.scale.x = 2 # Length

  car_body.scale.y = 1 # Width

  car_body.scale.z = 0.5 # Height

   

  # Create the roof

  bpy.ops.mesh.primitive_cube_add(size=1.5, location=(0, 0, 1.5))

  car_roof = bpy.context.object

  car_roof.name = “Car_Roof”

  car_roof.scale.x = 1.2

  car_roof.scale.y = 0.9

  car_roof.scale.z = 0.5

   

  # Create wheels

  wheel_positions = [(1, 0.8, 0.5), (-1, 0.8, 0.5), (1, -0.8, 0.5), (-1, -0.8, 0.5)]

  wheels = []

  for pos in wheel_positions:

    bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=0.2, location=pos)

    wheel = bpy.context.object

    wheel.name = f”Wheel_{len(wheels) + 1}”

    wheel.rotation_euler.x = 1.5708 # Rotate to align with the ground

    wheels.append(wheel)

   

  # Group car parts together

  bpy.ops.object.select_all(action=’DESELECT’)

  car_body.select_set(True)

  car_roof.select_set(True)

  for wheel in wheels:

    wheel.select_set(True)

  bpy.context.view_layer.objects.active = car_body

  bpy.ops.object.parent_set()

   

  print(“Car model created successfully!”)

# Run the function to create the car

create_car()

Leave a comment

Your email address will not be published. Required fields are marked *