private void DoReadBlenderData() {
if( !File.Exists( blendFilePathTextBox.Text ) ) {
return;
}
Process p = new Process();
//p.StartInfo.WorkingDirectory = outFolderPath;
p.StartInfo.FileName = "blender";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = String.Format("-b \"{0}\" -P \"{1}\"",
blendFilePathTextBox.Text,
Path.Combine(ScriptsPath, "get_project_info.py")
);
try {
p.Start();
}
catch( Exception ex ) {
Trace.WriteLine( ex );
}
StringBuilder jsonInfo = new StringBuilder();
bool jsonStarted = false;
int curlyStack = 0;
while( !p.StandardOutput.EndOfStream ) {
string line = p.StandardOutput.ReadLine();
if( line.Contains( "{" ) ) {
jsonStarted = true;
curlyStack++;
}
if( jsonStarted ) {
if( !line.ToLower().Contains( "blender quit" ) && curlyStack > 0 ) {
jsonInfo.AppendLine( line );
}
if( line.Contains( "}" ) ) {
curlyStack--;
if( curlyStack == 0 ) {
jsonStarted = false;
}
}
}
}
BlenderData blendData = null;
if( jsonInfo.Length > 0 ) {
JavaScriptSerializer serializer = new JavaScriptSerializer();
blendData = serializer.Deserialize<BlenderData>( jsonInfo.ToString() );
}
if( blendData != null ) {
startFrameNumericUpDown.Value = blendData.StartFrame;
totalFrameCountNumericUpDown.Value = blendData.EndFrame;
outFolderPathTextBox.Text = outFolderPath = blendData.OutputDirectory;
//blendProjectName = blendData.ProjectName;
if( blendData.EndFrame < endFrameNumericUpDown.Value ) {
endFrameNumericUpDown.Value = blendData.EndFrame;
}
}
Trace.WriteLine( "Json data = " + jsonInfo.ToString() );
//Trace.WriteLine( String.Format( "CEW: {0}", p.StartInfo.Arguments ) );
}