Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Add this script to a "Batch Script" editor (F10) and execute it with Script > Run.

The script will add random or uniform colors to a selection of objects:

import random
 
colourModes = ["Random colours","Uniform colour"]
guiForm     = GUIFormDialog.new()
 
guiForm.addListField("Colour mode", colourModes, 0)
guiForm.addIntField("Red (0-255)", 255)
guiForm.addIntField("Green (0-255)", 255)
guiForm.addIntField("Blue (0-255)", 255)
guiForm.addBoolField("Activate RBD mode", False)
 
if (guiForm.show() == GUI_DIALOG_ACCEPTED):
	mode          = guiForm.getFieldValue("Colour mode")
	rbdActivation = guiForm.getFieldValue("Activate RBD mode")
	nodeSelection = scene.getSelectedNodes()
 
	for entry in nodeSelection:
		if (mode == 0):
			red   = random.randint(0, 255)
			green = random.randint(0, 255)
			blue  = random.randint(0, 255)
 
		if (mode == 1):
			red   = guiForm.getFieldValue("Red (0-255)")
			green = guiForm.getFieldValue("Green (0-255)")
			blue  = guiForm.getFieldValue("Blue (0-255)")

		colour = Vector.new(red, green, blue)
		entry.setParameter("Color", colour)
 
		if (rbdActivation == True):
			entry.setParameter("Dynamics","Active rigid body")
else: scene.message(str("Script cancelled by user"))
  • No labels