Question on copying children objects to other parents

Hi all !

I’m facing a problem i cannot solve :
here’s the pic:

I have multiple projectors ( more than 230 ) in a scene.

On one of them ( Spot A ) , i added a child object.

Now i want to duplicate this child object so that it’s parented to SpotB and a the same relative position as in spotA ( the C over the green arrow ).

Possibly do this all at a time for the 230 spots ? :wink:

I wish this can be done. Even 1 by one; at least i won’t have to reparent/reposition 230 children :confused:

Thanks in advance for all your help :slight_smile:

Happy blending !

For an automatic option you would need to code a script in python. If you have already coded before then learning how to do it should take you much less time then doing everything manualy.

If you don’t like the option above (which is understandable) then there is “copy attributes” addon build in blender already. You just need to enable it in the preferences. With this addon, when you press ctr+C you can copy location or rotation from one object to the other. It’s still laborious but after like 30th object your fingers will get used to it XD

Maybe someone already wrote an addon that would allow you to do it automaticly, you would need to look for it somehow.

Thanks @jerzygorskiart for the copy attributes addon :slight_smile:
maybe this one associated to the commandrecorder one will help a lot :wink:

The coding option is quite complex to me because aof my lack of knowledge in the blender API and in the way to run code in blender…

I be back here if i found no solution :wink:

happy blending !

Hi :slight_smile:

Back there after 4 days struggling on this…
The copy attribute is useless for what i want to do :confused:

and i found nothing written by someone that do what i need.

therefore i wrote my very own script.
I confess it was a pain and numerous googling for each python function… :confused:

here it is:

import bpy # Never forget to import bpy


# petit script permettant de fabriquer des petits rectanglmes devant les
# spots de blender afin de les integrer dans unity.
# avant de lancer ce script il faut selectionner tous les spots et avoir
# un object nommé 'Projecteur' a la bonne taille dans la scène.
#
# le script clone le projecteur devant chaque spot et rotate le spot
# pour que le rectangle soit vertical.
#
# Blender 2.79.6 - 13-07-2020



def almost_eq(a,b):
	if(abs(b-a) < 0.0001):
		return True;
	else:
		return False;
	
def to_radians(a):
   return(a*3.141592653589793/180.0); # where's PI in this language ? XD



# We get the list of selected objects
selected_objects = bpy.context.selected_objects;

# and we unselect all of them.
bpy.ops.object.select_all(action='DESELECT')

# Let's grab the 'Projector' object for duplicating it
original = bpy.data.objects.get("Projecteur");

# Sweeping the selected objects list....
for i in range(0,len(selected_objects)):
	clone = original.copy(); # on le duplique
	bpy.data.scenes[0].objects.link(clone);
	
	# Let's parent the cloned projector to the spot light
	projo_parent = selected_objects[i];
	clone.parent = projo_parent;
	
	# Next, we rotate the spot around its normal Z axis
	# until the Y component of rotation is almost 0 ( or 180 )
	print(projo_parent.rotation_euler);
	while(almost_eq(projo_parent.rotation_euler[1],to_radians(180.0))==False and
	      almost_eq(projo_parent.rotation_euler[1],to_radians(0.0))==False):
		projo_parent.rotation_euler.rotate_axis("Z",projo_parent.rotation_euler[1]/100.0);
    
	# next we unparent the projector
	# select it:
	bpy.data.objects[clone.name].select=True;
	bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM'); # clear parent
	bpy.ops.object.select_all(action='DESELECT'); # unselect it....
	
# finally we gonna select all newly created Projectors and join the all in a unique Object
# 1st we unselect everything.
bpy.ops.object.select_all(action='DESELECT')

# and sweep the whole scene searching for 'Projectors"
for objet in bpy.context.scene.objects:
    if objet.name.startswith("Projecteur"):
        objet.select=True;

# Next we wanna make the Original Projector Active
bpy.context.scene.objects.active = original;

# and finally run a 'join' operation
bpy.ops.object.join();

# that's all :)

hope it can help someone :slight_smile:
( or at least me in some time when i need and have forgotten everything :rofl: )

happy blending !

1 Like