Skip to main content

recreate_layers_from_3ds

import maya.cmds as cmds
import json


# Function to create the hierarchy
def create_hierarchy(parent, data):
for item in data:
# Create an empty group (null object)
name = None

if cmds.objExists(item["name"]):
name = item["name"]

else:
null = cmds.group(empty=True, name=item["name"])

# Parent the null object to the parent if a parent is provided
if parent:
cmds.parent(null, parent)

# Recursively add children
if "children" in item and item["children"]:
create_hierarchy(null, item["children"])

# Main function
def main():
# Parse the JSON data
#data = json.loads(json_data)
param_path = r"C:/users/BT/Desktop/layers_hierarchy.json"
with open(param_path, "r") as read_file:
data = json.load(read_file)

# Create the hierarchy
create_hierarchy(None, data)

# Run the main function
main()