I am a bit new to Python! I wrote a piece of code using Python component in Gh. It works fine except for two things:
- First, it takes about 4 minutes to be processed!
- Second, it automatically bakes itself to the rhino document! I don’t have any part in my script regarding baking! Does anyone know what may be the problem?!
Thanks in advance,
I attached the code. Let me know if you have any questions.
Thanks!NYC_Giraffe_v0425.gh (501.4 KB)
When you set
scriptcontext.doc to target
rhinoscriptsyntax functions that generate objects will also add these to the Rhino document (i.e. “baking” it). Here’s once instance of this:
Thanks for the fast response!
And would getting rid of those functions help the general speed of the script?
Yes it would, adding stuff to the Rhino document can be costly. Especially if you do not disable redrawing during. Also, I’d recommend using
RhinoCommon directly (instead of
rhinoscriptsyntax) if speed is a concern. See this old thread in that topic, some more things that might speed things up for you as well.
@AndersDeleuran Thank you. Really appreciate it!
Is there a way I can avoid these .Add functions?
Basically, I want to add a polyline from a set of points. In RhinoScript the only function I can think of is rs.Addpolyline! I tried to use Gh library(specifically gh.components.PolyLine) The problem is that I can’t get a guid from its result. (Using rs.coerceguid returns None).
You can use them just fine in GHPython, just don’t change the
scriptcontext.doc away from the Grasshopper document (which GHPython targets by default).
That said, I personally prefer and recommend implementing
RhinoCommon directly for generating/manipulating geometry in GHPython (for many many reasons, try searching the forum, this has been covered ad nauseam). Here’s the polyline class, which you would implement like so:
import Rhino as rc
myPl = rc.Geometry.Polyline(listOfPoints)