0
$\begingroup$

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)
$\endgroup$
5
  • 1
    $\begingroup$ Boolean property works, you are "just doing it wrong". Define a property on a type, use it from an instance. eg if context.scene.save_function: $\endgroup$
    – batFINGER
    Commented Feb 4, 2020 at 15:33
  • 1
    $\begingroup$ Related blender.stackexchange.com/questions/102293/… $\endgroup$
    – batFINGER
    Commented Feb 4, 2020 at 15:39
  • $\begingroup$ I changed a part of the script, but i'm still stuck, why does: 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$ Commented Feb 5, 2020 at 8:11
  • 1
    $\begingroup$ What @batFINGER was saying is that you don't have to change the BoolProperty definition, you have to change how you call the bool value in the SaveAsRotationFix() function, and replace if bpy.types.Scene.save_function == True: with if 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 from context. docs.blender.org/api/current/bpy.props.html $\endgroup$
    – Tareyes
    Commented Feb 5, 2020 at 8:49
  • $\begingroup$ Oow I see, I get it now. Thanks, it works $\endgroup$ Commented Feb 5, 2020 at 9:03

0

You must log in to answer this question.

Browse other questions tagged .