UI: Presets for scene units
This adds simple preset menu for unit scale scene property. D1799 by @alm
This commit is contained in:
parent
9dc5e1dbc2
commit
7f3da8f5c9
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.scale_length = 0.01
|
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'IMPERIAL'
|
||||
scene.unit_settings.scale_length = 0.3048
|
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'IMPERIAL'
|
||||
scene.unit_settings.scale_length = 0.0254
|
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.scale_length = 1000.0
|
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.scale_length = 1.0
|
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'IMPERIAL'
|
||||
scene.unit_settings.scale_length = 1609.344
|
|
@ -0,0 +1,5 @@
|
|||
import bpy
|
||||
scene = bpy.context.scene
|
||||
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.scale_length = 0.001
|
|
@ -662,3 +662,21 @@ class WM_MT_operator_presets(Menu):
|
|||
return AddPresetOperator.operator_path(self.operator)
|
||||
|
||||
preset_operator = "script.execute_preset"
|
||||
|
||||
|
||||
class AddPresetUnitsLength(AddPresetBase, Operator):
|
||||
"""Add or remove length units preset"""
|
||||
bl_idname = "scene.units_length_preset_add"
|
||||
bl_label = "Add Length Units Preset"
|
||||
preset_menu = "SCENE_MT_units_length_presets"
|
||||
|
||||
preset_defines = [
|
||||
"scene = bpy.context.scene"
|
||||
]
|
||||
|
||||
preset_values = [
|
||||
"scene.unit_settings.system",
|
||||
"scene.unit_settings.scale_length",
|
||||
]
|
||||
|
||||
preset_subdir = "units_length"
|
||||
|
|
|
@ -18,7 +18,12 @@
|
|||
|
||||
# <pep8 compliant>
|
||||
import bpy
|
||||
from bpy.types import Panel, UIList
|
||||
from bpy.types import (
|
||||
Menu,
|
||||
Panel,
|
||||
UIList,
|
||||
)
|
||||
|
||||
from rna_prop_ui import PropertyPanel
|
||||
|
||||
from bl_ui.properties_physics_common import (
|
||||
|
@ -27,6 +32,14 @@ from bl_ui.properties_physics_common import (
|
|||
)
|
||||
|
||||
|
||||
class SCENE_MT_units_length_presets(Menu):
|
||||
"""Sets the unit of measure for properties that use length values"""
|
||||
bl_label = "Unit Presets"
|
||||
preset_subdir = "units_length"
|
||||
preset_operator = "script.execute_preset"
|
||||
draw = Menu.draw_preset
|
||||
|
||||
|
||||
class SCENE_UL_keying_set_paths(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
# assert(isinstance(item, bpy.types.KeyingSetPath)
|
||||
|
@ -75,14 +88,28 @@ class SCENE_PT_unit(SceneButtonsPanel, Panel):
|
|||
|
||||
unit = context.scene.unit_settings
|
||||
|
||||
col = layout.column()
|
||||
col.row().prop(unit, "system", expand=True)
|
||||
col.row().prop(unit, "system_rotation", expand=True)
|
||||
row = layout.row(align=True)
|
||||
row.menu("SCENE_MT_units_length_presets", text=SCENE_MT_units_length_presets.bl_label)
|
||||
row.operator("scene.units_length_preset_add", text="", icon='ZOOMIN')
|
||||
row.operator("scene.units_length_preset_add", text="", icon='ZOOMOUT').remove_active = True
|
||||
|
||||
if unit.system != 'NONE':
|
||||
row = layout.row()
|
||||
row.prop(unit, "scale_length", text="Scale")
|
||||
row.prop(unit, "use_separate")
|
||||
layout.separator()
|
||||
|
||||
split = layout.split(percentage=0.35)
|
||||
split.label("Length:")
|
||||
split.prop(unit, "system", text="")
|
||||
split = layout.split(percentage=0.35)
|
||||
split.label("Angle:")
|
||||
split.prop(unit, "system_rotation", text="")
|
||||
|
||||
col = layout.column()
|
||||
col.enabled = unit.system != 'NONE'
|
||||
split = col.split(percentage=0.35)
|
||||
split.label("Unit Scale:")
|
||||
split.prop(unit, "scale_length", text="")
|
||||
split = col.split(percentage=0.35)
|
||||
split.row()
|
||||
split.prop(unit, "use_separate")
|
||||
|
||||
|
||||
class SceneKeyingSetsPanel:
|
||||
|
|
Loading…
Reference in New Issue