my script to replaceing cubes not always working right [BLEND FILE INSIDE]

i created this script because i have a blender file that’s have alot of cubes with unneeded faces the most of them have 10 faces so i maked this script to replace this cubes with another normal cubes from add mesh menu that only have 6 faces by getting the old cube locations and dimensions and rotation then saving them to text files then delete the old cube then setting a the old cube data to the new one

the script working very good when i replace normal cube with another from add mesh menu but when i test this with the cube that have 10 faces i get a bigger cube and little different rotation and location but i have the right data in the transform menu

my code

import bpy
import re
file_data = [] # create an empty list
animation_data = {} # create an empty dictionary
thexdimensionsline = open("/home/my new blender addon/convert to lowpoly cubes/thexdimensionsline","w")
theydimensionsline = open("/home/my new blender addon/convert to lowpoly cubes/theydimensionsline","w")
thezdimensionsline = open("/home/my new blender addon/convert to lowpoly cubes/thezdimensionsline","w")
thexlocationline = open("/home/my new blender addon/convert to lowpoly cubes/thexlocationlinefil","w")
theylocationline = open("/home/my new blender addon/convert to lowpoly cubes/theylocationlinefile","w")
thezlocationline = open("/home/my new blender addon/convert to lowpoly cubes/thezlocationfile","w")
#readdddddddd
thexrotaionline = open("/home/my new blender addon/convert to lowpoly cubes/thexrotaionlinefil","w")
theyrotaionline = open("/home/my new blender addon/convert to lowpoly cubes/theyrotationlinefile","w")
thezrotaionline = open("/home/my new blender addon/convert to lowpoly cubes/thezrotationfile","w")
class DissolvePanel(bpy.types.Panel):
    bl_label = "lowpoly cube changer"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') 
    thexdimensionsline.write(str(bpy.context.object.dimensions[0])) 
    thexdimensionsline.close()
    theydimensionsline.write(str(bpy.context.object.dimensions[1])) 
    theydimensionsline.close()
    thezdimensionsline.write(str(bpy.context.object.dimensions[2])) 
    thezdimensionsline.close()
    
    thexlocationline.write(str(bpy.context.object.location[0])) 
    thexlocationline.close()
    theylocationline.write(str(bpy.context.object.location[1])) 
    theylocationline.close()
    thezlocationline.write(str(bpy.context.object.location[2])) 
    thezlocationline.close()    
    
    thexrotaionline.write(str(bpy.context.object.rotation_euler[0])) 
    thexrotaionline.close()
    theyrotaionline.write(str(bpy.context.object.rotation_euler[1])) 
    theyrotaionline.close()
    thezrotaionline.write(str(bpy.context.object.rotation_euler[2])) 
    thezrotaionline.close() 
    
    
    bpy.ops.object.delete(use_global=False)
    bpy.ops.mesh.primitive_cube_add(location=(2,0,0))
    thexdimensionsline = open("/home/my new blender addon/convert to lowpoly cubes/thexdimensionsline","r")
    theydimensionsline = open("/home/my new blender addon/convert to lowpoly cubes/theydimensionsline","r")
    thezdimensionsline = open("/home/my new blender addon/convert to lowpoly cubes/thezdimensionsline","r")
    thexlocationline = open("/home/my new blender addon/convert to lowpoly cubes/thexlocationlinefil","r")
    theylocationline = open("/home/my new blender addon/convert to lowpoly cubes/theylocationlinefile","r")
    thezlocationline = open("/home/my new blender addon/convert to lowpoly cubes/thezlocationfile","r")
    
    thexrotaionline = open("/home/my new blender addon/convert to lowpoly cubes/thexrotaionlinefil","r")
    theyrotaionline = open("/home/my new blender addon/convert to lowpoly cubes/theyrotationlinefile","r")
    thezrotaionline = open("/home/my new blender addon/convert to lowpoly cubes/thezrotationfile","r")
    
    actor_name = bpy.context.scene.objects.active.name
    thexdim = thexdimensionsline.readline()
    theydim = theydimensionsline.readline()
    thezdim = thezdimensionsline.readline()

    print(thexdim,theydim,thezdim)
    
    bpy.data.objects[actor_name].dimensions = (float(thexdim),float(theydim),float(thezdim))
    thexloco = thexlocationline.readline()
    theyloco = theylocationline.readline()
    thezloco= thezlocationline.readline()

    print(thexloco,theyloco,thezloco)
    
    bpy.data.objects[actor_name].location = (float(thexloco),float(theyloco),float(thezloco))


    thexroteto = thexrotaionline.readline()
    theyroteto = theyrotaionline.readline()
    thezroteto = thezrotaionline.readline()

    print(thexdim,theydim,thezdim)
    
    bpy.data.objects[actor_name].rotation_euler = (float(thexroteto),float(theyroteto),float(thezroteto))


    #print("afterbla",thexdim,theydim,thezdim)
    def draw(self, context):

        
        layout = self.layout
        col = layout.column(align=True)
        row = col.row(align=True)
        
        row.operator("mesh.subdivide", text = "Dissolve Verts")
        bpy.context.scene.update() 
        # invoke custom operator
        # row.operator("object.simple_operator" , text = "All")

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

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

if __name__ == "__main__":
    register()

there are two big cubes on my blend file the blue cube are the cube with ten faces and the red cube just a normal cube i added from mesh menu and created the small cubes around them are just to make you notice the dimensions for the cube that created after running the script with the cube that have 10 faces but if you runned the script with the red cube the cube replacing will work perfect and the new cube will take the right dimensions succesfullyproblemblend.zip (155 KB)