From what I remember
1) there is a sort of persistence, at least in FC "session", so if you define a method (function) in a script you will usually find it available in the Python Console.
2) There are however some settings to add some "isolation level" to the code input and executed as a script in the "Macro Editor", in
Preferences >> General >> Macro >> General macro settings - Run macro in local environment that at least in theory should isolate some more the code executed in the "Macro Editor"
You could however add proper line to launch the code in the editor after the code copied, and test here the working.
The whole article you linked create a WorkBench (WB) with the code so it could be activated and used in FC without explicit loading it "Macro Editor"
Edit
Probably I've made a mess mixing infos about Feature Python Objects (FPO), and the code linked is not creating FPO, offending lines are barred below.
There are many ways to make a job, if you want objects in a standard FCStd file, I think the only viable way is to "make a WB" so the code could be found by FC when you open the document containing "custom objects".
But this file is not portable unless the recipient will have the WB installed.
Some old test I've done were not clear at least from what I remember:
The file is open without errors, but some thing could occur:
1) if you try to modify the object it throw an error
2) the actions are not executed due to the lack of proper code.
Anyone know some more detailed infos, maybe with some link to wiki pages where the mechanic is explained?
https://wiki.freecadweb.org/Create_a_Fe ... ect_part_I
https://wiki.freecadweb.org/Create_a_Fe ... ct_part_II
Sorry for the mess.
End Edit
Regards
Carlo D.