I am searching for a way in Grasshopper to read out PBR material data like base color, roughness, metalness, ior, opacity (if possible also values like sheen and clearcoat and similar from the Rhino detailed PBM material settings) by a given GUID. Best would be a Python solution but an existing component that does it would be better than nothing.
I know from Human the component “Material Table” but this is very limited and also based on Specular/Glossiness instead of Metallic/Roughness - so unfortunately it does not help. But from the “basic idea” this is similar to what I would need:
Hi @nathanletwory thanks for pointing to your script. Unfortunately I could not get it to work. I took the raw file from Github and used it in GHPython (I use Rhino 7 SR14). When trying to run it I get an error message:
Runtime error (MissingMemberException): 'GrasshopperDocument' object has no attribute 'RenderMaterials' Traceback: line 7, in script
Where line 7 is: rms = list(sc.doc.RenderMaterials)
Not sure what I’m doing wrong. Maybe the context should be Rhino instead of GH? I dont’t know.
Ah, yes, I don’t know how much you can access from Python in GhPython. You’ll need access to the full Rhino document. But you should be able to do something similar in C# based on my script, essentially as what @maje90.
The example script is indeed for regular Rhino Python.
Thank you very much @maje90 for this - it works great and is (almost) exactly what I want (I would have preferred a GHPython script). Fortunately the c# script you provided can easily be modified (even with my very limited c# knowledge) to extract the parameters I need.
So thanks again - your answer (together with @nathanletwory suggestion to export .rmtl) is the solution.
Maybe this is of value? This can be done from a GHPython component. I’ll leave the xml parsing part to you, but this will get the gh xml file of the materials in the active Rhino doc. In this example, I only had one PBR material in the active document called “Fiber”.
import Rhino
import Grasshopper as GH
import ghpythonlib.treehelpers as th
DisplayMaterial = []
MaterialNames = []
for mat in Rhino.RhinoDoc.ActiveDoc.RenderMaterials:
DisplayMaterial.append([GH.Kernel.Types.GH_Material(mat.Xml)])
MaterialNames.append([mat.Name])
xmlOut = mat.Xml # this is the gh xml material file you would need to parse
DisplayMat = th.list_to_tree(DisplayMaterial)
MatNames = th.list_to_tree(MaterialNames)
Thanks for this info - it uses some interesting tricks I didn’t know before. So for me this is of value for sure.
Regarding the initial problem I have based my solution on the c# script provided by Riccoardo - with some modifications. It now does everything I need.