Added .ToFile(path) on OSCADObject

This commit is contained in:
Michael Smith 2016-02-21 11:39:36 -08:00
parent cce795332f
commit 28bb1736e9
2 changed files with 23 additions and 8 deletions

View File

@ -15,18 +15,17 @@ namespace OSCADSharp.ConsoleTests
{ {
var obj = new Cube(5, 10, 20) + new Sphere(10).Translate(-10, 5, 0); var obj = new Cube(5, 10, 20) + new Sphere(10).Translate(-10, 5, 0);
//var pos = obj.Position(); var pos = obj.Position();
//var cyl1 = new Cylinder(1, 100, true).Translate(pos); var cyl1 = new Cylinder(1, 100, true).Translate(pos);
//var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).Translate(pos); var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).Translate(pos);
//var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos); var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos);
//var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red"); var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red");
var topCorner = new Sphere().Translate(obj.Bounds().TopRight); var topCorner = new Sphere().Translate(obj.Bounds().TopRight);
var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft); var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
string script = (obj + topCorner + botCorner).ToString(); (obj + topCorner + botCorner + axisHelper).ToFile("test.scad");
File.WriteAllLines("test.scad", new string[] { script.ToString() });
//Console.ReadKey(); //Console.ReadKey();
} }
} }

View File

@ -3,6 +3,7 @@ using OSCADSharp.Spatial;
using OSCADSharp.Transforms; using OSCADSharp.Transforms;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -313,6 +314,21 @@ namespace OSCADSharp
return finalObject; return finalObject;
} }
/// <summary>
/// Writes the script for this OSCADObject to the file specified
/// </summary>
/// <param name="filePath">Path for the file to write. Including filename and (optionally) file extension</param>
public void ToFile(string filePath)
{
string path = filePath;
if (!path.EndsWith(".scad"))
{
path += ".scad";
}
File.WriteAllLines(path, new string[] { this.ToString() });
}
#endregion #endregion
#region Operators #region Operators