OK, Miguel. Bear with me, since I don’t use Python (I’m mostly familiar with Rhinoscript and starting to get my feet wet using VB.NET). I ran your script as a starting point. I had to add “from scriptcontext import doc”. Otherwise, it gave me a message "global name ‘doc’ is not defined.
import System
import Rhino.ApplicationSettings.AppearanceSettings
import scriptcontext
from scriptcontext import doc
def Main():
color = System.Drawing.Color.CadetBlue
settings = Rhino.ApplicationSettings.AppearanceSettings
settings.ViewportBackgroundColor = color
doc.Views.Redraw()
# Execute it...
if( __name__ == "__main__" ):
Main()
Took me a bit to realize that my viewport display style needed to be set to use the document’s background color, but then it worked.
Using Meier’s UI samples, I constructed a very simple slider:
import random
import Rhino.ApplicationSettings.AppearanceSettings
import System
import scriptcontext
#
# Background Colors
# by Damon Sidel (based on Mark Meier's UI examples)
# http://mkmra2.blogspot.com/2012/12/creating-graphical-user-interfaces-with.html
#
def Main():
# Make the UI object
ui = AllControlExample()
# Show the dialog from the UI class
Rhino.UI.Dialogs.ShowSemiModal(ui.form)
# Define a starting color for the background
lightness = 127
# This is just a class to test all the UI controls
class AllControlExample():
def __init__(self):
# Make a new form (dialog)
self.form = Meier_UI_Utility.UIForm("Background Color")
# Accumulate controls for the form
self.addControls()
# Layout the controls on the form
self.form.layoutControls()
# Add each control to an accumulated list of controls
def addControls(self):
# The controls get added to the panel of the form
p = self.form.panel
p.addLabel("", "Brightness: ", None, False)
p.addTrackBar("trackBar1", 0, 255, 1, 2, 1, 5, 150, False, self.trackBar1_OnValueChange)
p.addLabel("", "Value: ", None, False)
p.addReadonlyText("readonlyTextbox", "5", 50, True)
# ====================== Delegates =====================
# Called when the text changes in the box (every keypress)
# Called when the value changes
def trackBar1_OnValueChange(self, sender, e):
try:
c = self.form.panel.Controls.Find("readonlyTextbox", True)[0]
c.Text = str(sender.Value)
color = System.Drawing.Color.FromArgb(c, c, c)
settings = Rhino.ApplicationSettings.AppearanceSettings
settings.ViewportBackgroundColor = color
scriptcontext.doc.Views.Redraw()
except:
pass
# Execute it...
if( __name__ == "__main__" ):
Main()
In the “def trackBar1_OnValueChange” I put your code. This time, nothing happens. I’m sure I’m botching this up on a fundamental level, but like I said, bear with me.