algorithmic modeling for Rhino


Does anyone have any quick example of baking in GH via a component, but one which is not in legacy format but in the current SDK?

I am having great difficulty to find the relating commands in the new SDK, when I try to use a legacy-format example (there are some nice ones in the forum!) as a reference!

Any help?


Views: 715

Reply to This

Replies to This Discussion

What I actually need is to bake certain objects in certain layers.... and adjust layer colors.
Hello Daniel,

In C# it works like this for meshes - it's similar for other objects:

Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh((Rhino.Geometry.Mesh)obj, att);

att is an Object Attribute, use it like this:

Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
att.LayerIndex = layerlist[i];

Of course you don't have to use a list for the layers, if you just have one object. Just note that this is C# code, but you should be able to translate it into
You can adjust the layer colors before baking the objects, layer 0 is the top layer etc.

This code definitely works as part of a custom GH component, so I guess that it also works within a scripting component!


Thank you Johannes!

I managed to get what I wanted... it might not be the most efficient code ever, but it works like a charm.

Quick explanation: we are working on facades of skyscrapers, and we had a hole facade with thousands of facade panels, separated by width. In GH we were visualizing it via the Custom Preview component, but we wanted to bake it with the respective colors, and each color, or panel width, being in its own layer....

Private Sub RunScript(ByVal bake As Boolean, ByVal surfaces As List(Of Surface), ByVal lColor As List(Of Color), ByVal lengths As List(Of Double), ByRef A As Object)

If Not bake Then Return

Dim i As Integer
For i = 0 To surfaces.Count - 1
Dim s As Surface = surfaces(i)
Dim c As Color = lColor(i)
Dim l As Double = lengths(i)
Dim layerName As String = "panel_" & CStr(l)
Call CreateLayer(layerName, c)
End Sub

Sub CreateLayer (ByVal L As String, ByVal C As Color)

'decalere a variable to hold current layer index
Dim current_layer_i As Integer
current_layer_i = doc.Layers.CurrentLayerIndex()

'check if input layer already exist, otherwise create new layer
Dim layer_i As Integer
layer_i = doc.Layers.Find(L, 1)

'Create new layer
If layer_i = -1 Then

layer_i = doc.Layers.Add(L, C)

End If

'Set current layer to the new layer index
doc.Layers.SetCurrentLayerIndex(layer_i, 0)

End Sub
I noticed it is not possible to undo the baking done via

Any known workarounds for that?
The easiest way is probably to use regular Rhino commands for deleting items, like that:

Rhino.RhinoApp.RunScript("delete", true);

You have to select the items first, e.g. via "selall" instead of delete.

... and I didn't try that one out, but you could put each item into a seperate layer and then select that layer via "SelLayerNumber" followed by "delete" - just a random thought!







  • Add Photos
  • View All

© 2018   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service