'bpy.context.scene.cursor.location doesn't update in for loop

I'm trying change the origin point of all the children for the parent objects I have selected.

Right now I'm looping trough all my selected objects and see if one them is a EMPTY. I take this empty and check how many children object it has. I move my 3D cursor to the location of the empty and for each of the children I change them to the origin of the 3D cursor.

This works when I select 1 object. When I select more empty objects I sets all my children's origin to the first selected empty. However when I print out my object's location, it does show that it should be updated. For some reason the 3D cursor can't move anymore after assigning it once;

for obj in bpy.context.selected_objects:
    if obj is not None and obj.type == "EMPTY":
        children = getChildren(obj)
        for c in children:
            print(c.name)
            bpy.context.scene.cursor.location = obj.location
            print("set location to : " + str(obj.location) + "from object :" + obj.name)
            c.select_set(state=True)
            bpy.context.view_layer.objects.active = c
            print("set as active object: " + c.name)
            bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
            print("set new coordinates")
          
def getChildren(myObject): 
    children = [] 
    for ob in bpy.data.objects:
        if ob.parent == myObject: 
            children.append(ob) 
    return children 

enter image description here enter image description here enter image description here



Solution 1:[1]

Found out why :)

When selecting my childs they keptselected, and I had to add the bpy.ops.object.select_all(action='DESELECT')

command to clear the selection after running through my selected objects

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JSadones