Skip to content
December 12, 2013 / stevebaer

ghPython – Outside the Canvas

As a follow up to my post about the new features in ghPython, I wanted to point out another feature now available; running Grasshopper components outside of the Grasshopper canvas.

Download ghPython…

You will need to have installed ghPython and have used the component in grasshopper at least once. We will fix the “at least once” issue in a future release of ghPython.

  1. Start Rhino
  2. Run EditPythonScript and enter the following script
    import rhinoscriptsyntax as rs
    import ghpythonlib.components as ghcomp
    import scriptcontext
    
    points = rs.GetPoints(True, True)
    if points:
        curves = ghcomp.Voronoi(points)
        for curve in curves:
            scriptcontext.doc.Objects.AddCurve(curve)
        for point in points:
            scriptcontext.doc.Objects.AddPoint(point)
        scriptcontext.doc.Views.Redraw()
    
  3. Run the python script

ghpythonlib (both components and parallel) modules are available in the standard python editor in Rhino. Behind the scenes things are running through Grasshopper code, but you don’t have to use a canvas to do your work.

This also lets you work in a slightly different way where you can get points in Rhino using rhinoscriptsyntax “get input” type functions and pass those points (or curves or breps) into the Grasshopper component code.

editpythonscript_sample

9 Comments

Leave a Comment
  1. issworld / Dec 12 2013 8:15 pm

    Great work Steve.
    This is probably the best Christmas present.

    One question: when combining the rhinoscriptsyntax functions and these new grasshopper component ones: passing guids is not possible, right?
    For example using rs.GetObjects() instead of rs.GetPoints would not work?
    These new grasshopper component functions require either object type data (Point3d, Polyline…) or data in the form of lists/tuples (point = [2,0,6])?

    • stevebaer / Dec 12 2013 8:29 pm

      That is correct. The component functions would not know how to deal with guids. In those cases you would need to use the “coerce” functions in rhinoscriptsyntax (coercecurve, coercebrep, …) to get the geometry from the guids and then pass those on to the component functions.

  2. issworld / Dec 13 2013 11:06 am

    Steve, I noticed that “scriptcontext.doc.Objects.” and after that “scriptcontext.doc.Views.Redraw()” is always called behind each rhinoscriptsyntax function which creates geometry. Seems that way geometry is added to Rhino.
    What about baking geometry from Grasshopper? We do not need “scriptcontext.doc.Objects.” for that?
    Is there some documentation explaining this?

    • stevebaer / Dec 13 2013 6:37 pm

      I’m not sure I completely understand your question. It would probably be easier to discuss this at http://discourse.mcneel.com where I can bring other people into the discussion who may be more helpful.

  3. Arash / Dec 21 2014 8:25 am

    hello steve ,
    i have a problem …
    ghpythonlib does load in grasshopper but it doesnt load in editpythonscript in rhino , whats shoukld i do !?

    • MaxMarschall / Sep 6 2015 11:42 am

      Hey Arash,
      In case you couldn’t solve the problem: Are you sure ghpythonlib didn’t load? I thought the same thing because I got no auto-complete while writing the import statement, but after typing it in anyway the function calls worked.

  4. Sachin / Dec 20 2015 1:16 pm

    Hi, Can we use the usual python XLSX libraries for taking points and automate the process of multiple curve generation?

  5. Sachin / Dec 20 2015 2:12 pm

    Hi ,can we use the XLSX libraries of python to take points and parameters directly from the excel sheet to automate the generation of multiple curves?

    • stevebaer / Dec 20 2015 6:42 pm

      I haven’t tried this myself, but that library looks like it may work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: