# Problem in baking via python code

**URL:** <https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707>\
**Category:** Grasshopper\
**Tags:** windows, ghpython\
**Created:** [September 13, 2022, 7:57am UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707 "2022-09-13T07:57:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user883](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/user883/32/676385_2.png) [@user883](https://discourse.mcneel.com/u/user883)\
**Post date:** [September 13, 2022, 7:57am UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707/1 "2022-09-13T07:57:09Z")

</div>

Hi ,

I am new to coding via python , and I am facing a problem that the node failed to bake the geometry , although no errors showing in the IDE window , any advise .

regards  
[python tutorials \_color cubes.gh](https://discourse.mcneel.com/uploads/short-url/ldSim2xQnN3te1QHkDTLWHA14LT.gh) (6.9 KB)

---

<div class="post-metadata">

**Author:** ![kev.r](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kev.r/32/771963_2.png) [@kev.r](https://discourse.mcneel.com/u/kev.r)\
**Post date:** [September 13, 2022, 1:19pm UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707/2 "2022-09-13T13:19:07Z")

</div>

Note lines 36 and 42 that I added to your code:

 ![bake](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/8/e/98ebef904016e04340485759524336681dfaf4c6.jpeg)  
You will also need to add the line _ **`import Rhino`** _ at the top of your code.

See tutorial here for further info:

> **[Custom GhPython Baking Component](https://developer.rhino3d.com/guides/rhinopython/ghpython-bake/)**
>
> Use GhPython to create custom baking components.

-Kevin

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [September 13, 2022, 2:07pm UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707/3 "2022-09-13T14:07:58Z")

</div>

This was done with Python:

> [@'Bake to Layer' component with 'M' (Material) input?](https://discourse.mcneel.com/t/bake-to-layer-component-with-m-material-input/94820/21):
>
> Updated. Now handles groups. Open source Python. [mMaterial\_bake\_to\_layer\_pieces\_2020Jan30a] [mMaterial\_2020Jan30a.gh](https://discourse.mcneel.com/uploads/short-url/tT3jO02lTlkRmRzBJCzuNxWz0f6.gh) (29.5 KB) [mMaterial\_bake\_to\_layer\_2020Jan30a.gh](https://discourse.mcneel.com/uploads/short-url/y7Oqz7ADCwfvRIuaZkxLio55ltj.gh) (39.5 KB) [STEP1\_mMaterial\_bake\_to\_layer\_2020Jan30a.gh](https://discourse.mcneel.com/uploads/short-url/rKXhgsDuiVzltPQk6yIx7qWm6T0.gh) (40.0 KB) [STEP2\_mMaterial\_bake\_to\_layer\_2020Jan30a.gh](https://discourse.mcneel.com/uploads/short-url/n6jyaPrIayEJ5Z3hSZOEQxUr1Sc.gh) (16.1 KB) NOTE: The ~5 second benchmark in this video is more than three times longer than the same operation takes when not running the video capture software…? What are blocks? Again, I’d rather not be distracted …

[http://www.islandcad.com/grasshopper/bake\_to\_layer/](http://www.islandcad.com/grasshopper/bake_to_layer/)

---

<div class="post-metadata">

**Author:** ![user883](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/user883/32/676385_2.png) [@user883](https://discourse.mcneel.com/u/user883)\
**Post date:** [September 13, 2022, 6:13pm UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707/4 "2022-09-13T18:13:37Z")

</div>

@kev.r

thanks your comment has worked .  
actually there is something strange , because I followed this code from tutorial , and he is doing it the same code I attached and even baking objects with colors , if you don’t mind can you have look at  
[Learn Python for Grasshopper - Full Course for Beginners - Free - YouTube](https://youtu.be/Ln-ByMyfDy8?t=3683) at (function and baking part ) .

thanks again for your help

---

<div class="post-metadata">

**Author:** ![kev.r](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kev.r/32/771963_2.png) [@kev.r](https://discourse.mcneel.com/u/kev.r)\
**Post date:** [September 13, 2022, 7:32pm UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707/5 "2022-09-13T19:32:48Z")

</div>

You have created geometry and attributes, but they are not associated with each other.

 ![bake](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/8/e/98ebef904016e04340485759524336681dfaf4c6.jpeg)

Change line 41 to:

```nohighlight
        sc.doc.Objects.AddBrep(brep, attr)

```

-Kevin

---

<div class="post-metadata">

**Author:** ![user883](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/user883/32/676385_2.png) [@user883](https://discourse.mcneel.com/u/user883)\
**Post date:** [September 14, 2022, 10:51am UTC](https://discourse.mcneel.com/t/problem-in-baking-via-python-code/147707/6 "2022-09-14T10:51:10Z")

</div>

got it , thanks
