summaryrefslogtreecommitdiff
path: root/start.bat
blob: a96bcd2b3448e9babf1bfc1da03ef11ae4d25d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@echo off
setlocal EnableDelayedExpansion

:: check if the script is at the correct place
echo.
if not exist ".\blender.exe" (
  echo ERROR:
  echo Script is not located at the correct position...
  echo Put it in the same folder as the "blender.exe" file.
  echo.
  pause
  exit
)

:: check blender's python version
if exist ".\2.79\python" (
  for /f "delims=" %%i in ('.\2.79\python\bin\python.exe -c "import sys; print(sys.version[:3])"') do set blender_python_version=%%i
)
if exist ".\2.79\python_original" (
  for /f "delims=" %%i in ('.\2.79\python_original\bin\python.exe -c "import sys; print(sys.version[:3])"') do set blender_python_version=%%i
)
echo.
echo Blender Python version: %blender_python_version%

:: check if the manually installed version exists

:: Python 3.5
echo.
if "%blender_python_version%" == "3.5" (
  py -3.5 --version
  if !errorlevel! geq 1 (
    echo.
    echo ERROR:
    echo Python 3.5 is not installed...
    echo Be sure to add it to PATH.
    echo.
    pause
    exit
  )
  goto all_is_setup
)
:: Python 3.7
if "%blender_python_version%" == "3.7" (
  py -3.7 --version
  if !errorlevel! geq 1 (
    echo.
    echo ERROR:
    echo Python 3.7 is not installed...
    echo Be sure to add it to PATH.
    echo.
    pause
    exit
  )
  goto all_is_setup
)
echo.
echo ERROR:
echo Blender has different Python version as the one expected.
echo.
exit

:: surely nothing else can go wrong
:all_is_setup
echo Correct Python version found.

:: will rename the original python folder to python_original
echo Renaming some files...
ren .\2.79\python python_original
:: will also rename the python35.dll/python37.dll
if "%blender_python_version%" == "3.5" (
  ren python35.dll python35_original.dll
)
if "%blender_python_version%" == "3.7" (
  ren python37.dll python37_original.dll
)

:: set the BLENDER_SYSTEM_PYTHON variable and get the python interpreter path
for /f "delims=" %%i in ('py -%blender_python_version% -c "import sys; print(sys.exec_prefix)"') do set python_base_path=%%i
for /f "delims=" %%i in ('py -%blender_python_version% -c "import sys; print(sys.executable)"') do set python_interpreter_path=%%i
set BLENDER_SYSTEM_PYTHON=%python_base_path%
echo %BLENDER_SYSTEM_PYTHON%
:: run Blender sending as first argument the python interpreter path
blender.exe -- %python_interpreter_path%

:: will unrename the files renamed
:: so that blender can be used without Blenxy as well
echo Unrenaming renamed files...
ren .\2.79\python_original python
if "%blender_python_version%" == "3.5" (
  ren python35_original.dll python35.dll
)
if "%blender_python_version%" == "3.7" (
  ren python37_original.dll python37.dll
)
pause