mahmoudabdelrahman / gh_cpython Goto Github PK
View Code? Open in Web Editor NEWCPython plugin for Rhino-Grasshopper
License: BSD 2-Clause "Simplified" License
CPython plugin for Rhino-Grasshopper
License: BSD 2-Clause "Simplified" License
Is there any information on the difference with https://github.com/Digital-Structures/ghpythonremote ? Could this comparison be added to the wiki?
Dear Mahmoud,
Thank you for the updated GH_CPython.
In case an input variable is not assigned, the component does not run. Even though this is not an urgent issue, sometimes we need to test before assigning all input variables.
regards,
Jihoon
Hi @MahmoudAbdelRahman! I'm here with another error. Thanks for being so open to feedback!
I'm trying to receive strings and multi-line strings as inputs, but am getting a curious error. My use-case is to input a multi-line string into GH_CPython and to have it in a variable as a multi-line string, but GH_CPython seems to be doing some internal stuff that affects how things are being processed.
Specifically, I'm working with LispHopper so I can input a string such as (print "hello")
and everything handled and characters escaped properly and placed in a variable in GH_CPython.
Thanks!
Hi @MahmoudAbdelRahman , thanks for such a wonderful project - really excited to have 'real' Python in Grasshopper.
Is there a good way to access the GH file location from within GH_CPython?
I'd like to write some Python in the same directory as the .gh file and import those files. However, os.path.dirname(os.path.realpath(__file__))
is returning C:\Gh_CPython
.
Thanks!
In the wiki it says you can change node's icon by drag&dropping 24x24px PNG file. I tried but it doesn't change. Does that feature work in Rhino7?
Hi,
Do you think you can compile and release a version where the 'temp' interpreter files are not on C: but on a "USER"\Desktop\GH_CPython?
On windows lab servers writing on C: or even having separate 'virtual' folder directly on C is not going to work.
If you change the path to be inside the USERS personal folder it would be amazing.
Thanks
Really great job !
I think it would be good if we had line numbering.
Hi @MahmoudAbdelRahman ,
Thank you for this pluggin.
One question, is it compatible with Rhino 6 ?
I have followed the instructions from the wiki (.gha
and .dll
files in library
folder + open Rhino as administrator) but:
The only dialogue box that I have is when I double-click on .gha file directly from the library folder, Rhino opens and displays the following message
Is it just me or a Rhino 6 compatibility issue ?
I got the following error following the simple demo code as shown on GitHub for the GH_CPython component. May I ask why this error is related to the print function which I didn't use at all?
Traceback (most recent call last):
File "C:\GH_CPython\PythonFileWritten_2.py", line 36, in <module>
import Grasshopper as gh
File "C:\GH_CPython\Grasshopper.py", line 99
print allLines[5]
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(allLines[5])?
The code is here:
"""
Python Script
Created on Wednesday October 2020 01:09:39
@author: AAA
[desc]
Description of the plugin Here
Write here any thing...
[/desc]
ARGUMENTS:
----------
<inp>
_input :[required] - [type = int] - [default = None]
Descripe your input here
* bullet point.
* bullet point
</inp>
<inp>
Other inputs go here ...
</inp>
RETURN:
----------
<out>
output_ : indicate your output description here. \n refers to a new line.
a :
b :
</out>
"""
import Grasshopper as gh
output_ = gh.addPoint(0, 4, 2)
a = gh.addPoint(-5, 10, 0)
p1 = gh.Point(0, 0, 0)
p2 = gh.Point(5, 5, 5)
b = gh.addLine(p1, p2)
i don't know how to output a datatree.
Right now i'm using a second python script with the raggedListToDataTree function (https://gist.github.com/notionparallax/5433271)
Is there a better way?
Great work,
i try to create a exelsheet manipulator with pandas etc. at it works.
The only problem is the input and output of your cpython node.
Input:
Tree with branches
Item with one string
Output
Tree with branches
Tree with branches Item in each branch
If i print the input everything looks fine and its seams not possible to change the output to item because the manage data ouptput in your cpython node is emtpy only input shows correct.
I really hope you keep on going develope the cpython plugin it works phantastic.
Again great work
Currently the input access is set to list and doesn't seem to be possible to change it.
Dear Mahmoud,
GH_CPython does not save codes. I know you already fixed bugs in the input parts. Bugs in saving codes also need your care.
Thanks.
Jihoon
Hi!
I want to get iterative outputs by using "ghenv.Component.ExpireSolution(True)" as follows:
http://www.grasshopper3d.com/forum/topics/loops-in-gh-python (py_loop.gh)
In GH_Python, such script would walk fine and outputs are recomputed in each iterations.
However, In GH_CPython, I recieved this message: AttributeError: 'fileInfo' object has no attribute 'Component'
Is it possible to use "ghenv.Component.ExpireSolution(True)" in the current version of GH_CPython?
Hello Mahmoud!
You forgot the paranthesis in the print statement in the last line ;p the Grasshopper ( 02 ? ) module can't be imported.
Outstanding initiative, by the way! Thank you so much! I'll try to catch up with the know-how and maybe help in the near future :D
edit: same for line 155: print "you have to create surface from 4 points"
Hi, I've just tried to import numpy or matplotlib in grasshopper with GH_CPython.
I have Spyder 3 (ANACONDA), Python standalone, Microsoft Visual studio.
My operating system is Windows 10.
It gives me a long errors messages and gives me some advise like:
from . import distributor_init
Traceback (most recent call last):
File "D:\anaconda3\lib\site-packages\numpy\core_init.py", line 24, in
from . import multiarray
File "D:\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in
from . import overrides
File "D:\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\GH_CPython\PythonFileWritten_6.py", line 24, in
import numpy as np
File "D:\anaconda3\lib\site-packages\numpy_init_.py", line 142, in
from . import core
File "D:\anaconda3\lib\site-packages\numpy\core_init_.py", line 54, in
raise ImportError(msg)
ImportError:
"
So, I don't knwo how can I figure out this issue! My goal is be able to use the whole python libraries on Grasshopper.
Thanks!
What a great plugin!
I was wondering though if there is a way of setting the default values for the inputs?
Many thanks,
N/
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
2 ) when I input an actual tree - I get errors when I set data acces type to either tree or list
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
Hi Mahmoud,
first of all, thank you very much for developing this, as it has been a missing component from GH. I just want to ask you about the installation process. Is it a simple copy of the gha into the libraries folder?
The component is visible in my tooldbar, but whenever I try to run any code, the process freezes and Rhino crashes.
Any advise will be much appreciated.
I have several python tools that run outside Grasshopper that I would like to implement and some of them run using Pandas module. Do you think this is something that will be stable enough in the environment you are building?
Thank you very much,
-Byron
Hi there!
I am running Pandas to read an .xlsx file into GH_CPython. As this process is quite slow, I want to do it once and then send the imported Dataframe to other GH_CPython components. However, everytime I connect the output with the input, it crashes.
I have tried 'hiding' the Dataframe in a class. The program doesn't crash, but it doesn't see the Dataframe either.
Is there any way I can send a Dataframe to other components?
Thanks a lot!
Hi,
Thanks for the great work on this! It seems to me that it should be possible to use this with Anaconda, however, when I set a custom interpreter and try to import numpy, I receive this error:
C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\GH_CPython\PythonFileWritten_2.py", line 33, in <module>
import numpy
File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.6 from "C:\Users\USERDIR\.conda\envs\cpython36\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
(Please note that I replaced my user directory in the paste above)
Opening the environment in a CLI and importing numpy from there works without any problems.
One user reported #39 that reinstalling the numpy package solved the issue for him but that, unfortunately, doesn't work for me.
Is there anything I can do to get this running with Anaconda?
Best,
Patrick
Traceback (most recent call last):
File "C:\GH_CPython\PythonFileWritten_1.py", line 1, in
exec('output_ = None\n_input = Referenced Mesh (V:152257 F:50991) \n\nclass fileInfo:\n def init(self):\n self.filePath = "E:/ZJJ/地形分区快/unnamed.gh"\n self.fileName = "unnamed"\nghenv = fileInfo()\n\n\n')
File "", line 2
_input = Referenced Mesh (V:152257 F:50991)
^
SyntaxError: invalid syntax
Just got a problem to output string array. Each single array is in single quotes.
test become 'test'.
I also have a problem to output "[" in a string array. It just disappeared. "{" and "(" works but not "[".
Any suggestions?
Hi,
Thank you very much for this awesome work!
I have installed Anaconda on my computer and launched Rhino as Administrator. When I try to import numpy, CPython shows an error not fiding 'numpy'.
I'd appreciate if you could help me here.
Thank you
How are you, Mahmoud?
From my testing of GH_CPython, Rhino crashed in case block comment part (""" ... """) was removed from script windows. I am not sure if it happens only at my computer.
regards,
Jihoon
I'm getting a strange error when returning a very specific value: "Line(3)" as an output.
My code is:
s = "Line(0123456789)"
output_ = s
Any ideas? Thank you, @MahmoudAbdelRahman !
Dear Mahmoud,
Adding input parameter such as 'x' without assigning data to it makes me unable to open the editing window of GH_CPython. I am not sure if it is a kind of bug or another issue.
Best regards,
Jihoon
Hi Mahmoud,
I have some problems with the component, I did as instructed in the wiki; placing the .gha
and the .dll
inside ./Libraries
. I also ran Rhino as admin. The component appears on my component tab but it won't run anything. Also, File>Open and Save as doesn't open a window.
Clicking test only updates the 'successful in _ ...' part.
I've tried Py 2.7, 3.5 and 3.6
. Could you help me? Thanks in advance!
Btw, I was also wondering what the little green box was for.
Looks like this is going to be my new favorite plugin :)
Hi,
Is it possible to input a numpy matrix and use numpy.asmatrix to cast input as numpy matrix? What I am trying to do it use one CPython component to read a big binary file as matrix then use the second CPython component to get information out of the matrix. By using two component, i think I could avoid the slow process of reading the file every time a variable changes.
Another question is how to input a file path? Can you give an example? I tried a couple of ways but did not manage to get it to work. Many thanks.
Hello!
when i restart the grasshopper,it always has the problem:
File "C:\GH_CPython\PythonFileWritten_1.py", line 1
SyntaxError: Non-ASCII character '\xe2' in file C:\GH_CPython\PythonFileWritten_1.py on line 1, but no encoding declared
However,# -- coding: utf-8 -- has been in line1
Thanks!
Feature request: Do you think you could implement the 'F5' keyboard shortcut for testing that's in GHPython already? It's a very helpful feature that can make the editor feel a bit more like a REPL.
Thank you!!
Importing the numpy c-extensions failed.
Strangely this works on my laptop, but on the PC I cannot solve this.
I have anaconda python 3.6 installed with all the modules. These work in Jupyter Notebook for example, but not in GH.
1. Traceback (most recent call last):
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\numpy\core\__init__.py", line 17, in <module>
from . import multiarray
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: Nie można odnaleźć określonego modułu.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\GH_CPython\PythonFileWritten_5.py", line 3, in <module>
from sklearn.externals import joblib
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\sklearn\__init__.py", line 74, in <module>
from .base import clone
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\sklearn\base.py", line 17, in <module>
import numpy as np
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\Mateusz\Anaconda3\envs\gh36\lib\site-packages\numpy\core\__init__.py", line 47, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.6 from "C:\Users\Mateusz\Anaconda3\envs\gh36\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.4" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: Nie można odnaleźć określonego modułu.
Thanks for this valuable development.
Please note the error shown on the following image.
Can the component accept input? How can I use input part with text, number, geometry and so on? Please note the error message on the python test window.
I also found output variable did not work. The panel should show 100 if the component works.
Would you show me how to handle input and output variables? If input and output variable parts are under development, a couple of basic types can be used in stead of all types of objects until the development is completed.
Thanks in advance.
Jihoon
Hello,
Could you please reupload a new zip file here and to food4rhino as the ones that are published still have at least one issue that you have resolved in the source files.
Specifically I am talking about this one - #44 , as I have encoutared it too and corrected my local C:/GH_CPython/Grasshopper.py myself. When I checked it here - I found that you had already made the change in the source files, but the new version is not usable as a distributable.
Hello!
I am wondering it GH_CPython as a "node in code" functionality like GH_Python does (https://stevebaer.wordpress.com/2013/12/11/ghpython-node-in-code/)
GH_CPython is able to run a module I am working with and I am hoping to be able to call firefly components in a script.
Thanks!
Good morning,
I wrote a code to run energy analysis from Python 3.8 in Spyder (Anaconda3) and it works. In a few words, my code modifies the idf file (the file used for the energy analysis) and then launches the analysis in an external software (EnergyPlus). I was trying to use this code in grasshopper using GH_CPython code (with this path C:\Users\Pc\anaconda3\python.exe) but I'm facing different problems, it would be great to have help from you.
I have created a rhinoremote environment and imported all the scripts needed for my Python code (Eppy which is installed in anaconda) and the code seems to work if I modify my .idf file or save it. But if I try to launch the analysis it doesn't work, find attached the error.
C:\Users\Pc\anaconda3\lib\site-packages\numpy_init_.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\GH_CPython\PythonFileWritten_1.py", line 27, in
idf.run(readvars=True, expandobjects=True,output_directory=os.path.join(folderpath,"Output"))
File "C:\Users\Pc\anaconda3\lib\site-packages\eppy\modeleditor.py", line 1009, in run
self.saveas("in.idf")
File "C:\Users\Pc\anaconda3\lib\site-packages\eppy\modeleditor.py", line 974, in saveas
self.save(filename, lineendings, encoding)
File "C:\Users\Pc\anaconda3\lib\site-packages\eppy\modeleditor.py", line 947, in save
with open(filename, "wb") as idf_out:
PermissionError: [Errno 13] Permission denied: 'in.idf'
Hi Mahmoud,
Thanks for the amazing progress! I was wondering if it is possible to add as a future goal Python 3 support.
This is not that critical since the workflows are still completely fine, but I feel a lot of DL libraries are moving to Python 3 support (only?) slowly.
Kind regards,
Theodore.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.