0

I want to create an empty for every object selected (with its coordinates) and parent each object to the empty. I found this solution

How to create an empty per object in selection?

In that link they share this code where it says "If you want the empties to be the parents :"

import bpy

for obj in bpy.context.selected_objects: # Loop over all selected objects empty = bpy.data.objects.new(obj.name + "_Empty", None) # Create new empty object obj.users_collection[0].objects.link(empty) # Link empty to the current object's collection empty.empty_display_type = 'PLAIN_AXES' empty.location = obj.location obj.parent = empty obj.location = (0, 0, 0)

But the nulls appear in the world's origin not in the objects' origin.

enter image description here

Any idea to get it?

Thanks

Víctor GV
  • 187
  • 9
  • 1
    What is the meaning of this sentence: "But the nulls appear in the world origin not in the object origin." – lemon Nov 21 '23 at 10:58
  • I edited the post, fixed my grammar errors and added an image, sorry – Víctor GV Nov 21 '23 at 11:11
  • 1
    If you want to do this with python, please use the python tag on your question (I took the freedom to add it). – Gordon Brinkmann Nov 21 '23 at 11:17
  • 1
    That seems to be most likely because every chain part is at the same location (world origin) – lemon Nov 21 '23 at 11:32
  • Every chain part has its own origin and not located in the world origin. In fact, when I apply the solution proposed in the link where the object is the parent it works perfectly placing the nulls in the parts' origins... but when making the empties the parents they appear at the world origin as shown above. – Víctor GV Nov 21 '23 at 11:42
  • 1
    Same here, the code works as expected. There is something else specific to your objects setup – lemon Nov 21 '23 at 11:43
  • Ok, I applied All transforms to the objects and there is when the problem begins and the empties appear at the world origin. I need that objects whitout transforms... Can I apply transforms and get the emptys where the objects are? – Víctor GV Nov 21 '23 at 11:52
  • Well, I tried and I can run the script and then apply all transforms. This way I get the parenting and clean transformations – Víctor GV Nov 21 '23 at 12:02
  • 1
    could you share your file? that will help to try to see what is happening here – lemon Nov 21 '23 at 12:04
  • 1
    The chain parts have a delta transform. But without it they effectively are at the same location. – lemon Nov 21 '23 at 12:27
  • 1
    I think you need to read a bit more about what applying transform means. It will reset the origin of the object to the world origin. What you want is something like setting the empties at the center of mass or barycenter of geometry, because the origin is set to 0, 0, 0 when you apply the location – Gorgious Nov 22 '23 at 07:48

0 Answers0