-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathProgram.cs
81 lines (70 loc) · 2.56 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.IO;
using Rhino.Runtime.InProcess;
using Rhino.Geometry;
using Rhino;
namespace Convert
{
class Program
{
#region Program static constructor
static Program()
{
RhinoInside.Resolver.Initialize();
}
#endregion
// Use STAThread for this app as we are starting Rhino in a mode that does actually
// include user interface (we just never show the main window). This allows for things
// like RhinoApp().RunScript to properly run.
[System.STAThread]
static void Main(string[] args)
{
Console.WriteLine("Please wait while Rhino is starting...");
try
{
using (new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Hidden ))
{
Console.WriteLine("Enter path to directory which contains files to convert and press ENTER:");
string path = Console.ReadLine();
string[] filePaths = Directory.GetFiles(path, "*.3dm");
if (filePaths == null || filePaths.Length == 0)
{
Console.WriteLine("Directory is empty. No files to process. Press any key to exit.");
Console.ReadKey();
return;
}
foreach (string file in filePaths)
{
var doc = RhinoDoc.Open(file, out bool wasOpen);
Console.WriteLine("Nº of objects in file: {0}", doc.Objects.Count);
// View capture to .png file
var pngPath = Path.ChangeExtension(file, ".png");
var imgScript = string.Format("_-ViewCaptureToFile \"{0}\" _Enter", pngPath);
RhinoApp.RunScript(imgScript, false);
// Save the .obj file
var fowo = new Rhino.FileIO.FileObjWriteOptions(new Rhino.FileIO.FileWriteOptions { SuppressAllInput = true })
{
ExportMaterialDefinitions = false,
MapZtoY = true,
MeshParameters = MeshingParameters.Default,
};
var objPath = Path.ChangeExtension(file, ".obj");
var result = Rhino.FileIO.FileObj.Write(objPath, doc, fowo);
if(result == Rhino.PlugIns.WriteFileResult.Success)
Console.WriteLine("Converted file: {0}", objPath);
else
Console.WriteLine("File conversion failed.");
}
Console.WriteLine("Finished converting. Press any key to exit...");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
Console.WriteLine("press any key to exit");
Console.ReadKey();
}
}
}
}