Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
protected override void SolveInstance(IGH_DataAccess DA)
{
List<Brep> InputBreps = new List<Brep>();
string SavePath = null;
bool On = false;
DA.GetDataList(0, InputBreps);
DA.GetData(1, ref SavePath);
DA.GetData(2, ref On);
if(On)
{
ExportStl(InputBreps, SavePath);
}
IEnumerable<string> files = GetStlFiles(SavePath);
DA.SetDataList(0, files);
}
protected void ExportStl(List<Brep> breps, string path)
{
List<Guid> guidList = new List<Guid>();
Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
for (int i = 0; i < breps.Count; i++)
{
if (breps[i] == null || !breps[i].IsValid)
{
this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No object to bake, or brep not valid, aborted.");
return;
}
System.Guid guid = ot.AddBrep(breps[i]);
guidList.Add(guid);
}
int nSelected = ot.Select(guidList);
if (nSelected != guidList.Count)
{
this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not all objects could be selected, aborted.");
return;
}
string cmd = "-_Export " + path + "file.stl" + " _Enter";
Rhino.RhinoApp.RunScript(cmd, true);
ot.Delete(guidList, true);
}
protected IEnumerable<string> GetStlFiles(string path)
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] files = di.GetFiles("*.stl", System.IO.SearchOption.AllDirectories);
IEnumerable<string> fullNames = files.Select(file => file.FullName);
return fullNames;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment