I'm just trying to get a script to do anything at this point.
Why doesn't this work? It compiles but nothing happens when I build and run.
using System;
namespace Vixen.User {
public partial class Test_3 {
protected override void Startup() {
// Initialization goes here.
}
protected override void Play() {
// Code starts here.
Notify("Starting Sequence");
//Set_Level({ElementName},{Length of Effect},{Intensity},{Color});
Set_Level(Nodes, TimeSpan.FromSeconds(10), .75, System.Drawing.Color.Blue);
}
protected override void Shutdown() {
// Tear-down of initialization goes here.
}
}
}
Thanks for the help!
Try moving the Set_Level command to the Startup. In Startup you are building the sequence with the effect commands. Play then executes it.
Jeff
Let me give you another code snippet if you plan to do anything meaningful. The default code just inserts the effect at the time of zero. But if you want to build a sequence with effects at varying times this will get you going in the right direction.
using System;
using System.Collections.Generic;
using Vixen.Module.Script;
using Vixen.Sys;
using Vixen.Module.Effect;
using System.Linq;
namespace Vixen.User {
public partial class TestCode {
protected override void Startup() {
// Initialization goes here.
Sequence.Length=TimeSpan.FromSeconds(25);
//Tree_Node is the name of a specific element in my setup, effect duration, effect start time, Level, Color
Set_Level(Tree_Node, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(5), 1, System.Drawing.Color.Blue);
Set_Level(Tree_Node, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(15), 1, System.Drawing.Color.Red);
Notify("Set Level inserted");
}
protected override void Play() {
// Code starts here.
Notify("Starting Sequence: " + Sequence.Length);
}
protected override void Shutdown() {
// Tear-down of initialization goes here.
Notify("Starting Teardown");
}
// Original name: Set Level
public void Set_Level(IEnumerable<UserScriptNode> targetNodes, TimeSpan timeSpan, TimeSpan startTime, System.Double Level, System.Drawing.Color Color) {
_InvokeEffect("Set_Level", targetNodes, timeSpan, startTime, Level, Color);
}
private void _InvokeEffect(string effectName, IEnumerable<UserScriptNode> targetNodes, TimeSpan timeSpan, TimeSpan startTime, params object[] args) {
Execute(CreateEffectNode(effectName, targetNodes, timeSpan, startTime, args));
}
public EffectNode CreateEffectNode(string effectName, IEnumerable<UserScriptNode> targetNodes, TimeSpan timeSpan, TimeSpan startTime, params object[] args) {
Guid effectId;
if(_effects.TryGetValue(effectName, out effectId)) {
IEffectModuleInstance effect = Vixen.Services.ApplicationServices.Get<IEffectModuleInstance>(effectId);
effect.TimeSpan = timeSpan;
effect.TargetNodes = targetNodes.Select(x => x.Node).ToArray();
effect.ParameterValues = args;
return new EffectNode(effect, startTime);
}
return null;
}
}
}
Jeff
Thanks. I've managed to get my simple example working.
Can you give me any advice on how to only have something turn on for certain times of the day?
I would assume I would use a while loop, but for some reason whenever I use a while loop, Vixen crashes.
Why exactly would something like this not work?
using System;
namespace Vixen.User {
public partial class Red_100_ {
protected override void Startup() {
// Initialization goes here.
DateTime now = DateTime.Now;
DateTime start = new DateTime(now.Year, now.Month, now.Day, 17, 30, 00);
DateTime end = new DateTime(now.Year, now.Month, now.Day, 23, 00, 00);
while (now.CompareTo(start) >= 0 && now.CompareTo(end) <= 0){
Set_Level(Nodes, TimeSpan.FromSeconds(600), 1, System.Drawing.Color.Red);
}
}
protected override void Play() {
// Code starts here.
Notify("Starting Sequence");}
protected override void Shutdown() {
// Tear-down of initialization goes here.
}
}
}
Thanks!
I figured out a way, but I'm sure there is a better way to do it. This will get my display to play until midnight.
using System;
namespace Vixen.User {
public partial class Red_100_ {
protected override void Startup() {
// Initialization goes here.
DateTime now = DateTime.Now;
DateTime end = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
int x = (end.Hour-now.Hour)*3600+(end.Minute-now.Minute)*60+(end.Second-now.Second);
Set_Level(Nodes, TimeSpan.FromSeconds(x), 1, System.Drawing.Color.Red);
}
protected override void Play() {
// Code starts here.
Notify("Starting Sequence");}
protected override void Shutdown() {
// Tear-down of initialization goes here.
}
}
}
You should use the scheduler to manage start times. The script should just build what it should do. In your first example you need the while loop to end so the sequence can start. It has to exit the StartUp method.
The second example determines length based on start and a predetermined end so that is reasonable.
Other than just playing with the scripting you could easily do what yo are after with a simple timed sequence that repeats in the scheduler between two times.
Jeff
I just did my Christmas tree this year as a feeler gauge.
For an indoor tree in our living room, the scheduler doesn't work very well. If I used the scheduler, songs would be coming on when we are trying to watch a movie, ect. I like to use my phone to access the web server, and just run sequences that way. If my kids want to listen to a song, it only takes a second to get going.
What format instead of System.Drawing.Color.Red do I use to make custom colors?
Thanks!
You can create any color from RGB.
http://msdn.microsoft.com/en-us/library/cce5h557(v=vs.110).aspx
Jeff
Thanks for the help!
One last question for now.
How do I work with color gradients?
For the example:
Twinkle(Nodes, TimeSpan.FromSeconds(10), true, 1, 100, 50, 120, 50, 50, VixenModules.Effect.Twinkle.TwinkleColorHandling.StaticColor, System.Drawing.Color.White, DefaultGradient, 50);
There is DefaultGradient that I have to set up somehow. I found this example:
VixenModules.App.ColorGradients.ColorGradient DefaultGradient
{
get
{
VixenModules.App.ColorGradients.ColorGradient defaultGradient = new VixenModules.App.ColorGradients.ColorGradient();
defaultGradient.IsCurrentLibraryGradient = false;
defaultGradient.Alphas.Add(new AlphaPoint(1, .5, 0));
defaultGradient.Alphas.Add(new AlphaPoint(1, .5, 1));
defaultGradient.Colors.Add(new ColorPoint(Color.White, 0));
defaultGradient.Gammacorrected = false;
return defaultGradient;
}
}
But I have no idea where this should go in the script. Can you help explain this for me?
Thanks!
