Post #4805: It’s the same there

📋 Metadata

  • Author: HirasawaYui
  • Date: 2023-07-23 09:02:30
  • Type: bug_report
  • Quality Score: 5/10
  • Reply to: post_04804

🏷️ Tags

macro property-binding intermediate unsolved

  • Macro Editor
  • Property Editor
  • Python Scripting

💬 Content

It’s the same there
Ended up going to ChatGPT and he wrote this.
The values are shown, but they are not passed to the Location Rotation Scale when entered
I think you can get that much easier than this crutch.

Summary

bl_info = {
    "name": "Menu_LRS",
    "blender": (2, 80, 0),
    "category": "Object",
}

import bpy

# Flags to determine if changes were made through the addon or standard transformation tools
addon_change_translate = False
addon_change_rotate = False
addon_change_scale = False

# Functions that update the object's transformations when variables are changed
def update_translate(self, context):
    global addon_change_translate
    obj = context.object
    if obj and addon_change_translate:
        obj.location.x = self.Nloc_X
        obj.location.y = self.Nloc_Y
        obj.location.z = self.Nloc_Z

def update_rotate(self, context):
    global addon_change_rotate
    obj = context.object
    if obj and addon_change_rotate:
        obj.rotation_euler.x = self.Nrot_X
        obj.rotation_euler.y = self.Nrot_Y
        obj.rotation_euler.z = self.Nrot_Z

def update_scale(self, context):
    global addon_change_scale
    obj = context.object
    if obj and addon_change_scale:
        obj.scale.x = self.Nsca_X
        obj.scale.y = self.Nsca_Y
        obj.scale.z = self.Nsca_Z

# Functions that update the variables based on the object's transformations
def update_variables(scene):
    global addon_change_translate, addon_change_rotate, addon_change_scale
    obj = bpy.context.object
    if obj:
        if not addon_change_translate:
            scene.Nloc_X = obj.location.x
            scene.Nloc_Y = obj.location.y
            scene.Nloc_Z = obj.location.z
        if not addon_change_rotate:
            scene.Nrot_X = obj.rotation_euler.x
            scene.Nrot_Y = obj.rotation_euler.y
            scene.Nrot_Z = obj.rotation_euler.z
        if not addon_change_scale:
            scene.Nsca_X = obj.scale.x
            scene.Nsca_Y = obj.scale.y
            scene.Nsca_Z = obj.scale.z

# Custom panel definition
class OBJECT_PT_CoordinatesPanel(bpy.types.Panel):
    bl_label = "Coordinates Panel"
    bl_idname = "OBJECT_PT_coordinates_panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Menu_LRS"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        # Add input fields for transformations
        layout.prop(scene, "Nloc_X", text="Translate X")
        layout.prop(scene, "Nloc_Y", text="Translate Y")
        layout.prop(scene, "Nloc_Z", text="Translate Z")

        layout.prop(scene, "Nrot_X", text="Rotate X")
        layout.prop(scene, "Nrot_Y", text="Rotate Y")
        layout.prop(scene, "Nrot_Z", text="Rotate Z")

        layout.prop(scene, "Nsca_X", text="Scale X")
        layout.prop(scene, "Nsca_Y", text="Scale Y")
        layout.prop(scene, "Nsca_Z", text="Scale Z")

    def update_location(self, context):
        global addon_change_translate
        addon_change_translate = True
        context.scene.update()
    
    def update_rotate(self, context):
        global addon_change_rotate
        addon_change_rotate = True
        context.scene.update()
    
    def update_scale(self, context):
        global addon_change_scale
        addon_change_scale = True
        context.scene.update()

# Registering the panel and properties
def register():
    bpy.utils.register_class(OBJECT_PT_CoordinatesPanel)
    bpy.types.Scene.Nloc_X = bpy.props.FloatProperty(name="Translate X", update=update_translate, precision=3)
    bpy.types.Scene.Nloc_Y = bpy.props.FloatProperty(name="Translate Y", update=update_translate, precision=3)
    bpy.types.Scene.Nloc_Z = bpy.props.FloatProperty(name="Translate Z", update=update_translate, precision=3)

    bpy.types.Scene.Nrot_X = bpy.props.FloatProperty(name="Rotate X", update=update_rotate, precision=3, unit='ROTATION')
    bpy.types.Scene.Nrot_Y = bpy.props.FloatProperty(name="Rotate Y", update=update_rotate, precision=3, unit='ROTATION')
    bpy.types.Scene.Nrot_Z = bpy.props.FloatProperty(name="Rotate Z", update=update_rotate, precision=3, unit='ROTATION')

    bpy.types.Scene.Nsca_X = bpy.props.FloatProperty(name="Scale X", update=update_scale, precision=3)
    bpy.types.Scene.Nsca_Y = bpy.props.FloatProperty(name="Scale Y", update=update_scale, precision=3)
    bpy.types.Scene.Nsca_Z = bpy.props.FloatProperty(name="Scale Z", update=update_scale, precision=3)

    # Set initial values from the object's properties when the addon is activated
    def set_initial_values(dummy):
        obj = bpy.context.object
        if obj:
            bpy.context.scene.Nloc_X = obj.location.x
            bpy.context.scene.Nloc_Y = obj.location.y
            bpy.context.scene.Nloc_Z = obj.location.z

            bpy.context.scene.Nrot_X = obj.rotation_euler.x
            bpy.context.scene.Nrot_Y = obj.rotation_euler.y
            bpy.context.scene.Nrot_Z = obj.rotation_euler.z

            bpy.context.scene.Nsca_X = obj.scale.x
            bpy.context.scene.Nsca_Y = obj.scale.y
            bpy.context.scene.Nsca_Z = obj.scale.z

    bpy.app.handlers.depsgraph_update_post.append(set_initial_values)
    bpy.app.handlers.depsgraph_update_post.append(update_variables)

# Unregister the panel and properties
def unregister():
    bpy.utils.unregister_class(OBJECT_PT_CoordinatesPanel)
    del bpy.types.Scene.Nloc_X
    del bpy.types.Scene.Nloc_Y
    del bpy.types.Scene.Nloc_Z

    del bpy.types.Scene.Nrot_X
    del bpy.types.Scene.Nrot_Y
    del bpy.types.Scene.Nrot_Z

    del bpy.types.Scene.Nsca_X
    del bpy.types.Scene.Nsca_Y
    del bpy.types.Scene.Nsca_Z

    # Remove the handlers when the addon is disabled
    bpy.app.handlers.depsgraph_update_post.remove(set_initial_values)
    bpy.app.handlers.depsgraph_update_post.remove(update_variables)

if __name__ == "__main__":
    register()

imageimage2133×1087 200 KB


🔗 View on Blender Artists