How do I access the glTF Metallic roughness shader node with Python? I am currently working on a little script that takes a bunch of obj, imports them into blender with their textures, plugs the textures in the right places of the GLTF Metallic Roughness shader group, and then exports everything into GLTF.

I have arrived to the part where I have to add the GLTF Metallic Roughness Node. As those who use that plugin (https://github.com/KhronosGroup/glTF-Blender-Exporter) know, to access the node and plug your textures manually, you first have to link your blender scene to the GLTF2.blend scene, and especially to the pbr node tree and the Metallic Roughness group there.

I have tried a couple of things... First I tried this:

GLTF = matnodes.new(settings =[{"value" : "byp.data.node_groups['glTF Metallic Roughness']"}], type= "ShaderNodeGroup")


Yet Blender doesn't seem to like this and says that it expects only one argument for the function "matnodes.new()"...

So I have tried this:

GLTF = matnodes.new("ShaderNodeGroup")


There it spawns a gorup shader node, but it is empty and displaying ("Missing Data-Block"... On the menu dropdown, I have tried selecting "glTF Metallic Roughness", and it turns the node into the right node, but in the info console there's no command I can use... Basically I don't know how to do that in Python.

Does anyone have an idea :/?

I haven't put the entire code because I think the rest is kind of irrelevant but don't hesitate to ask if you want to see it.

Thank you all!
Find your node group:

group = bpy.data.node_groups.get('glTF Metallic Roughness')


Assign it to the node:

GLTF = matnodes.new("ShaderNodeGroup")
GLTF.node_tree = group