Skip to content

Instantly share code, notes, and snippets.

@danielbierwirth
Created June 10, 2024 08:48
Show Gist options
  • Save danielbierwirth/738a03192f0afa9976c8744b8364adc7 to your computer and use it in GitHub Desktop.
Save danielbierwirth/738a03192f0afa9976c8744b8364adc7 to your computer and use it in GitHub Desktop.
Pixyz Studio automation script to export model hierarchy and metadata as json file. Each occurrence with attached metadata will be exported as json tree. Run this script in Pixyz Studio python console
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# [USER PARAMETER] Desired file path
FILE_PATH = 'C:/output/modeldescription.json'
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_metadata_dict(metadata):
metadata_dict = dict()
metadata_dict['name'] = metadata.name
metadata_dict['value'] = metadata.value
return metadata_dict
def get_hierarchy_dict(occurrence):
hierarchy_dict = dict()
hierarchy_dict['name'] = core.getProperty(occurrence, "Name")
hierarchy_dict['children'] = [get_hierarchy_dict(child) for child in scene.getChildren(occurrence)]
if scene.hasComponent(occurrence, scene.ComponentType.Metadata):
metadata = scene.getComponent(occurrence, scene.ComponentType.Metadata)
metadata_definitions = scene.getMetadatasDefinitions([metadata])[0]
hierarchy_dict['metadata'] = [get_metadata_dict(metadata_definition) for metadata_definition in metadata_definitions]
#for metadata in metadata_definitions:
# metadata_info = f'(name: {metadata.name}, value: {metadata.value})'
# print('\nmatadata ' + metadata_info)
return hierarchy_dict
def main(root, filePath):
hierarchy_dict = get_hierarchy_dict(root)
with open(filePath, 'w') as file:
json.dump(hierarchy_dict, file)
print('\nDone: structure tree exported at ' + filePath)
main(scene.getRoot(), FILE_PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment