This post has been updated for Blender 2.5 build 26234
Some time ago I downloaded a development build of Blender 2.5 for the first time. I wanted to see for myself if it was already feasible to start writing scripts for it.
Since I didn’t find any examples of where to begin, I’m documenting my progress in this thread. Hopefully it’s of use for other people. You’re of course welcome to share your own examples. Together we can make the transition to the new api much faster.
Table of contents
Scripts (checked with build 26234)
- Hello world - a first test
- Ping pong - operators and pushbuttons
- Monkify - tools panel, poll() and predefined operators
- Armature - script without a gui, bones, transform() and angles
- Icons - custom groups for operators
- Dropdown - dropdown boxes and retrieving materials
- Subclassing RNA - add custom properties and functions to types (by ideasman42)
- Keyframes - inserting a keyframe (by taniwha)
- CrystalSpace - inheriting and unsetting properties (by sueastside)
- Export - access and export a custom property (by Borgleader)
- Measure - full script, context dependencies (by pontiac)
- Twitter - full script, connecting to the web (by deflinto)
- Gems - add mesh, integration in add-menu, eternal editable (by dreampainter)
- Files - using the file select window (by Darknet)
- Edge intersection - addon-registration, mathutils module, and more (by zeffii)
General info (checked with build 26234)
- Abbreviations - class types and layout items
- Icons - overview of all icons and their names (script 5)
- Script window - information on creating a custom script window
- Columns - information on creating a multiple column layout
- Properties, ID-Properties and their differences - lot of documentation
Outdated examples (please update)
- Gears - menu items, properties and mesh editing (by varkenvarken)
- Custom mesh - dynamic parameters, adding to add_mesh menu (by FourMadMen)
- Keymap - adding functions to the keymap (by vidar_nelson)
- Popup - creating a simple popup menu (by Loolarge)
Script example 1
class ObjectButtonsPanel(bpy.types.Panel): bl_space_type = "PROPERTIES" bl_region_type = "WINDOW" bl_context = "object" class OBJECT_PT_hello(ObjectButtonsPanel): bl_label = "My new panel" def draw(self, context): layout = self.layout ob = context.object type = ob.type.capitalize() row = layout.row() row.label(text="Hello world!", icon='WORLD_DATA') col = layout.column() row = col.row() row.label(text="The currently selected object is: "+ob.name) row = col.row() if type == 'Mesh': row.label(text="It is a mesh containing "+str(len(ob.data.verts))+" vertices.") else: row.label(text="it is a "+type+".") row = layout.row() row.alignment = 'RIGHT' row.label(text="The end") bpy.types.register(OBJECT_PT_hello)
Just copy/paste it into the text editor and run it with alt+P. Then go to the “Properties” window (used to be the buttons-window in 2.4x) and select the object panel. At the very bottom of it (just collapse the Transform, Relations, etc. panels) you’ll find our very own new panel. It’ll update realtime, based on what object is selected in the 3d-view.
And here’s a screenshot of the result.
If you got any questions about the code: just ask! There are a lot of new things and not everything might be clear.
Disclaimer: I don’t know if I’m doing things the correct way. Do not experiment in blend-files which contain important work.