I’m attempting to write my first python script. I have used Blender and others’ scripts for years, but never made my own. I did Visual Basic, and that was 12 years ago in high school.
So, why I want a script: I’ve gotten tired of changing all the viewport color settings to the Surface color settings when using Cycles and decided this would be a good chance to go to town on my first script to do it automatically for all selected objects. Seemed reasonably straight forward enough.
But I’ve run into this problem: I can’t figure out how to call all the materials of my selected objects. This is what I have gotten to, I know, it’s not much yet.
import bpy
for myobjects in bpy.context.selected_objects:
print (myobjects)
So far, that’s simple and it works. It lists the objects I have selected in the viewport.
Now I want to take all the materials for all the selected objects and make their viewport color equal their surface color. Well, there are properties for both of those, but I can’t figure out how to call them up.
selected_objects doesn’t have a function to call up all the materials that are associated with those models, that I can find. Can anyone give me a pointer on this?
What I’m trying to do as a work around is working either.
I tried to set up the script to run on all the materials in a scene, but I now cannot figure out how to access the color of the node diffuse shader from within python.
When I hover over the color swatch it gives me a NodeSocketRGBA.default_value property, that I cannot figure out how to reference.
Also, I would like to understand how to call up all the materials of my selected objects for future reference. Thanks for any help you can give.
-Matt