I have this code, but the save_function doesn't seem to assign a True value. The rest of the script works without the bool, but I want to create a toggle to enable or disable part of this function. What am I doing wrong here?
import bpy
import os
from bpy.props import BoolProperty
bl_info = {
"name": "Henry Rotation fix",
"author": "Henry de Lange",
"version": (1,4,1),
"blender": (2,80,0),
"location": "3D View > Sidebar > Rotation tab",
"description": "tool to fix the rotation issue when saving blend files",
"warning": "",
"wiki_url": "",
"category":"Object"}
bpy.types.Scene.save_function = BoolProperty(
name="Enable Save Function",
description="Disables or Enables the save function",
default = True)
# fixes rotation and saves as
class MUT_OT_RotationFixSaveAs(bpy.types.Operator):
bl_description = "Fixes the rotation when saving the blend file"
bl_label = "Save As"
bl_idname = "object.save_as_rotation_fix"
bl_options = {'REGISTER','UNDO'}
def SaveAsRotationFix(self):
for obj in bpy.context.scene.objects:
obj.name = obj.name.lower()
obj.data.name = obj.name.lower()
print(bpy.types.Scene.save_function)
if bpy.types.Scene.save_function == True:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False, properties=False)
bpy.ops.transform.rotate(value = 1.5708, orient_axis='X', constraint_axis = (True, False, False), orient_type='GLOBAL')
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False, properties=False)
bpy.ops.transform.rotate(value = -1.5708, orient_axis='X', constraint_axis = (True, False, False), orient_type='GLOBAL')
else:
print("Doesn't work")
Edit:
save_function = BoolProperty(
name="Enable Save Function",
description="Disables or Enables the save function",
default = True)
if context.scene.save_function:
$\endgroup$save_function = BoolProperty( name="Enable Save Function", description="Disables or Enables the save function", default = True)
Give me a tuple? And how can I change it to give me a bool. $\endgroup$SaveAsRotationFix()
function, and replaceif bpy.types.Scene.save_function == True:
withif context.scene.save_function:
. Also, that definition you mentioned is not a bool because it is a "property" that needs multiple arguments (like default value, update function etc) and it's used also to display the checkbox in the UI. The bool is only returned if you call that property fromcontext
. docs.blender.org/api/current/bpy.props.html $\endgroup$