@Goodriver wrote:
I am using rhinocommon under Rhino 5, and I’m trying to create a new material, apply it to a layer and export the material to a rmtl file. I can do the first two, but when exporting with Rendersavematerialtofile as rmtl file it gives an error (“Invalid Instance”)
// Create material int index = Rhino.RhinoDoc.ActiveDoc.Materials.Add(); Rhino.DocObjects.Material mat = doc.Materials[index]; mat.DiffuseColor = System.Drawing.Color.Chocolate; mat.SpecularColor = System.Drawing.Color.CadetBlue; mat.Name = "myMaterial"; mat.CommitChanges(); // Assign to current layer Rhino.DocObjects.Layer layer = Rhino.RhinoDoc.ActiveDoc.Layers.CurrentLayer; layer.RenderMaterialIndex = index; doc.Layers.Modify(layer, layer.LayerIndex, true); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); // Export to rmtl Rhino.RhinoApp.RunScript("Rendersavematerialtofile \"myMaterial\" C:\\temp\\myMaterial.rmtl", true);
If I then try layer.RenderMaterial it says “Object reference not set to an instance of an object”, even if I have assigned a material to the layer. There is no method layer.Material…
If I create the material manually, then the command does work, but I would like to do it programatically with rhinocommon.
I wonder if it has to do with different material types in Rhino. I can see two different ones in the documentation:
Rhino.DocObjects.Material andn Rhino.Render.RenderMaterial. The colour for the first type I can modify, but for the second it seems not possible.Thanks
Posts: 3
Participants: 2