Hi
I am new to scripting with blender and I am starting to understand how the UI stuff works but I still have some problems with the blender API. I managed to write a custom Pie menu with the ability to interactivly change values of sliders that affect objects in the scene. I am now trying to transfer this script from a single file to multi-files. Thats how the pie menu looks right now, the functionality doesn’t make a lot of sence but it was just to try.
The sliders for the singlefile script work basically that way:
# update function which is called when a parameter changes
def update_func(self, context):
scn = bpy.context.scene
context.active_object.location.x = scn.transformX
context.active_object.location.y = scn.transformY
context.active_object.location.z = scn.transformZ
print("Prop1 changed to", bpy.context.scene.transformX)
return None
###########################
# Pie menu Layout
##########################
class MP_PIE(Menu):
# label is displayed at the center of the pie menu.
bl_label = "Select Mode"
bl_idname = "mp.mp_pie_menu"
scn = bpy.context.scene
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
row = box.row()
#row.prop(obj, "hide_select")
#row.prop(obj, "hide_render")
box.prop(self.scn, "transformX", slider=True)
box.prop(self.scn, "transformY", slider=True)
box.prop(self.scn, "transformZ", slider=True)
##############################################
# register function where I create the variables stored into the scene
##############################################
def register():
bpy.utils.register_class(MP_PIE)
bpy.types.Scene.transformX = FloatProperty(name = "X", default = 50, min = -1000, max = 1000, subtype = 'DISTANCE', update = update_func)
bpy.types.Scene.transformY = FloatProperty(name = "Y", default = 50, min = -1000, max = 1000, subtype = 'DISTANCE', update = update_func)
bpy.types.Scene.transformZ = FloatProperty(name = "Z", default = 50, min = -1000, max = 1000, subtype = 'DISTANCE', update = update_func)
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name = "Window",space_type='EMPTY', region_type='WINDOW')
kmi = km.keymap_items.new("wm.call_menu_pie", "E", "PRESS").properties.name = "mp.mp_pie_menu"
This is maybe not the most beautiful way to do it but at least it works that way. While trying to get this script running in a multi-file addon I get the problem that I don’t know where to define this code.
bpy.types.Scene.transformZ = FloatProperty(name = "Z", default = 50, min = -1000, max = 1000, subtype = 'DISTANCE', update = update_func)
I am using the code autocomplete addon https://cgcookiemarkets.com/all-products/code-autocomplete/ which handles the registration and unregistration of modules at it’s own. Therefore I can’t really but this code into the register. I tried to make a function that stores the Parameteres into the scene, but than I have the propblem where to call this function. Looking in the internet and in other addons I often found something like this but I don’t understand what it is for, is this maybe the way to go? I would really apprichiate your help as I am stuck right now
<b>class</b> <b>MyPropertyGroup</b>(bpy.types.PropertyGroup):
If it helps: that’s the multi-file code of the file mp_pie_shader which also works, except the Smooth Angle Slider
import bpy
from bpy.props import *
from bpy.types import Menu
def SmoothUpdate_func(self,context):
scn = bpy.context.scene
for ob in context.selected_objects:
if ob.type == 'MESH':
ob.autos_smooth_angle = scn.float_autosmoothAngle
return None
def initSceneProperties(scn):
bpy.types.Scene.Smooth_angle = FloatProperty(
name = "setSmoothAngle",
description = "Enter a float",
default = 45,
min = 0,
max = 360,
update = SmoothUpdate_func)
class MP_Pie_Shader(Menu):
# label is displayed at the center of the pie menu.
bl_label = "Select Mode"
bl_idname = "mp.mp_pie_shader"
scn = bpy.context.scene
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
pie.operator("viewportshade.change", text="Rendered", icon = 'SMOOTH').mode = "rendered"
pie.operator("viewportshade.change", text="Wireframe", icon = 'WIRE').mode = "wireframe"
box = pie.box().column()
box.operator("object.shade_smooth", text="Smooth Shade")
box.operator("object.shade_flat", text="Flat Shade")
box.prop(self.scn, "setSmoothAngle", text = "Smooth Angle", slider = True)
pie.operator("viewportshade.change", text="Material", icon = 'MATERIAL').mode = "material"
pie.operator("viewportshade.change", text="Textured", icon = 'TEXTURE_SHADED').mode = "textured"
pie.operator("viewportshade.change", text="Solid", icon = 'SOLID').mode = "solid"
class Autosmooth_Button(bpy.types.Operator):
bl_idname = "viewport.autosmooth"
bl_label = "Autosmooth"
def execute(self, context):
bpy.context.object.data.use_auto_smooth = True
#
# class OBJECT_OT_AddButton(bpy.types.Operator):
#
class ChangeViewportShade_Button(bpy.types.Operator):
bl_idname = "viewportshade.change"
bl_label = "Add"
mode = bpy.props.StringProperty()
def execute(self, context):
if self.mode == "rendered":
bpy.context.space_data.viewport_shade = 'RENDERED'
elif self.mode == "wireframe":
bpy.context.space_data.viewport_shade = 'WIREFRAME'
elif self.mode == "material":
bpy.context.space_data.viewport_shade = 'MATERIAL'
elif self.mode == "textured":
bpy.context.space_data.viewport_shade = 'TEXTURED'
elif self.mode == "solid":
bpy.context.space_data.viewport_shade = 'SOLID'
return{'FINISHED'}
So please help me. How to make the Slider work for the multi-file Pie menu!?