Skip to content

Instantly share code, notes, and snippets.

@enzyme69
Created March 25, 2013 06:10
Show Gist options
  • Save enzyme69/5235201 to your computer and use it in GitHub Desktop.
Save enzyme69/5235201 to your computer and use it in GitHub Desktop.
Simple script to arrange selected objects into 2D grid with specified width and height
import bpy
'''
Arrange selected objects in specified grid space
'''
def arrangeIn2DGrid(width=10, height=10, spread=2):
# Get List of Selected Objects
myObjects = bpy.context.selected_objects
if(myObjects):
print('Please select some objects')
totalGrid = width * height
if(len(myObjects) > totalGrid):
print('You need to specify bigger grid for your objects')
coords = []
for x in range(0,width):
for z in range(0,height):
coords.append([x,z])
# For every object in list, place each one in order into provided coordinates
for number, object in enumerate(myObjects):
object.location = coords[number][0] * spread, coords[number][1] * spread , 0.0
arrangeIn2DGrid(spread = 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment