Access to material notes

I’d like to retrieve notes from a material assigned to a layer.
myLayer.RenderMaterial always seems to give me null, even if a material is assigned in the Layers tab.
myLayer.RenderMaterialIndex gives me an index that I can use with RhinoDoc.ActiveDoc.Materials to retrieve a Material, but Materials do not have Notes, only RenderMaterials seem to have them.
The materials in the Materials tab do have notes, but I don’t know how to access them programatically.
Curiously enough, when I manually change a material in the Materials tab all properties update in the Layers tab except for the notes. If I access the material through the Layers tab Notes is always empty, and any changes I make to Notes there are not saved.
For the record I’m using Rhino 6.

by chance I recently happen to have made this quick script for a friend, to assign materials to layers based on strings stored in their notes:

import Rhino
doc = Rhino.RhinoDoc.ActiveDoc;
for layer in doc.Layers:
    layer.RenderMaterial = None # Start off by clearing any material.
    parts = layer.Name.Split(' ')
    if parts.Length > 0:
        for material in doc.RenderMaterials:
            if material.Notes and parts[-1] == material.Notes.Trim():
                print 'Assigning material %s to layer %s' % (material.Name, layer.Name)
                layer.RenderMaterial = material

so if you have a layer named “Layer 01” and a material with “01” in its notes, this will assign the material to the layer

trying to reproduce what you report in rhino 6 (6.35.21222):

  1. I started with a new document, using no template
  2. I added 3 layers with the default names “Layer 01”, “Layer 02”, and “Layer 03”
  3. I created and assigned a material for each, by clicking on the Material column for each layer in the Layers panel; in each case I chose “Use a new material” in the layer material dialog, and added the matching “01”, “02”, or “03” in the newly-created material’s notes

these notes show up as expected when the material is selected in the Materials panel, and the script works as intended, first clearing each layer’s material, and then assigning the desired material, according to its notes

to check that accessing Layer.RenderMaterial directly works, here is a slightly modified version, which first prints the state of each layer’s material and or/notes, and which also shows things apparently working as intended

import Rhino
doc = Rhino.RhinoDoc.ActiveDoc;
for layer in doc.Layers:
    if layer.RenderMaterial and layer.RenderMaterial.Notes:
        print 'Layer %s\'s material (%s) has notes: %s' % (layer.Name, layer.RenderMaterial.Name, layer.RenderMaterial.Notes.Trim())
    elif not layer.RenderMaterial:
        print 'Layer %s has no material' % layer.Name
    elif not layer.RenderMaterial.Notes:
        print 'Layer %s\'s material (%s) has no notes' % (layer.Name, layer.RenderMaterial.Name)
    layer.RenderMaterial = None # Start off by clearing any material.
    parts = layer.Name.Split(' ')
    if parts.Length > 0:
        for material in doc.RenderMaterials:
            if material.Notes and parts[-1] == material.Notes.Trim():
                print 'Assigning %s to %s' % (material.Name, layer.Name)
                layer.RenderMaterial = material

so, I’m not sure what you may be seeing there, but maybe this can help find where things are going wrong

Yes, your example does work! I guess the materials in my file were created in a different way because when I try to get the layer.RenderMaterial it returns nothing. I know there are Materials and RenderMaterials, although I do not quite understand the difference. Perhaps the materials in my model were created directly as Materials (which do not have Notes) without using a RenderMaterial (if that is possible)? That would make sense, you cannot get a RenderMaterial if you did not use one in the first place.

my best guess would be that the file is from a version older than v6 and that the materials have subtly different behavior, for whatever reason (mcneel may be able to say, if you gave them the file), and/or that there was some plugin involved in the history of these materials