Bake GH Components via Python


1500 Nodes per iteration

The other day I needed to translate some GH dimensions to native rhino dimensions. Not only that , but it was a sequence of steps in a parametric model, which means that I had to repeat the same process for about a 1000 times. Obviously the old-fashioned right click wasn’t working for me,

Although, I already have some routines that can bake geometry directly to rhino (and export it) , the Dimension and Preview components of Grasshopper3d don’t have any geometry output. Nonetheless, i needed the leader(or marker ) tag utility.

I wrote this small snippet to bake, not only dimensions, but any component type and with a specific name , to a specific layer, without much hustling. I just put it out there for people to use, however I have to warn you that it was written in a couple of minutes, so its almost certain that it will contain many bugs.

Please let me know if you experience one, or if you have a possible suggestion or fix.

Enjoy a usual at the [Sub]Code Page. Python labeled defs.

import Grasshopper as gh
import Rhino as rc
import ghpythonlib.components as comp
from System import *
from System.Collections.Generic import *

#Active Rhinodoc
rcdoc = rc.RhinoDoc.ActiveDoc
#Active GH document
my_ghdoc = ghenv.Component.OnPingDocument()
attr =rc.DocObjects.ObjectAttributes()

# Bake the dimensions in the specified layer called Dimensions
#if it doesn't exist it used the default
attr.LayerIndex = rcdoc.Layers.Find(L,True)

# Iterate the active objects in the current GH file and find the one of the specific type
#if there are many look for the one with the name
objs = []
obj_types =[]
for obj in my_ghdoc.ActiveObjects():
 my_type = obj.GetType()
 #uncomment the next line if you want to see all the component types in the document
 if str(my_type) == Comp_type :
 if Comp_name == None:
 print("found it")
 if obj.NickName == Comp_name:
 print("found it")
 #bake the component
 if Bake == True:
 for obj in objs:
 #create an empty GUID list
 ids = List[Guid]()
 print("baked the dimension elements")

doc_components = obj_types

2 thoughts on “Bake GH Components via Python

  1. Dear Marios,

    I found your python script for dimensions baking but i get an error Msg. I am not good in programming. So maybe you can support me a bit to find out what’s wrong.

    the Error msg
    1. Solution exception:name ‘Guid’ is not defined

    found it
    Runtime error (UnboundNameException): name ‘Guid’ is not defined
    line 37, in script

    Think you as professional programmer can solve this muuuuuuch faster as me as dummy user


    • Hi Georg,

      Did you import System.Collections?

      It seems that you are missing the Guid Object

      Let me know if this solved the problem.

      I have a working definition in the downloads page

      Kind regards

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s