Batch conversion¶
Convert a folder of schematics into Litematica files, keeping a JSON result for each input. The script continues after a failed or blocked conversion, but exits with a failure status if any input could not be saved. Inspect the report even when some outputs were saved.
Download batch_convert.py and
conversion-inputs.zip. Extract the
archive into an incoming directory; it contains workshop.schem and the
two-region workshop-regions.litematic. Choose a separate output directory:
uv run --with mcschemora batch_convert.py incoming output/converted
Both supplied inputs convert successfully:
workshop-regions.litematic: saved
workshop.schem: saved
The output contains workshop-regions.litematic.litematic,
workshop.schem.litematic, and report.json. Appending the new suffix to each
full filename keeps outputs separate when input stems match across formats.
Download the successful sample report
to compare the results.
Blocked exports¶
Converting the same inputs to WorldEdit requires flattening:
uv run --with mcschemora batch_convert.py incoming output/worldedit --format schem --flatten
The multi-region input has flattening losses, so its result is blocked.
Review report.json before rerunning with --allow-loss; that flag never
permits an export error. Use --version to choose a supported target Java
version, allowing for any intermediate catalogs that preparation needs.
Error handling¶
The script reads immediate directory children ending in .schem, .litematic,
.nbt, or .snbt. It caps binary NBT decompression at 64 MiB per input and
records failures in the report. Legacy .schematic and MineColonies .blueprint
files are unsupported inputs.
Rerunning replaces existing outputs. Each schematic save is atomic, but an interrupted batch can leave some converted files without a final report. Keep that possibility in mind when using the script in an automated pipeline:
import argparse
import json
from pathlib import Path
from mcschemora import Schematic
def main():
parser = argparse.ArgumentParser(description="Convert a directory and report every outcome.")
parser.add_argument("source", type=Path)
parser.add_argument("destination", type=Path)
parser.add_argument("--format", choices=("schem", "litematic", "nbt"), default="litematic")
parser.add_argument("--version")
parser.add_argument("--flatten", action="store_true")
parser.add_argument("--allow-loss", action="store_true")
args = parser.parse_args()
if not args.source.is_dir() or args.source.resolve() == args.destination.resolve():
parser.error("Use an input directory and a separate output directory.")
sources = sorted(
path
for path in args.source.iterdir()
if path.is_file() and path.suffix in {".schem", ".litematic", ".nbt", ".snbt"}
)
if not sources:
parser.error("No supported input files found.")
args.destination.mkdir(parents=True, exist_ok=True)
results = []
for source in sources:
result = {"source": source.name}
try:
scene = Schematic.load(source, max_unpacked_bytes=64 * 1024 * 1024)
report = scene.check_export(
format=args.format, version=args.version, flatten=args.flatten
)
result.update(
import_diagnostics=scene.import_diagnostics,
errors=report.errors,
losses=report.losses,
)
if report.errors or (report.losses and not args.allow_loss):
result["status"] = "blocked"
else:
destination = args.destination / f"{source.name}.{args.format}"
scene.save(
destination,
format=args.format,
version=args.version,
flatten=args.flatten,
allow_loss=args.allow_loss,
)
result.update(status="saved", output=destination.name)
except (OSError, ValueError) as error:
result.update(status="error", message=str(error))
results.append(result)
print(f"{source.name}: {result['status']}")
(args.destination / "report.json").write_text(json.dumps(results, indent=2) + "\n")
if any(result["status"] != "saved" for result in results):
raise SystemExit("Some files were not converted; read report.json.")
if __name__ == "__main__":
main()
See files and conversion for supported formats and handling retained imported data.