Customer Marlin Build Failing dev not defined

I am trying to build a custom Marlin for Makerbase Robin E3 board. I got the firmware from the makers and I am having trouble building.
In PlatformIO, I am getting this error.
NameError: name ‘env’ is not defined:
File “C:\Users\jthrasher.platformio\penv\Lib\site-packages\platformio\builder\main.py”, line 180:
env.SConscript(env.GetExtraScripts(“post”), exports=“env”)
File “C:\Users\jthrasher.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py”, line 598:
return _SConscript(self.fs, *files, **subst_kw)
File “C:\Users\jthrasher.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py”, line 285:
exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
File “C:\Users\jthrasher\Downloads\MKS ROBIN E3+ TFT35-FW\MKS ROBIN E3+ TFT35-FW\MKS_Marlin-2.0.6.1_for_ender3_TMC2209\Marlin-2.0.6.1_for_ender3_TMC2209\buildroot\share\PlatformIO\scripts\mks_robin_e3.py”, line 6:
for define in env[‘CPPDEFINES’]:

In the IDE, env is showing as not defined.
There is an Import for it:
from ast import Import ← I added this to resolve an error with Import.
import os
Import(“env”)

I am not sure where to go from here. Please let me know if I can provide additional information.

No. The red squiggles in this script mean nothing because it cannot dynamically resolve the Scons Import() function. Adding in the Import function from the ast pacakge is wrong, you should undo that change.

You’re attempting to compile an older Marlin version likely with PlatformIO core 6, which does not have needed backpatch

What does CLIpio system info say?

I am not sure how to get to the CLI. However, it is Core 6.1.10

I specifically linked the “CLI” word as a link to the documentation, but it doesn’t seem you clicked on it.

Then either download https://github.com/MarlinFirmware/Marlin/commit/ba38d4f411c1d43eb62b210ba668b4aaca9e15ee.diff and git apply that into your firmware version (or equivalently with the .patch file and the patch tool) or downgrade your core to 5.x, e.g., pip install "platformio == 5.2.5" in the aforementioned CLI.

Sorry. Thought that was a random hyperlink.
PlatformIO Core 6.1.10
Python 3.11.4-final.0
System Type windows_amd64
Platform Windows-10
File System Encoding utf-8
Locale Encoding cp1252
PlatformIO Core Directory C:\Users\jthrasher.platformio
PlatformIO Core Executable C:\Users\jthrasher.platformio\penv\Scripts\platformio.exe
Python Executable C:\Users\jthrasher.platformio\penv\Scripts\python.exe
Global Libraries 0
Development Platforms 1
Tools & Toolchains 5

I will try downgrading. Thank you for your help.

Ok. I tried downgrading and it didn’t seem to work.
So, now I am trying to apply the .diff.
Below is the error I get.
Thank you again for the help.

EDIT:
I did copy and paste from the URL. It may have added a weird character at the end. I will try a direct download.

That gave yet another error.

I guess I will try the downgrade again.

Can you invoke it like this

git apply --reject --whitespace=fix "path to .diff file"

That worked. It rejected one update.
And I am getting the same error.

No it didn’t apply the patch correctly if there is still a for define in env['CPPDEFINES'] in there. That should be gone after the pathc.

PLease replace the contents of the mks_robin_e3.py file with exactly what’s in https://github.com/MarlinFirmware/Marlin/blob/ba38d4f411c1d43eb62b210ba668b4aaca9e15ee/buildroot/share/PlatformIO/scripts/mks_robin_e3.py

Compile Successful !!!
Thank you SO much for the help. Now, I have to learn to upload it and deal with the .BIN

Thank you again!