Skip to content

Instantly share code, notes, and snippets.

@GREEB
Created April 24, 2024 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GREEB/e34fc1a23324c4f94ae1b763bab37575 to your computer and use it in GitHub Desktop.
Save GREEB/e34fc1a23324c4f94ae1b763bab37575 to your computer and use it in GitHub Desktop.
import and space in grid blender, good for kenny assets
import bpy
import os
from mathutils import Vector
# Directory containing your GLB files
directory = r"C:\Users\crazyUser\models\gltf"
# List all files in the directory
files = os.listdir(directory)
# Define grid parameters
grid_spacing_x = 1
grid_spacing_y = 1
grid_rows = 10
# Initialize offset for parent objects
parent_offset = Vector((0, 0, 0))
# Import GLB files and offset each imported object
for i, file in enumerate(files):
if file.endswith(".glb"):
filepath = os.path.join(directory, file)
bpy.ops.import_scene.gltf(filepath=filepath)
# Offset the parent objects
parent_objects = [obj for obj in bpy.context.selected_objects if obj.parent is None]
for obj in parent_objects:
obj.location.x = parent_offset.x + (i % grid_rows) * grid_spacing_x
obj.location.y = parent_offset.y + (i // grid_rows) * grid_spacing_y
obj.location.z = parent_offset.z
# Increment the offset for the next parent object
parent_offset.x += grid_spacing_x
if (i + 1) % grid_rows == 0:
parent_offset.x = 0
parent_offset.y += grid_spacing_y
@GREEB
Copy link
Author

GREEB commented Apr 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment