Public API¶
PME2 provides a public API for external scripts and other addons.
Quick Start¶
import pme
# Runtime package identity (Legacy add-on or Blender Extension)
addon_id = pme.ADDON_ID
# Find a menu
pm = pme.find_pm("My Pie Menu")
pm = pme.find_pm(uid="pm_9f7c2k3h")
# Invoke a menu
pme.invoke_pm("My Pie Menu")
pme.invoke_pm(uid="pm_9f7c2k3h")
# List menus
all_menus = pme.list_pms()
pie_menus = pme.list_pms(mode="PMENU", enabled_only=True)
tags = pme.list_tags()
# Execute code
result = pme.execute("bpy.ops.mesh.primitive_cube_add()")
print(result.ok, result.error)
# Evaluate an expression
value = pme.evaluate("len(C.selected_objects)")
# Validate JSON
result = pme.validate_json(json_string)
for err in result.errors:
print(err.code, err.message)
Changes from PME1¶
Topic |
PME1 |
PME2 |
|---|---|---|
Import |
|
|
Runtime add-on ID |
Hard-coded |
|
Design |
Exposed internal module |
Public API facade |
Menu invocation |
|
|
Code execution |
|
|
Menu lookup |
None |
|
JSON validation |
None |
|
Types and constants |
None |
|
API Reference¶
Code execution¶
Function |
Description |
|---|---|
|
Execute code and return |
|
Evaluate an expression and return the result. Raises on failure |
|
Syntax-check only. Returns |
Validation¶
Function |
Description |
|---|---|
|
Validate against JSON Schema v2. Returns |
|
Validate a uid string format |
User properties¶
User properties created with the Property Editor use the same access forms in
PME commands (props()) and through import pme (pme.props()).
import pme
# Get the PropertyGroup and access a property as an attribute
pme.props().MyCounter = 10
value = pme.props().MyCounter
# Read or write by registered storage ID
value = pme.props("MyCounter")
written = pme.props("MyCounter", 10)
pme.props(name, None) remains a read operation; it does not write None.
Named access is limited to properties registered by PME. An unregistered name
returns None when read and False when written; it is not created as scratch
storage.
Code that used pme.props.MyCounter in earlier Experimental builds must use
pme.props().MyCounter instead.
Runtime add-on identity¶
Use pme.ADDON_ID when a Blender API requires the current add-on module ID.
The value follows the active package identity, including the
bl_ext.<repository>.<package> identity used by Blender Extensions.
import bpy
import pme
addon_preferences = bpy.context.preferences.addons[pme.ADDON_ID].preferences
Use pme.preferences when only the PME preferences object is needed. Do not
hard-code "pie_menu_editor" in new scripts.
Backward compatibility¶
PME1’s pme.context and the props() command global remain available.
Existing props() scripts inside PME command slots continue to work.
# These still work in PME2
pme.context.open_menu("My Menu")
pme.context.event.mouse_x
pme.context.add_global("my_var", value)
props("MyCounter", 10)
Prefer pme.execute() and pme.invoke_pm() for new code.
Note
The public API is currently Experimental. The basic interface is intended to stay stable, but smaller details may change in future versions.
See also
You must enable import pme before using this API. See Boot Options.