Vi3W
Skip to content

Guides

Blender Python for beginners: your first scripts with bpy

Blender Python scripting for beginners: the Scripting workspace, bpy basics, first scripts for renaming and batch export, and safe AI help.

2 min read

A laptop showing code at night, with light trails flowing into a small floating blocky game world
Illustration. A few lines of Python can replace hours of clicking.

Quick answer

How do I start scripting in Blender with Python?

Open the Scripting workspace, create a new text in the Text Editor, and write Python using Blender's bpy module, for example looping over bpy.context.selected_objects to rename or move them. Run it with the play button or Alt+P. Hover over any button to see its Python path, and use the Info editor to see operators you just ran.

Where to write scripts

The Scripting workspace has a Python Console (try lines interactively), a Text Editor (write and run scripts), and an Info editor (shows the Python for actions you just did in the UI). Manual: scripting introduction.

Two tricks that teach you the API:

  • Hover tooltips show the Python path of any setting (turn on Python Tooltips in Preferences ‣ Interface).
  • Info editor: do something by hand, then copy the operator call it shows.
Video: Intro to Python Scripting in Blender - Workshop to automate tasks for artists, by TheDuckCow (YouTube)

The bpy basics

  • bpy.data: everything in the file (objects, meshes, materials).
  • bpy.context: what's active or selected right now.
  • bpy.ops: operators, the same actions as buttons and menus. They depend on context (mode, editor), which makes them fragile in scripts.

Prefer bpy.data and direct property changes where possible.

First scripts to try

Rename selected objects: loop over bpy.context.selected_objects and set obj.name = f"Prop_{i:02d}".

Apply a material to many objects: get the material from bpy.data.materials["Wood"], then for each selected mesh, append it to obj.data.materials if it's not already there.

Batch export: for each selected object, select only that one and call the glTF exporter with "selected objects only" to write one GLB per prop. A real time-saver for game assets.

Run headless: blender --background file.blend --python script.py runs a script without opening the UI, ideal for batch jobs.

Safety

Scripts can delete or overwrite data. Save first, test on a copy, and read scripts from the internet or AI before you run them. Blender's scripting security settings control auto-running scripts inside .blend files.

A laptop with code flowing into a blocky world
Illustration. Scripts arrange, rename and export at scale.

Using AI to write Blender Python

AI assistants write bpy well, especially when connected to Blender through MCP so they can run and fix their own scripts. Tips and limits: best AI for Blender Python and Blender MCP.

Scripts plus generated assets

A common pipeline: generate props, then script their import, naming, scaling and export. Vi3W generates props from a prompt, photo or sketch, retopologises them, and exports GLB, FBX or OBJ ready for your scripts to batch-process. Try Vi3W.

Last reviewed