|  | import sys
import re
import json
import glob
# here's the import workflow:
# 1. import buildings into blender
# 2. use the blender-building.py script in blender while selecting a building to export images
# 3. batch-trace and color the overlay images
# 4. batch-trace the base images
# 5. batch-expand all of the images
# 6. use this script to combine the images and record the building data
# 7. batch-crop the combined images
# this script smashes two svgs together in a way that is,
# to be frank, sacrilege
def combine(base_path, highlight_path, output_path):
    base = open(base_path, "r", encoding="utf-8").read()
    highlight = open(highlight_path, "r", encoding="utf-8").read()
    
    base_data = re.search("<path.*?</svg>", base)[0][:-6]
    highlight_data = highlight.replace("</defs>", "</defs>" + base_data)
    with open(output_path, "w", encoding="utf-8") as f:
        f.write(highlight_data)
if len(sys.argv) <= 1:
    print(f"Usage: {sys.argv[0]} [location name]")
    sys.exit(1)
sides = [
    "North",
    "Northwest",
    "West",
    "North (Top)",
    "West (Top)"
]
template = """    results.push(makeRealBuilding(
        "{0}",
        [
{1}
        ]
    ))
"""
side_strings = []
for path in glob.glob("*.json"):
    with open(path, "r") as f:
        data = json.load(f)
        if data["place"] == [sys.argv[1]]:
            name = "./svgs/" + data["name"]
            for side in sides:
                base = name + "-" + side + "-base-01.svg"
                highlight = name + "-" + side + "-highlight-01.svg"
                result = name + "-" + side + ".svg"
                combine(base, highlight, result)
                side_strings.append("            [\"{0}\", {1}]".format(data["name"] + "-" + side, data["views"][side]))
print(template.format(sys.argv[1] + " Buildings", ",\n".join(side_strings)))
 |