# Python Script bakes itself automatically!

**URL:** <https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496>\
**Category:** Scripting\
**Tags:** python, grasshopperrhino\
**Created:** [April 28, 2019, 8:06am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496 "2019-04-28T08:06:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![milad.rogha](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/milad.rogha/32/151776_2.png) [@milad.rogha](https://discourse.mcneel.com/u/milad.rogha)\
**Post date:** [April 28, 2019, 8:06am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/1 "2019-04-28T08:06:17Z")

</div>

Hi all,  
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,

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [April 28, 2019, 8:08am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/2 "2019-04-28T08:08:30Z")

</div>

> [@milad.rogha](#):
>
> I wrote a piece of code

What did you write?

---

<div class="post-metadata">

**Author:** ![milad.rogha](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/milad.rogha/32/151776_2.png) [@milad.rogha](https://discourse.mcneel.com/u/milad.rogha)\
**Post date:** [April 28, 2019, 8:16am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/4 "2019-04-28T08:16:36Z")

</div>

@AndersDeleuran,  
I attached the code. Let me know if you have any questions.

Thanks! [NYC\_Giraffe\_v0425.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/a/7/a70f0e7dce4eb2328c2b2f6d260bc628492b9c44.gh) (501.4 KB)

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [April 28, 2019, 8:20am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/5 "2019-04-28T08:20:43Z")

</div>

When you set `scriptcontext.doc` to target `Rhino.RhinoDoc.ActiveDoc`, calling `rhinoscriptsyntax` functions that generate objects will also add these to the Rhino document (i.e. “baking” it). Here’s once instance of this:

 ![2019-04-28%2010_16_34-Grasshopper%20Python%20Script%20Editor](https://global.discourse-cdn.com/mcneel/original/3X/0/4/0486c72ae62821f04db09991f16c9d6f7034ff62.png)

---

<div class="post-metadata">

**Author:** ![milad.rogha](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/milad.rogha/32/151776_2.png) [@milad.rogha](https://discourse.mcneel.com/u/milad.rogha)\
**Post date:** [April 28, 2019, 8:24am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/6 "2019-04-28T08:24:12Z")

</div>

Thanks for the fast response!  
And would getting rid of those functions help the general speed of the script?

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [April 28, 2019, 8:32am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/7 "2019-04-28T08:32:07Z")

</div>

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](https://www.grasshopper3d.com/forum/topics/ghpython-some-bottlenecks-bugs) in that topic, some more things that might speed things up for you as well.

---

<div class="post-metadata">

**Author:** ![milad.rogha](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/milad.rogha/32/151776_2.png) [@milad.rogha](https://discourse.mcneel.com/u/milad.rogha)\
**Post date:** [April 28, 2019, 8:41am UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/8 "2019-04-28T08:41:19Z")

</div>

@AndersDeleuran Thank you. Really appreciate it!

---

<div class="post-metadata">

**Author:** ![milad.rogha](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/milad.rogha/32/151776_2.png) [@milad.rogha](https://discourse.mcneel.com/u/milad.rogha)\
**Post date:** [April 28, 2019, 12:10pm UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/9 "2019-04-28T12:10:10Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [April 28, 2019, 12:42pm UTC](https://discourse.mcneel.com/t/python-script-bakes-itself-automatically/82496/10 "2019-04-28T12:42:48Z")

</div>

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](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Polyline.htm), which you would implement like so:

```python
import Rhino as rc

myPl = rc.Geometry.Polyline(listOfPoints)

```
