Public API¶
PME2 provides a public API for external scripts and other addons.
Quick Start¶
import pme
# 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 |
|
|
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 |
Backward compatibility¶
PME1’s pme.context and pme.props remain available.
Existing 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)
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.