mcneel / ghpython

A Grasshopper component for Rhino.Python
http://www.food4rhino.com/project/ghpython
117 stars 34 forks source link

Access/Overwrite the code inside the GHPython from another GHPython component #54

Closed mostaphaRoudsari closed 10 years ago

mostaphaRoudsari commented 10 years ago

I wonder if there is a way that I can can access the code inside the GHPython components on canvas and modify/overwrite them from a GHPython component.

I'm thinking to use this method to update the components that I share with others as user objects. I want to iterate through the components, read the code, check if it is old (in my case there is a line that indicates the version) and overwrite the code with a newer version in case there is a newer version.

Thanks, Mostapha

piac commented 10 years ago

Hi Mostapha

this shows how to achieve an update of the code from another Python component. I made this into a working example, so you can choose the way you would like this to work: either manually, one by one (this is not possible with the usual upgrader), or all components at once.

updater

https://github.com/mcneel/ghpython/blob/master/Samples/quickUpdater.gh

Giulio

Giulio Piacentino for Robert McNeel & Associates giulio@mcneel.com

piac commented 10 years ago

@mostaphaRoudsari: please let me know if this helps -- otherwise, please feel free to open this issue again. Thanks!

mostaphaRoudsari commented 10 years ago

@piac Thanks for the reply. It gives me the error below when I try to open the file. Seems to be an issue with the ghx file. I tried to fix the file but I couldn't get it to work.

updatescript

piac commented 10 years ago

@mostaphaRoudsari I've changed the sample to .gh to have it more easily downloadable

mostaphaRoudsari commented 10 years ago

Hi @piac, Thank you for the new file. I can't still open the file. I asked a friend to test it and he wasn't able to open the file either. Do you have a guess why this is happening? What if you just share the code inside the component?

piac commented 10 years ago

This is just a file on Git -- you can download the whole source, which you already did once, and it will be there. Otherwise, follow the link. Then you'll see the "raw view" link. That is the file that you are supposed to save... I just tried and it worked well. If this does not work, there are some issues on GitHub...

mostaphaRoudsari commented 10 years ago

Hi Guilio, I will try it on more systems and will let you know if I could open it. Thanks.

mostaphaRoudsari commented 10 years ago

We tried on another system and now it is working fine. Exactly what I was looking for. This is a great help. Thank you so much.