Why not push the branch with your changes to the official FreeCAD repo, I'll take it from there, we can delete it afterwards when we're done... After all the official FreeCAD repo is a bit yours by right

I don't want to pollute the official repo. And since I still have some old branches on SF I anyway need a github repo to migrate them some time.

Then in order to not let crash the application it might be good to put the invoking of the script in a try/catch block:

Yorik wrote:I can do that too, just go to the compiled lib folder, run a python3 console and "import FreeCAD". This is what I have in that folder, btw, no libFreeCAD.so:

Here you have to be careful which exact Python version you are running. I have setup a clean Debian sid and "python" is Python 2.7, python3 is Python3.4 and Python3.5 is the needed command to get the correct version.

I now have ported MainPy.cpp and of course "python" doesn't work. However, "python3" gives error message:

While initializing FreeCAD the following exception occurred: ''ParameterGrp' object has no attribute 'GetString''

ParameterGrpPy is one of the remaining classes that were manually written and its type object is not set up properly. Instead, attributes are accessed via the macro _getattr_up which doesn't work with Python3.

building with py2 works too. Still a couple of small issues here and there, and the GUI module still fails with py3, but this should be much easier to solve.I am learning a lot by looking at your commits... Many things I read on the net make sense only now...

Found an oddity with PyCXX's Py::PythonExtension template class. The methods of ParameterGrpPy can be accessed now but when doing a "dir()" on the object it gives an empty list. Looks like a bug in PyCXX which is still there in the latest version.

There are a few more changes on my branch:

reverted back to PyUnicode_AsUTF8 in the Console methods.
There are actually two ways to do it:
PyUnicode_AsEncodedObject and PyBytes_AsString or PyUnicode_AsUTF8 but you can't mix PyUnicode_AsEncodedObject and PyUnicode_AsUTF8

current status:
with py3: builds with all modules disabled. runs in command mode, not in GUI mode
with py2: builds with all modules enabled, runs in both command and GUI mode

the py2 build however gives a lot of errors when running the tests from test WB. Normal, much of the underlying code has changed. I'm surprised it built at all I started looking at them, one thing annoys me, although I had read the contrary, it seems that under py2, PyLong_Check refuses to recognize an int as long:

yes, in master all integer checks are with PyInt_Check. However this is removed in py3 (all ints are longs). In all docs I've read, it said you could safely replace all PyInt_Check by PyLong_Check, that it would work for both... But apparently not

Before starting to port the FreeCAD modules we should first cleanup a few things in master so that it doesn't diverge too much from the py3 branch.
So, can you incorporate my latest changes and then rebase on master?