MahmoudAbdelRahman / GH_CPython

CPython plugin for Rhino-Grasshopper
BSD 2-Clause "Simplified" License
175 stars 38 forks source link

Tree input data structure not parsing corectly for PythonFileWritten.py #21

Open mcleonte opened 6 years ago

mcleonte commented 6 years ago

Hello again! :D

I've been trying to understand the whole source code more, for a more useful feedback, but I can't seem to find how the "C:\GH_CPython\PythonFileWritten.py" temporary file is getting its input data, and more importantly, how is that input data parsed.

Maybe I have something outdated, not sure, but this is what I'm getting for each data acces type, in 2 different cases:

1 ) when I input a flattened tree (so just a list, basically) - no errors, but there are discrepancies which require to create an additional string parser on the grasshopper canvas in order to further process the output and make it look like the IronPython outputs

image

2 ) when I input an actual tree - I get errors when I set data acces type to either tree or list

image

In the end, I'm guessing that the goal is for the 6 white panels in the center of the screenshot to have the exact same output, and the yellow panels on the left ( from IronPython's print(x) ) is giving some clues about how to do it.

From what I can understand from the runtime error (extracted with some MetaHopper components), the PythonFileWritten.py is receiving wrong parsed input data: x = '[0.0,1.0,2.0,,3.0,4.0,,5.0,6.0]' Instead of the double comma ",," that separates the list (/branch) in a list of lists (/tree), I'm guessing it should have the closing parantheses and a single comma, like "],[", AND have an extra pair of parantheses at the ends of the string, making the parsed string look like an actual list of lists, like this: x = '[[0.0,1.0,2.0],[3.0,4.0],[5.0,6.0]]' In case I missed an update, or updating incorrectly, I'm sorry for the long post. :)) If not, I hope this was helpful enough, without finding where in the source code this is actually happening. :p

Here is the gh file in case you want the template: DataAcces_comparison.zip

os: Windows 10 interpreter: Python 3.6

MahmoudAbdelRahman commented 6 years ago

Hi @Costin-M-Leonte , Thanks so much for this detailed feedback, this is very useful. I'll start working on it.


In C#, the file "C:\GH_CPython\PythonFileWritten.py" is supposed to be created at protected override void SolveInstance(IGH_DataAccess DA) method starting at line 555, Then the python process is started:

pythonFileControl.writeReadPythonFile(this,
                PythonIDE,
                DA,
                thisIndex,
                path);

RunningPythonProcess.StartInfo.FileName = @StartFileName;
//MessageBox.Show(@StartFileName);
RunningPythonProcess.StartInfo.Arguments = path + name + ".py";
RunningPythonProcess.Start();

Each PythonFileWritten.py includes a footer that writes the output variables as an Xml File. Then PythonFileWritten.py is automatically deleted after writing all the results in a xml file (which will be deleted also).

I'll start working on dataAccess, and I'll report the results as soon as possible. Thanks so much. Regards, Mahmoud AbdelRahamn.

MahmoudAbdelRahman commented 6 years ago

Hi @Costin-M-Leonte, I have modified it a little bit Here, converting Tree to list still needs some work, I'll spend more time on it, I think that I'm gonna rewrite that part again. Thanks so much for the feedback. eerr