Objects in blender are created with a universal default size. The size is relative to the active 3D view’s grid size.
Most of us Blender users are working under the default/standard grid size of 1.0. However, working with UE4, I had adapted a scene unit scaling of 0.01 on Metric. After that change, my default 3D view’s grid had visually scaled up 100 times, while the grid scale remains at 1.0.
This caused all my objects created to be sitting at a whopping 2 meters in diameter. Not ideal for anything other than Architecture/Level design. So I set the grid size to 0.1. And then, my newly created objects all has a default radius of 10cm. Which is pretty good for character/character prop creation.
Problem is, all the amazing plugins that has object creation functions does not pay regard to blender’s scene scale, nor the grid scale. Therefore the objects created from them are often too small to work with.
I am too lazy to just scale them up one by one.
Here are a few pieces of code to help with it. The idea is simple.
UPDATE:
Grid_Unit_Size = area.spaces[0].grid_scale / bpy.context.scene.unit_settings.scale_length
This is the actual correct grid unit size for objects creation. Previously I have left the scene unit scale length out, which is also a key factor to object creation size.
How you get grid scale given correct context:
bpy.context.area.spaces[0].grid_scale
# This value is actually stored here:
# bpy.data.screen[<your active screen layout>].areas[<index of area.type == "VIEW_3D">].space[0].grid_scale
If correct context isn’t guaranteed:
<i># Finding the grid scale of your first available 3D view. (Yes, you are right. Every 3D view has a separate grid_scale setting.)</i>
def getGridScale():
if bpy.context.area.type == "VIEW_3D":
area = bpy.context.area
else:
areas = [a for a in bpy.context.screen.areas if a.type == "VIEW_3D"]
if len(areas) > 0:
area = areas[0]
<i># Current screen contains multiple 3D views, use the first one available.</i>
else:
return 1
<i># Current screen contains no 3D view, therefore can not get grid size, return 1 for safety.</i>
<b>Grid_Unit_Size</b> = area.spaces[0].grid_scale / bpy.context.scene.unit_settings.scale_length
return <b>Grid_Unit_Size</b>
# It's also possible to just get a grid scale from a 3D view outside of the current screen layout,
# there is no point in doing so since there will be no visual indication of what happens.
Note: If you type “bpy.context.area.type” in blender’s console, you’ll likely never get a ‘VIEW_3D’ as answer. Because when you type in the console, the context is the console, therefore the context.area.type will always be ‘CONSOLE’.
Note 2: Sometimes it is not the object’s dimension being too small, but one specific value that affects the visual size/width/thickness of the object, and in this case, the getGridScale() needs to be injected into the code where these specific values are present.
Inject location:
<i># The <obj> below points to the object that needs its size adjusted.</i>
obj.dimensions = obj.dimensions * getGridScale()
<i># Or divide the <obj.dimensions> by <bpy.context.area.spaces[0].grid_scale></i>