@echo off

if [%1]==[] goto usage
for %%i in ("%~1") do (
    set "FILENAME=%%~ni"
    set "EXT=%%~xi"
    set "DIR=%%~dpi"
)
call c:\kabellaengen\bin\setenv.bat

REM echo Dateiname ohne Erweiterung: %FILENAME%
REM echo Erweiterung: %EXT%
REM echo Verzeichnis: %DIR%
REM 
REM Namen der auf dem RENAMER Layer gefundenen Symbole, die überschrieben werden sollen
set JSON_SYMBOLS=%FILENAME%_symbols.json

REM Fehlerdatei
set ERROR_FILE=%FILENAME%_errors.json


if exist "%~dp0_setenv.bat" (
    echo Lade lokale Umgebungseinstellungen aus _setenv.bat...
    call "%~dp0_setenv.bat"
)
REM Zielverzeichnis
set TARGET_DIR="%PROJECT_IO_RESULTS%\%FILENAME%"
mkdir "%TARGET_DIR%"
REM lösche alte Fehlermeldungen
del "%PROJECT_WORK%\%ERROR_FILE%"



echo === Creating enriched dxf file  ===
call create_numbers.bat --filename %1 --errorfile %PROJECT_WORK%\%ERROR_FILE% --write %PROJECT_WORK%\%JSON_SYMBOLS% 
if exist "%PROJECT_WORK%\%ERROR_FILE%" (
    @echo -failed- errors found during processing! 
    pause
    move %PROJECT_WORK%\%ERROR_FILE% %TARGET_DIR%
    move %PROJECT_WORK%\%JSON_SYMBOLS%  %TARGET_DIR%
    goto :eof
)
echo move %PROJECT_WORK%\%FILENAME%_* %TARGET_DIR%
move %PROJECT_WORK%\%FILENAME%_* %TARGET_DIR%
pause
goto :eof


:usage
@echo Usage: %0 ^<dxfinWorkOrdner.dxf^>
exit /B 1
goto :eof


