How can i get color by python

hi every

I use node to change my texture color by change Z position。
But i don’t know how to get my texture color。
I find some example from webside,he use diffuse_color。
But it’s not work。


You cannot get a color output of a shader in Python because the shader is used to render the image. Therefore you would have to render the image with python and then look at the image to get the color of a specific part (but this is then dependent on the surrounding light and objects).

In your case you can simply get the object location and do the multiplying and color ramping in python.

But what do you really want to do? This sounds like a XY-problem.

Thx Patrick

I went to make a real LED matrix,to show some light illusion。
So I need to get the color data from my cube materal。
And let the data become file,for my LED matrix。

Ohh, I understand.
So you basically want to create some procedural animated texture to use for your RGB-LED cube.

I think it would be easier to just create the procedural animation yourself on the cube with wathever language it is written, as doing this in Blender will be quite difficult.

But here is how I would do it:
1.) Don’t use the PrincipledBSDF Shader but use only an Emissive Shader.
2.) UV unwrap the cube
3.) For every frame create an image and set this image as the source in an active image texture node with python.
4.) Bake the emit-part of your material with pythom (by calling the corresponding bpy.ops)
5.) Go to the next frame qnd repeat from step 3.)

Blender baking:

PS: Click the reply button of my post so I get a notification if you have further questions.

Thx Patrick

It’s work!!

I use bake to get a uv texture image
then use bpy to get texture color

Thx again