I have a script in which I’m importing data from another program, to correct for the ZY reversal I rotate the objects 90 degrees. After all objects have been positioned and key framed I run a function that does any necessary parenting of objects. The problem is even though the script executes in that order the parenting seems to happen before the rotation. Does anyone know why this would be? Are there any helper functions to make sure something runs after objects have been added and their data set? Like an internal “after” method you could places your code in?
The following is a part of the script, which shows the execution order. The main function “run” is called, which loops through data creating new blender objects of different types (and adding them to the scene), in each loop it checks for a parent property as well and adds the child and parent name to an array for later use. After all the data has been looped through and the objects created the set_parents() function is run, which goes through the before mentioned array and created any necessary parent/child relationships.
Thanks, any help is appreciated.
class Main():
def __init__(self, json_data):
self.json_data = json_data
self.defaultComp = json_data['compositions'][0]
self.compSettings = self.defaultComp['compSettings']
self.relationships = []
#['ObjectName1':'ParentName1', 'ObjectName2:ParentName2']
def run(self):
layers = self.defaultComp['layers']
for layer in layers:
layerType = layer['layerType']
if(layerType == 'Null'):
obj = Empty(self.compSettings, layer)
elif(layerType == 'Solid'):
obj = Mesh(self.compSettings, layer)
elif(layerType == 'Camera'):
obj = Camera(self.compSettings, layer)
self.check_for_parent(layer)
self.set_parents()
def check_for_parent(self, child):
if(child['parent'] != 0):
self.add_to_relationships(child['parent'], child['name'])
def add_to_relationships(self, parentName, childName):
self.relationships.append({'parent': parentName, 'child': childName})
def set_parents(self):
print('set_parents')
for relation in self.relationships:
child = bpy.data.objects[relation['child']]
parent = bpy.data.objects[relation['parent']]
child.parent = parent
Full script here https://github.com/ichabodcole/JSON2Blender/blob/master/app/JSON2Blender.py
