How to get RenderMaterial List?

Hi All:
I’ve created a lot of geometry and given them materials with code. I can see these materials in the material panel, but I can’t get the list of rendering materials from the render material table. How can I get as many as the list of rendering materials in the material panel? thank you.

private void RunScript(ref object A)
  A = RhinoDocument.RenderMaterials.Count;
} (3.2 KB)

Thank you for your reply. You can try this code, and then the RhinoDocument.RenderMaterials.Count is still zero.

  private void RunScript(ref object RenderMaterial_Count)
    int index = RhinoDocument.Materials.Add();
    Rhino.DocObjects.Material mat = doc.Materials[index];
    mat.Name = "材质";
    mat.DiffuseColor = System.Drawing.Color.Chocolate;
    mat.SpecularColor = System.Drawing.Color.CadetBlue;

    Rhino.Geometry.Sphere sp = new Rhino.Geometry.Sphere(Rhino.Geometry.Plane.WorldXY, 5);
    Rhino.DocObjects.ObjectAttributes attr = new Rhino.DocObjects.ObjectAttributes();
    attr.MaterialIndex = index;
    attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
    doc.Objects.AddSphere(sp, attr);


    RenderMaterial_Count = RhinoDocument.RenderMaterials.Count;