0
$\begingroup$

enter image description here python blender create parent create child keep transform blender3D

parent keep transform??

objects = bpy.data.objects

a = objects['Cube']

b = objects['Cube.001']

b.parent.keep_transform = a

CODE:

import bpy # sin esta libreria no funcionan los comandos en blender
techos = bpy.context.selected_objects

for i in techos:
    #bpy.ops.object.empty_add(type='PLAIN_AXES',radius=100,location = i.location) = o

    empty = bpy.data.objects.new( "empty", None )#crea un empty y lo guarda en una variable
    bpy.context.scene.collection.objects.link(empty)#agrega el empty a la escena
    empty.empty_display_size = 3 #da un tamaño al empty
    empty.empty_display_type = 'PLAIN_AXES'#determina la forma del empty
    empty.location = i.location #la locacion del empty es la misma que la del objeto seleccionado


    i.parent = empty#el objeto seleccionado es hijo del empty
    i.matrix_parent_inverse = empty.matrix_world.inverted()    

    #i.parent_set(i,keep_transform = True)
    #i.parent_set()
    print(empty)

I found a solution, putting the object "I" on both sides, however I can't understand it well blender keep transform parent

$\endgroup$
  • $\begingroup$ parent keep transform?? objects = bpy.data.objects a = objects['Cube'] b = objects['Cube.001'] b.parent.**keep_transform** = a ??? $\endgroup$ – Ariel Gimenez Sep 15 '19 at 3:47
1
$\begingroup$

If you want to retain the transformation of the child you can do this:

 b.parent = a
 b.matrix_parent_inverse = a.matrix_world.inverted()

enter image description here

You need to update depsgraph after creating the empty (matrix_world of the newly created object is updated after updating depsgraph):

import bpy # sin esta libreria no funcionan los comandos en blender
techos = bpy.context.selected_objects

for i in techos:
    #bpy.ops.object.empty_add(type='PLAIN_AXES',radius=100,location = i.location) = o

    empty = bpy.data.objects.new( "empty", None )#crea un empty y lo guarda en una variable
    bpy.context.scene.collection.objects.link(empty)#agrega el empty a la escena
    empty.empty_display_size = 3 #da un tamaño al empty
    empty.empty_display_type = 'PLAIN_AXES'#determina la forma del empty
    empty.location = i.location #la locacion del empty es la misma que la del objeto seleccionado


    # Add this line
    bpy.context.evaluated_depsgraph_get().update()


    i.parent = empty#el objeto seleccionado es hijo del empty
    i.matrix_parent_inverse = empty.matrix_world.inverted()    

    #i.parent_set(i,keep_transform = True)
    #i.parent_set()
    print(empty)
$\endgroup$
  • $\begingroup$ It does not work although I can make the relationship the object moves from its place of origin. $\endgroup$ – Ariel Gimenez Sep 15 '19 at 4:23
  • $\begingroup$ Please see edit. Is it possible for you to share your code? $\endgroup$ – Blender Dadaist Sep 15 '19 at 4:44
  • $\begingroup$ there I put the sample code choose some objects from the scene and this script creates an empty which is then the parent of the selected object $\endgroup$ – Ariel Gimenez Sep 15 '19 at 4:55
  • $\begingroup$ Please see the updated code. You need to add the line: bpy.context.evaluated_depsgraph_get().update() $\endgroup$ – Blender Dadaist Sep 15 '19 at 5:12
  • $\begingroup$ Update the publication with the solution I found or found, but I vote yours too. If instead of putting empty I put "I" the problem is solved, but in the way you told me too, even if I don't understand it very well, you helped me a lot ... until next time ... $\endgroup$ – Ariel Gimenez Sep 15 '19 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.