Python ? why?

Hi all,

I’m totally ignorant with python, but sometimes i see some of you adding C+ or python in definitions.Is it faster or lighter to compute instead of conventional grasshopper def?


I can only speak to my opinon…but I think the reasons are generally something like this.
1 - A scripting component is used to perform a task/series of tasks, that might not be directly achievable with native GH compoentns
2 - Depending on the operation, sometimes a few lines of code in one component can take the place of many native components
3 - some people like to write their own! (whether we should or not…sometimes you end up writing something, only to later realize that a plug-in has already been written…that does the job better than you did!)

Scripts are good for making essentially your own components especially for things that do not exist yet, They are faster for the most part but as a routine not in comparison to a single component then it will be similar in speed. For instance, you might have a routine that you do often which uses 10 components, well you can cluster that into one component (but it is usually slower) or you can script the routine as one component and it can be very fast. One of the biggest uses for scripting is looping and recursion which you cannot do in grasshopper without plug-ins like Anemone.

And you can import external modules to write your own import export for example
xml reader writer for open exel

Plus there is the use of Python scripts OUTSIDE of Grasshopper in the native Rhino environment. In that case they can be integrated as Rhino commands, called from aliases or toolbar buttons, etc.

Ok ,thanks a lot !
As I’m using Anemone for recursive calculation (truely amazing and fast compared to normal Rhino modeling)
I always want more…so do you consider Python as a must have when using grasshopper every days, or another tool depending of what you got to achieve in Rhino?
I have to confess grasshopper was a hard part to control, with trees , path mapper,solvers, recursives etc…will it be kind of same difficulty with python if you advise me to go threw?


I found data control easier in scripting because loops solve a lot of headaches caused with data trees. The hard part of course is the syntax. Once you know the language it is, in my opinion, easier to do a lot of things, but learning a language to a good level is harder than learning how to use grasshopper.

1 Like

I think it’s a essential if you want to focus your work around computational design. If you only use Grasshopper occasionally, I think concentrating on mastering those tools first is more important then learning a programming language and ultimately learning how to program for GH/Rhino. By all means, if you’re interested, it’s a great skill to have.

Personally, I end up using a lot of Python and C# components. This is mainly because I learned those programing languages years before touching GH. I default to coding when doing somewhat complicated math/logic or in some cases where I know dealing with the tree logistics is going to be a pain. It of course opens up a lot of doors like recursion, custom goals, calling applications outside… It can also be easier reuse code snippets with functions then it is to grab chunks of GH file to reuse them elsewhere or implementing clusters.

Well, you have cross must of the bridge, a good thing about grasshopper is that it teach you most of the important programming concepts that are require either to learn python or C#(programming languages are very similar even weird ones like haskell, you learn one the rest follows a similar pattern), so learning to program becomes a lot easier, still you’re gonna need to get used to reading scripts but learning to program is a lot more accessible today.

Scripting yes, I think is a most have if you want to create more useful, powerful and personalize tools that help you in your everyday professional task, scripting pretty much opens the door to a very wide world of possible uses for grasshopper and it might give you back a lot of the time that you spend on repetitive meaningless task, secondly the knowledge that you acquire can be applied to any other software the offers an API or an SDK, and thirdly it give you back the creative power that designer lost because it was embedded in the tools that we use.

Hmmm very interesting answers you provide to me.
In one hand I see python like a magic wander to improve and get to the next step
in scripting every day tasks,open other gates of thinking my job, to an other, I suspect my skills to be improved.
At the moment I’m stuck with packing objects in a particular way in grasshopper(it’s not a disguised question, I want to find myself!)it seems to be really hard to compute both in grass and math, so for something that seems really hard to do, I understand python could help me.
An observation I often do to myself, is mastering to a good level grasshopper and maybe python has to do with imagination first? I from hand crafting ,did no studies and think this could explain why I feel so slow,
so am I?

Well, I also didn’t have any real technical education, for me I learn to program by studying some math concepts by myself, watching tutorials and searching guidance from the main developers in this forum and gh old forum…, reading their scripts really teach me a lot on how “programmers are suppose to think”, it is always messy, but if you can use GH you can learn to program.

Imagination first, yeah but it’s not the whole story, sometimes programing becomes instinctive, other times you work on script and later you revise it, not been able to understand what the hell the script was suppose to do, so you need to develop heavy patience with yourself, for your example, packing is a difficult problem even for the advance mathematicians and only some small number of developer in this forum can tackle the algorithms require to solve it.(sometimes it has no solution).

A good feature of programming is that you don’t need to understand or solve every problem that you find, for packing you can find code libraries either in python or c# that makes everything easier(and examples publish in this forums too), in this way you only need to learn how to use the library without having to understand the math behind it, similar to using Grasshopper.

When learning to program everyone feels slow because people compare themselves with others who have programmed for 10, 20 years. But I can assure you that there is a moment where everything clicks and it becomes “easier”.

Here is an interesting document about mathematics. It has code sample for Grasshopper and Python.

1 Like

Many thanks to all of you

Also this:

1 Like