Index: trunk/src_plugins/io_tedax/io_tedax.c =================================================================== --- trunk/src_plugins/io_tedax/io_tedax.c (revision 760) +++ trunk/src_plugins/io_tedax/io_tedax.c (revision 761) @@ -512,7 +512,8 @@ static int camv_tdx_save_design(camv_design_t *camv, const char *fn) { write_ctx_t ctx; - rnd_cardinal_t n; + long n, end, i; + int open_ly = 0; const camv_layer_t *ly; if (tdx_open_write_header(camv, &ctx, fn) != 0) @@ -521,17 +522,24 @@ for(n = 0; n < camv->layers.used; n++) tdx_write_layer_grps(&ctx, camv->layers.array[n]); - for(n = 0; n < camv->layers.used; n++) { + /* write layers in reverse order so the file is top->bottom */ + end = camv->layers.used; + for(n = camv->layers.used-1; n >= 0; n--) { ly = camv->layers.array[n]; if (!ly->sub) { - if (n > 0) + if (open_ly) tdx_write_layer_foot(&ctx, ly); tdx_write_layer_head(&ctx, ly); + open_ly = 1; + for(i = n; i < end; i++) + tdx_write_layer(&ctx, camv->layers.array[i]); + end = n; } - tdx_write_layer(&ctx, ly); } - tdx_write_layer_foot(&ctx, ly); + if (open_ly) + tdx_write_layer_foot(&ctx, ly); + return tdx_close_write_header(&ctx); }