Skip to content

Instantly share code, notes, and snippets.

@aobond2
Created January 24, 2023 10:48
Show Gist options
  • Save aobond2/4f949a772cf0a3eebed7bb528b81da38 to your computer and use it in GitHub Desktop.
Save aobond2/4f949a772cf0a3eebed7bb528b81da38 to your computer and use it in GitHub Desktop.
def repositionChildrenToPivot():
coll = bpy.context.collection
# Iterate on all object, separate into list of objects, pivot, shadow catcher
objectList = []
pivot = None
shadowCatcher = None
for c in coll.all_objects:
if ("Pivot" in c.name):
pivot = c
continue
if ("ShadowCatcher" in c.name):
shadowCatcher = c
continue
else:
objectList.append(c)
pLoc = pivot.location
# Set location of children object to pivot location
for o in objectList:
o.location = pLoc
# Select child then parent object
bpy.ops.object.select_all(action='DESELECT')
o.select_set(True)
pivot.select_set(True)
bpy.context.view_layer.objects.active = pivot
bpy.ops.object.parent_set(type='OBJECT')
#print(pivot.location)
#print(shadowCatcher)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment