This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/release/scripts/templates_py/manipulator_simple.py
Campbell Barton 28b2f1c305 Manipulator: Python API
Initial support for Python/Manipulator integration
from 'custom-manipulators' branch.

Supports:

- Registering custom manipulators & manipulator-groups.
- Modifying RNA properties, custom values via get/set callbacks,
  or invoking an operator.
- Drawing shape presets for Python defined manipulators (arrow, circle, face-maps)

Limitations:

- Only float properties supported.
- Drawing only supported via shape presets.
  (we'll likely want a way to define custom geometry or draw directly).
- When to refresh, recalculate manipulators will likely need
  integration with notifier system.

Development will be continued in the 2.8 branch
2017-06-26 16:38:04 +10:00

43 lines
1.2 KiB
Python

# Example of a group that edits a single property
# using the predefined manipulator arrow.
#
# Usage: Select a lamp in the 3D view and drag the arrow at it's rear
# to change it's energy value.
#
import bpy
from bpy.types import (
ManipulatorGroup,
)
class MyLampWidgetGroup(ManipulatorGroup):
bl_idname = "OBJECT_WGT_lamp_test"
bl_label = "Test Lamp Widget"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'3D', 'PERSISTENT'}
@classmethod
def poll(cls, context):
ob = context.object
return (ob and ob.type == 'LAMP')
def setup(self, context):
# Arrow manipulator has one 'offset' property we can assign to the lamp energy.
ob = context.object
mpr = self.manipulators.new("MANIPULATOR_WT_arrow_3d")
mpr.target_set_prop("offset", ob.data, "energy")
mpr.matrix_basis = ob.matrix_world.normalized()
mpr.draw_style = 'BOX'
mpr.color = 1, 0.5, 0, 0.5
mpr.color_highlight = 1, 0.5, 1, 0.5
self.energy_widget = mpr
def refresh(self, context):
ob = context.object
mpr = self.energy_widget
mpr.matrix_basis = ob.matrix_world.normalized()
bpy.utils.register_class(MyLampWidgetGroup)