blender python addon
via PatrickJS/awesome-cursorrules
Structure, register, and safely script Blender Python add-ons with operators, panels, and properties.
What is blender python addon?
Rules for building well-structured Blender Python add-ons, covering operator and panel registration, property management, API safety, and cleanup. Use this when developing add-ons that extend Blender's functionality with custom tools, UI panels, or scene automation.
- Define operators, panels, and property groups with explicit bl_idname, bl_label, and registration in __init__.py
- Validate context in poll() and use invoke()/execute() patterns for interactive and non-interactive operations
- Store settings in PropertyGroup and AddonPreferences instead of global state
- Batch mesh edits with bmesh and use dependency graph for reading final scene state
- Clean up classes, handlers, timers, and keymaps during unregister() to prevent memory leaks
- Test add-on import, registration, core operators, and unregister in clean profiles and representative scenes
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
Blender Python Add-on Rules
Add-on Structure
- Keep add-on entry points in
__init__.pywith clearregister()andunregister()functions. - Group operators, panels, properties, preferences, and utilities into separate modules for non-trivial add-ons.
- Use
bl_infoorblender_manifest.tomlaccording to the Blender version and packaging target. - Keep UI labels concise and user-facing text translatable where appropriate.
API Usage
- Use
bpy.types.Operatorfor actions,bpy.types.Panelfor UI, andbpy.types.PropertyGroupfor grouped settings. - Define
bl_idname,bl_label, andbl_optionsexplicitly. - Validate context in
poll()before enabling operators. - Use
invoke()for interactive setup andexecute()for the actual operation. - Return
{'FINISHED'}or{'CANCELLED'}consistently. - Use dependency graph updates and evaluated objects when reading final scene state.
Data and Properties
- Register custom properties through
PropertyGroupclasses instead of loose global state. - Store add-on preferences in
AddonPreferences. - Use
PointerProperty,CollectionProperty, and typed properties with names and descriptions. - Clean up custom properties and handlers during
unregister().
Safety and Performance
- Do not run destructive scene operations without explicit user action.
- Avoid blocking UI work in modal operators; use timers or modal state machines for long operations.
- Batch mesh changes and use
bmeshwhen editing mesh data programmatically. - Avoid repeatedly scanning large scenes in draw methods.
- Keep file paths configurable and use Blender path utilities.
Testing and Debugging
- Test scripts in a clean Blender profile and a representative production scene.
- Add smoke tests that import the add-on, register it, run core operators, and unregister cleanly.
- Log actionable messages with
self.report()for user-facing operator feedback. - Keep version-specific API differences isolated behind helper functions.
Common Mistakes
- Do not forget to unregister classes, handlers, timers, and keymaps.
- Do not mutate Blender data from panel
draw()methods. - Do not assume an active object, selected object, or mode without checking context.
- Do not hardcode absolute asset paths.
Related rules
Expert guidance for Chrome Extension development with TypeScript, modern JavaScript, and Web APIs.
Guidelines for writing clean, maintainable, and human-readable code.
Set up email-to-Telegram forwarding via Cloudflare Email Routing and Workers using mail2tg CLI.
Full-stack SaaS on Cloudflare Workers with Hono APIs, Angular frontends, and enterprise integrations.
Code development guidelines for precise, efficient AI-assisted changes without unnecessary commentary.
Guidelines for writing clean, interview-ready code during pair programming sessions.
