Skip to content

Instantly share code, notes, and snippets.

@stilobique
Last active March 15, 2022 09:41
Show Gist options
  • Save stilobique/31c30bc203deef548231323442b92115 to your computer and use it in GitHub Desktop.
Save stilobique/31c30bc203deef548231323442b92115 to your computer and use it in GitHub Desktop.
Blender Batch Placement by name correspondance
import bpy
import bmesh
import math
from mathutils import Euler
def get_rotation_from_source(ob: bpy.types.Object) -> Euler:
"""Get rotation from Cursor or Object, and set-it to the new items"""
bm = bmesh.new()
bm.from_object(ob, bpy.context.evaluated_depsgraph_get())
bm.transform(ob.matrix_world)
bm.normal_update()
get_rotation = None
for f in bm.faces:
get_rotation = f.normal.to_track_quat().to_euler()
get_rotation.rotate_axis("X", math.radians(-90.0))
get_rotation.rotate_axis("Z", math.radians(-90.0))
return get_rotation
for ob in bpy.context.selected_objects:
"""From selected objects, find a correspondance name, get a location and make a new placement."""
ref = ob.name.replace('Window', 'BlockoutW')
for slt in bpy.data.objects:
if ref in slt.name:
ob.location = slt.location
ob.rotation_euler = get_rotation_from_source(slt)
slt.hide_set(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment