So here's an example for a simple console application in c#
I used VS2013; I seem to have problems with 2017 but I didn't really try to figure out why it had issues, and I used pip to get the latest python.net dll
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Python.Runtime;
using System.Threading;
namespace cslux
{
public class Program
{
static dynamic session;
static float renTime;
static decimal renTr;
static dynamic pyluxcore;
static dynamic sceneProps;
static dynamic configProps;
static dynamic scene;
static dynamic config;
public static void Main(string[] args)
{
using (Py.GIL())
{
pyluxcore = Py.Import("pyluxcore");
pyluxcore.Init();
Console.WriteLine(pyluxcore.Version());
sceneProps = pyluxcore.Properties();
configProps = pyluxcore.Properties(@"scenes\cornell\cornell.cfg");
scene = pyluxcore.Scene(configProps.Get("scene.file").GetString());
sceneProps = scene.ToProperties();
dynamic cameraPos = sceneProps.Get("scene.camera.lookat.orig").GetFloats();
configProps.SetFromString("film.outputs.0.filename = image.png");
config = pyluxcore.RenderConfig(configProps, scene);
Console.WriteLine(cameraPos);
session = pyluxcore.RenderSession(config);
Console.WriteLine(@"
#############################################################
# Press r to render.
#############################################################");
ConsoleKeyInfo chinput = Console.ReadKey();
switch (chinput.Key)
{
case ConsoleKey.R:
session.Start();
while (!session.HasDone())
{
session.UpdateStats();
var stats = session.GetStats();
renTime = stats.Get("stats.renderengine.time").GetFloat();
renTr = Convert.ToDecimal(renTime);
renTr = Math.Round(renTr, 3);
Console.WriteLine("render time = {0}", renTr);
Thread.Sleep(100);
}
session.Stop();
session.GetFilm().Save();
Console.WriteLine("saved");
break;
default:
Console.WriteLine("Unknown Command.");
break;
}
}
}
}
}