From 26f4d70876d15f4110ca4cbdaf5c28674d0e3504 Mon Sep 17 00:00:00 2001 From: Michael L Smith Date: Sun, 28 Feb 2016 15:08:27 -0800 Subject: [PATCH] Added getOpenSCADPath method to discover path to OpenSCAD executable amongst multiple options --- OSCADSharp/OSCADSharp.ConsoleTests/Program.cs | 7 +++--- OSCADSharp/OSCADSharp/Settings.cs | 22 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs index a172d01..35e02f9 100644 --- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs +++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs @@ -14,10 +14,11 @@ namespace OSCADSharp.ConsoleTests { static void Main(string[] args) { - Variables.Global.Add("$fn", 100); + Variables.Global.Add("sphereRadius", 15); + + var obj = new Sphere(); + obj.Bind("Radius", Variables.Global["sphereRadius"]); - var obj = new Sphere(30); - var pos = obj.Position(); var cyl1 = new Cylinder(1, 100, true).Translate(pos); var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).Translate(pos); diff --git a/OSCADSharp/OSCADSharp/Settings.cs b/OSCADSharp/OSCADSharp/Settings.cs index 0d87776..61a9772 100644 --- a/OSCADSharp/OSCADSharp/Settings.cs +++ b/OSCADSharp/OSCADSharp/Settings.cs @@ -2,6 +2,7 @@ using OSCADSharp.Scripting; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,11 +19,28 @@ namespace OSCADSharp /// public static readonly string OSCADSharpHeader = String.Format("/*Code Generated using OSCADSharp on {0}. {1}{2}For more information, please visit https://github.com/Exolun/OSCADSharp */{3}", DateTime.Now.ToString(), Environment.NewLine, Environment.NewLine, Environment.NewLine); - + /// /// Path to the OpenSCAD executable for file invocation /// (Default value is set the default install directory on Windows) /// - public static string OpenSCADPath = @"C:\Program Files (x86)\OpenSCAD\openscad.exe"; + public static string OpenSCADPath = getOpenSCADPath(); + + private static string getOpenSCADPath() + { + string[] possibleFilePaths = new string[] + { + @"C:\Program Files (x86)\OpenSCAD\openscad.exe", + @"C:\Program Files\OpenSCAD\openscad.exe" + }; + + foreach (string path in possibleFilePaths) + { + if (File.Exists(path)) + return path; + } + + return null; + } } }