`import bpy

class DimensionToolsPanel(bpy.types.Panel): """Creates a panel with two buttons to remember and apply object dimensions""" bl_label = "Retransform Tool" bl_idname = "OBJECT_PT_retransform_tools" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object"

def draw(self, context):
    layout = self.layout
    obj = context.active_object
    
    row = layout.row()
    row.label(text="Selected Object: " + obj.name)
    
    row = layout.row()
    row.operator("object.remember_dimensions", text="RETRANSFORM", icon='FILE_REFRESH')

class RememberDimensionsOperator(bpy.types.Operator): """Stores the object's dimensions""" bl_idname = "object.remember_dimensions" bl_label = "RETRANSFORM"

def execute(self, context):
    obj = context.active_object
    obj["remember_dimensions"] = obj.dimensions.copy()
    obj.dimensions = (10,10,10)
    bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
    obj.dimensions = obj["remember_dimensions"]
    self.report({'INFO'}, "RETRANSFORMED object: " + obj.name)
    return {'FINISHED'}

def register(): bpy.utils.register_class(DimensionToolsPanel) bpy.utils.register_class(RememberDimensionsOperator)

def unregister(): bpy.utils.unregister_class(DimensionToolsPanel) bpy.utils.unregister_class(RememberDimensionsOperator)

if name == "main": register()`

This script creates a custom panel in Blender's properties window called "Retransform Tool", which contains a button labeled "RETRANSFORM". When the button is pressed, it applies the following actions to the currently selected object:

  1. Store the object's current dimensions in a custom property called "remember_dimensions"
  2. Scale the object to the dimensions (10,10,10)
  3. Apply the transformation to the object's data
  4. Scale the object back to the dimensions stored in "remember_dimensions"
  5. Report a message in the info bar that the object has been "RETRANSFORMED" The script also includes functions to register and unregister the panel and operator classes.

Can you change it so that it will perform the action for all mesh objects in the scene?

Sure, here's one way you could modify the script to apply the action to all mesh objects in the scene:

import bpy

class DimensionToolsPanel(bpy.types.Panel):
    """Creates a panel with two buttons to remember and apply object dimensions"""
    bl_label = "Retransform Tool"
    bl_idname = "OBJECT_PT_retransform_tools"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        obj = context.active_object
        
        row = layout.row()
        row.label(text="Selected Object: " + obj.name)
        
        row = layout.row()
        row.operator("object.remember_dimensions", text="Retransform All Meshes", icon='FILE_REFRESH')
        
class RememberDimensionsOperator(bpy.types.Operator):
    """Stores the object's dimensions"""
    bl_idname = "object.remember_dimensions"
    bl_label = "Retransform All Meshes"

    def execute(self, context):
        for obj in bpy.data.objects:
            if obj.type == 'MESH':
                obj["remember_dimensions"] = obj.dimensions.copy()
                obj.dimensions = (10,10,10)
                bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
                obj.dimensions = obj["remember_dimensions"]
                
        self.report({'INFO'}, "Retransformed all meshes in the scene")
        return {'FINISHED'}
    
def register():
    bpy.utils.register_class(DimensionToolsPanel)
    bpy.utils.register_class(RememberDimensionsOperator)

def unregister():
    bpy.utils.unregister_class(DimensionToolsPanel)
    bpy.utils.unregister_class(RememberDimensionsOperator)

if __name__ == "__main__":
    register()

This script will loop through all the objects in the scene and check their type, if it is mesh then it will perform the action of storing the object's current dimensions in a custom property called "remember_dimensions", and then scaling the object to the dimensions (10,10,10), applying the transformation, and then scaling the object back to the dimensions stored in "remember_dimensions". Finally, it will show the message of "Retransformed all meshes in the sceneā€