Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module main;
- import std.stdio;
- import std.file;
- import std.path;
- import std.range : array,take,chunks;
- import std.algorithm : find, canFind, map, joiner;
- import std.format : format;
- import std.conv : to;
- import std.process : executeShell;
- import std.string : replace;
- import std.algorithm : filter;
- enum export_version = "2016";
- enum import_version = "2016";
- enum installer_path = "E:\\Max Resources\\001 Max Plugins\\000 Octane\\Max\\";
- enum successlist_file = ".\\success_list.txt";
- enum faillist_file = ".\\fail_list.txt";
- void main(string[] args)
- {
- string export_exe;
- string import_exe;
- version (linux) string autodesk_path = "/media/Windows7/Program Files/Autodesk/";
- else version (Windows) string autodesk_path = "C:\\Program Files\\Autodesk\\";
- else assert(0,"unsupported platform");
- auto max_executables = dirEntries(autodesk_path,"*3dsmax.exe",SpanMode.depth);
- foreach (exe; max_executables)
- {
- writeln(exe);
- if (exe.name.canFind(import_version)) import_exe = exe.name;
- if (exe.name.canFind(export_version)) export_exe = exe.name;
- }
- if (import_exe == "" || export_exe == "")
- {
- max_executables = dirEntries("D:\\Program Files\\Autodesk\\","*3dsmax.exe",SpanMode.depth);
- foreach (exe; max_executables)
- {
- writeln(exe);
- if (exe.name.canFind(import_version)) import_exe = exe.name;
- if (exe.name.canFind(export_version)) export_exe = exe.name;
- }
- }
- assert(import_exe != "" && export_exe != "","Couldn't find the max versions we are using on this system\n");
- version(linux)
- {
- auto import_script = "/media/danni/network/resources/Temp/danni/OctaneImporter/importer_c.ms";
- auto export_script = "/media/danni/network/resources/Temp/danni/OctaneImporter/exporter.ms";
- auto filedir = "/media/danni/network/resources/Temp/danni/maxfiles/";
- }
- else version(Windows)
- {
- // auto import_script = "E:\\Temp\\Danni\\OctaneImporter\\importer.ms";
- auto import_script = "E:\\Temp\\Danni\\OctaneImporter\\importer_c.ms";
- auto export_script = "E:\\Temp\\Danni\\OctaneImporter\\exporter.ms";
- auto filedir = ".";
- }
- else assert(0);
- if (export_version == import_version)
- {
- auto installer_script = installer_path ~ "OctaneRender for 3ds Max 2.23.2 - 1.9.exe";
- executeShell(installer_script);
- }
- writeln("\n starting on export step\n");
- auto max_files = dirEntries(filedir,"*.max",SpanMode.depth).
- map!(a => a.name).
- filter!(a =>
- !a.canFind("Octane2.") &&
- !a.canFind("\\ssd\\") &&
- !a.canFind("\\ssed\\") &&
- !a.canFind("\\quaratined\\") &&
- !a.canFind("\\octane1\\") &&
- !a.replace(".max",".txt").exists()).map!(a => a.replace("\\","\\\\")).array;
- // writeln(filedir.dirEntries("*.max",SpanMode.depth).map!(a => a.name).filter!(a => !a.canFind("Octane2.") && !a.canFind("\\ssd\\")) );
- enum chunk_size = 8;
- writefln("exporting %d files",max_files.length);
- if (max_files.length > 0)
- {
- int o = 1;
- foreach (chunk; max_files.chunks(chunk_size))
- {
- writeln("exporting chunk ", o.to!string, " of ", (max_files.length/chunk_size).to!string);
- o++;
- auto tmp_script = "tmp_exporter.ms";
- std.file.write(
- tmp_script,
- format(
- "include \"%s\"\r\nai3d_octane_convert_export_files = #(%s)\r\nfor export_file in ai3d_octane_convert_export_files do export_material_file export_file\r\nquitMax() #noprompt\r\n",
- export_script, chunk.map!(a => "\"" ~ a ~ "\"").joiner(",").to!string()
- )
- );
- auto export_cmd = format("\"%s\" -mip -silent -U MAXScript \"%s\" ",export_exe, tmp_script);
- writeln(export_cmd);
- executeShell(export_cmd);
- }
- }
- if (export_version == import_version)
- {
- auto installer_script = installer_path ~ "NEW ERA Testing Only\\OctaneRender_for_3ds_Max_2.25_-_2.23.exe";
- executeShell(installer_script);
- }
- if (!successlist_file.exists) std.file.write(successlist_file,"");
- if (!faillist_file.exists) std.file.write(faillist_file,"");
- writeln("\n done exporting work; lets import...\n");
- max_files = dirEntries(filedir,"*.max",SpanMode.depth).
- map!(a => a.name).
- filter!(a =>
- !a.canFind("Octane2.") && // DON'T use old octane converter attempts
- !a.canFind("\\ssd\\") && // or files in superseeded folders
- !a.canFind("\\ssed\\") &&
- !a.canFind("\\octane1\\") && // or files that have already been converted
- !a.canFind("\\quarantined\\") && // or files that failed to convert
- a.replace(".max",".txt").exists && // MAKE SURE that a material text file has been generated
- std.file.read(a.replace(".max",".txt"),8) != "END_FILE" && // that isn't essentially an empty file
- !(a.dirName~"\\\\octane1\\\\"~a.baseName).exists && // and that the file hasn't already been converted
- !a.replace(".max","_Octane2.max"
- ).exists).map!(a => a.replace("\\","\\\\")).array;
- // writeln (max_files);
- // check for files that have an exported material txt file but not an imported and saved max file
- int i=1;
- foreach (max_file; max_files)
- {
- writeln("\nimporting ", max_file, " ( ", i.to!string, " of ", max_files.length.to!string , " )\n");
- i++;
- // writeln("old should be %s", (max_file.dirName~"\\\\ssd\\\\"~max_file.baseName));
- auto tmp_script = "tmp_importer.ms";
- std.file.write
- (
- tmp_script,
- format("include \"%s\"\r\nimport_material_file \"%s\"\r\nquitMax() #noprompt\r\n", import_script, max_file)
- );
- string import_cmd = format("\"%s\" -mip -silent -U MAXScript \"%s\"", import_exe, tmp_script);
- //writeln(import_cmd);
- executeShell(import_cmd);
- auto backup_dir = max_file.dirName() ~ "\\octane1\\";
- mkdirRecurse(backup_dir);
- string result_file = max_file.replace(".max","_Octane2.max").replace("\\\\","\\");
- if (result_file.exists && result_file.isFile)
- {
- writefln(result_file);
- max_file.rename (backup_dir~max_file.baseName);
- max_file.replace(".max","_Octane2.max").rename(max_file);
- auto ff = max_file.replace(".\\\\","").replace("\\\\","\\").asAbsolutePath();
- std.file.append(successlist_file,format("%s\n",ff));
- }
- else
- {
- auto badfiledir = max_file.dirName() ~ "\\quarantined\\";
- mkdirRecurse(badfiledir);
- auto badfile =badfiledir~max_file.baseName();
- max_file.rename(badfile);
- max_file.replace(".max",".txt").rename(badfile.replace(".max",".txt"));
- // max_file.replace(".max",".log").rename(badfile.replace(".max",".log"));
- auto ff = badfile.replace(".\\\\","").replace("\\\\","\\").asAbsolutePath();
- std.file.append(faillist_file,format("%s\n",ff));
- }
- }
- writeln("\ndone\n");
- // Lets the user press <Return> before program returns
- stdin.readln();
- }
Add Comment
Please, Sign In to add comment