I’m trying to add a new layer with a new material via the Rhinocommon code below, but it isn’t working. Anyone know what I might be missing?
Also, I’m hoping to make the material plastic, the same as in Rhino where you can change the type of the material to plastic.
Dim MyLayer = New Rhino.DocObjects.Layer
Dim index As Integer = doc.Materials.Add()
Dim mat As Rhino.DocObjects.Material = New Rhino.DocObjects.Material
mat.AmbientColor = System.Drawing.Color.Blue
Dim rm As Rhino.Render.RenderMaterial = Rhino.Render.RenderMaterial.CreateBasicMaterial(mat, doc)
MyLayer.RenderMaterialIndex = mat.Index
MyLayer.Name = "MyLayer"
Perhaps you can translate this to VB:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
var color = Color.BurlyWood;
// Create the layer
var layer = new Layer
Name = color.Name,
Color = color
// Add the layer to the document
var layerIndex = doc.Layers.Add(layer);
if (layerIndex < 0)
// Create a Rhino material
var rhino_material = new Material
Name = color.Name,
DiffuseColor = color
// Create a basic Render material from the Rhino material
var render_material = RenderMaterial.CreateBasicMaterial(rhino_material, doc);
// Add the basic Render material to the document
// Assign the render material to the layer
doc.Layers[layerIndex].RenderMaterial = render_material;
That worked, thanks.
In Rhino, I often switch the material type to plastic and use the bump texture leather at XXS. How would I go about achieving this or the equivalent in Rhinocommon?
Form this page I learnt how to set the material to plastic, thanks.
Next I was trying to implement the script on this page as a first step to getting the leather texture, but I run into a problem saying SimulatedTexture is not a member of RenderContent:
Basically, I’m trying to apply the standard leather with XXS scale as done in Rhino in below image. I’m thinking the leather texture file is somewhere in Rhino and I have to figure out where to access it. If there is a quick way to set this up, would really like to know:
RenderContent is the base class for
RenderTexture. The method
NewContentFromTypeId gives you a
RenderContent, so you have to cast to
I’ll check the other bits later, probably tomorrow, it is getting soon bed time (:
I recorded a short video on how to find what you can change in Rhino materials. In short: save out the material to file, open it to inspect. Take note of the parameters you are interested in and then use RenderContent.SetParameter Method (String, Object) on your material instance, properly bracketed by RenderContent.BeginChange Method and RenderContent.EndChange Method
I hope this helps.
Thanks Nathan! A video is worth a thousand pictures, really learnt some problem solving skills from your approach. And of course got my answer to this question too. Enjoyed the beats too and that is one funky keyboard you are using
I’m glad the video was useful. Keep asking questions, because that is how we know where people want or need to learn!
Showing my own approach is the reason why I started doing my Rhino live coding streams. Naturally it is not the only way, but one that helps me a lot. I also found that having calm musical background also helps watching this type of videos and streams.
And naturally I love my keyboard, that is why I have posted about it in Meta and the Gallery (: