0

I wrote a simple script to quickly (by hotkey) change Object Origin transformation options, but I want a good indication that this is enabled or disabled, and the most better way is to add a checkbox to a 3DView header, near with Options dropdown - see the fake shot. Spend a lot of time how to add it to it, but no luck! ((

enter image description here

#todo: Make it as a checkbox in Header

bl_info = { "name": "PivotToggle", "author": "MikeMS", "version": (1,0), "blender": (2,93,0), "category": "Object", "location": "Add to QuickFavorites from Search Operator or to a Hotkey for object.pivottoggle", "description": "Toggle Affect Only Origins and Parent for Object transformations.", }

import bpy

class PivotToggle(bpy.types.Operator): """Toggle Affect Only Origins and Parent for Object transformations.""" bl_idname = "object.pivottoggle" bl_label = "PivotToggle"

def execute(self, context):

    #Script start: 

    if bpy.context.scene.tool_settings.use_transform_data_origin == False and bpy.context.scene.tool_settings.use_transform_skip_children == False:
        bpy.context.scene.tool_settings.use_transform_data_origin = True
        bpy.context.scene.tool_settings.use_transform_skip_children = True
        self.report({'INFO'}, "Pivot Transformation Enabled")
    else:
        bpy.context.scene.tool_settings.use_transform_data_origin = False
        bpy.context.scene.tool_settings.use_transform_skip_children = False
        self.report({'INFO'}, "Pivot Transformation Disabled")


    #Script end.

    return {'FINISHED'}


def register(): bpy.utils.register_class(PivotToggle)

def unregister(): bpy.utils.unregister_class(PivotToggle)

if name == "main": register()

Thanks for a help!

MikeMS
  • 3
  • 2

1 Answers1

0
bl_info = {
    "name": "PivotToggle",
    "author": "MikeMS",
    "version": (1,0),
    "blender": (2,93,0),
    "category": "Object",
    "location": "Add to QuickFavorites from Search Operator or to a Hotkey for object.pivottoggle",
    "description": "Toggle Affect Only Origins and Parent for Object transformations.",
}

import bpy

class OBJECT_OT_pivot_toggle(bpy.types.Operator):
    """Toggle Affect Only Origins and Parent for Object transformations."""
    bl_idname = "object.pivot_toggle"
    bl_label = "PivotToggle"

def execute(self, context): 
    if bpy.context.scene.tool_settings.use_transform_data_origin == False and bpy.context.scene.tool_settings.use_transform_skip_children == False:
       bpy.context.scene.tool_settings.use_transform_data_origin = True
       bpy.context.scene.tool_settings.use_transform_skip_children = True
       self.report({'INFO'}, "Pivot Transformation Enabled")
    else:
       bpy.context.scene.tool_settings.use_transform_data_origin = False
       bpy.context.scene.tool_settings.use_transform_skip_children = False
       self.report({'INFO'}, "Pivot Transformation Disabled")

    return {'FINISHED'}

def origin(self, context):
    layout = self.layout
    mode_string = context.mode
    tool_settings = context.tool_settings
    if mode_string == 'OBJECT':
        row = layout.row(align=True)
        row.prop(tool_settings, "use_transform_data_origin", text="Origins")

def register():
    bpy.utils.register_class(OBJECT_OT_pivot_toggle)
    bpy.types.VIEW3D_HT_header.append(origin)

def unregister():
    bpy.utils.unregister_class(OBJECT_OT_pivot_toggle)
    bpy.types.VIEW3D_HT_header.remove(origin)

if __name__ == "__main__":
    register()
Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
Karan
  • 1,984
  • 5
  • 21
  • I think you want to remove _tool from your append and remove routines, as the OP wants the question in the view header. I hope you don't mind that I did that. – Marty Fouts Oct 22 '21 at 15:35
  • Oh, thank you very much!!! It works!) – MikeMS Oct 22 '21 at 15:45
  • Hmm, strange, by checking this checkbox enables only origins (not both origins and parents options), I need to understand it better how it works...)) P.S.: Oh, yep, I understand why it's that)... Thanks) – MikeMS Oct 22 '21 at 15:50
  • @MikeMS don't leave us hanging. What did you have to change to get it to work? – Marty Fouts Oct 22 '21 at 16:36
  • 1
    @marty-fouts It's all fine. But I returned return {'FINISHED'} because without it hotkey starts to throw an error about incorrect return value and stops working. – MikeMS Oct 22 '21 at 16:45
  • doh. I missed that that had gone missing when I made my small change. Fixed. – Marty Fouts Oct 22 '21 at 16:47