# Python code, copy dimension from one object to another

I require some help please. I select one object (A), then shift to select another (B). Then I require some python code to copy the X dimension from (A) to (B). The X dimensions for both objects are the same after the script is run.

Swap A and B

For the most part, blender works the other way. The last selected object is the active object,aka the context.object or context.active_object used by operators. An attribute of the context object can be assinged to all the other selected objects, in the list context.selected_objects

Hence select B [C, D, E, F...] then A, A has context. The x dimension of A is set as the X dimension of B and other non active selected objects. (and lazily A too not that it matters in this case as it is same)

import bpy
context = bpy.context
x = context.object.dimensions.x
for o in context.selected_objects:
o.dimensions.x = x


Note: if an objects data has a zero dimension, for instance default plane in Z. there is no way of scaling to make its z dimension non zero.

• How would you change this to get all x,y,z dimensions to be the same length? – Michael Teiniker Aug 25 '19 at 1:49
• ob.dimensions = (x,) * 3 – batFINGER Aug 25 '19 at 15:41