# Let's process the JSON file to convert the PCB layout from multi-layer to single-layer and save it to a new file.
import json
file_path = '/mnt/data/PCB_PCB_clap-kit_2_2024-08-12.json'
output_file_path = '/mnt/data/PCB_Single_Layer_clap-kit_2_2024-08-12.json'
# Load the JSON file
with open(file_path, 'r') as file:
pcb_data = json.load(file)
# Define layer IDs for easy reference
TOP_LAYER_ID = '1'
BOTTOM_LAYER_ID = '2'
# Iterate through the objects to move bottom layer objects to the top layer
for obj in pcb_data['objects']:
if obj['layerid'] == BOTTOM_LAYER_ID:
obj['layerid'] = TOP_LAYER_ID
# Update the layers to remove the bottom layer from the design
pcb_data['layers'] = [layer for layer in pcb_data['layers'] if not layer.startswith(BOTTOM_LAYER_ID)]