I'm writing an application which will display a nice looking 3D model of a building. The building will have some areas which will change their color depending on some data points provided by the application.

The application will invoke blender's command line rendering feature to generate a PNG out of the .blend file, which then can be displayed in the UI.

The point where I'm stuck is how to change some material colors in the .blend file.

All hints are appreciated.

  • $\begingroup$ Welcome to the site :) What do you mean by changing colors? $\endgroup$ – p2or Mar 11 '16 at 11:14
  • $\begingroup$ Thank you :). Imagine rendering a room of the building red or green, so the material's color (or some lamp's color) must therefore be changed. $\endgroup$ – thomai Mar 11 '16 at 11:28
  • $\begingroup$ That could be too broad for this site. Material or lamp color? Might be a good idea to split up the question. What render engine are you using? Cycles or Internal? $\endgroup$ – p2or Mar 11 '16 at 11:37
  • 1
    $\begingroup$ Changing the color depends on the engine... Anyway, you can run a given python script file via -P option, see the manual $\endgroup$ – p2or Mar 11 '16 at 11:55
  • 1
    $\begingroup$ related: blender.stackexchange.com/questions/1101/… $\endgroup$ – p2or Mar 11 '16 at 12:24

The following command line will do the job (-P will run the given python script before rendering):

blender -b OG1.blend  -P ChangeColor.py -o Render.png -f 0


import bpy

bpy.data.materials["NameOfMaterial"].diffuse_color = (0, 1.0, 0)

The value ranges for the color channels are [0 to 1.0].

Thank you for your help, poor! Blender ist just too awesome! <3


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.