I made a script that sucessfully bakes Breps, but when I try using the same script to bake Block instances (geometry) it fails. Why does it fail, and what code to use to properly “bake” Block instances?
This code fails for blocks but works fine for Breps :
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
# Set Name and Bake GH objects.
if active:
if G:
i = StartIx
for obj in G:
# Script context = Grasshopper
sc.doc = ghdoc
# Get the geometry info for later baking
dobj = rs.coercerhinoobject(obj)
geom = dobj.Geometry
attribs = dobj.Attributes
# Script context = RhinoCAD
sc.doc = Rhino.RhinoDoc.ActiveDoc
# "BAKE" (sort of)
new_ref = sc.doc.Objects.Add(geom, attribs)
# NAME
new_name = BaseName + "_" + str(i)
rs.ObjectName(new_ref, new_name)
i += 1
# LAYER
rs.ObjectLayer(new_ref, LayerName)
out = G
I found out that the Block components came from the Elefront plugin (just typing F4 + “Blocks” doesn’t tell which plugin a component belongs to, so…), any way, I also learned that Elefront has a dedicated component for baking Blocks.
So, the problem seems to be solved, see the following thread in which I had some other questions related to Blocks, which I think will be answered in an example I was directed to. GH/Elefront: Block variant difference? - #7 by fraguada
You can use the 'Ctrl+Alt+Click' combo to see where a component is placed on the toolbar, and then right-click on it and choose "Component Info" to see the plug-in