I want to export curves per branch to dxf via code, so that I have a file for each heightsection.
I got stuck looping through the tree.
Maybe someone can help me out.
private void RunScript(bool export, Brep brep, List plane, string path, string fileType, string filename, ref object A, ref object B)
{
// get contours
var contourTree = new DataTree<Curve>();
for (int i = 0; i < plane.Count; i++)
{
Curve[] contours = Brep.CreateContourCurves(brep, plane[i]);
contourTree.AddRange(contours, new GH_Path(i));
}
//get or create directory
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
//create filetype
if (!fileType.StartsWith("."))
{
fileType = "." + fileType;
}
//declare attributes
ObjectAttributes attr = RhinoDocument.CreateDefaultAttributes();
var doc = Rhino.RhinoDoc.ActiveDoc;
if (doc == null) return;
doc.Objects.UnselectAll();
if (export)
{
for (int i = 0; i < contourTree.BranchCount; i++)
{
var crvs = doc.Objects.AddCurve(contourTree.Branches[i], attr);
doc.Objects.Select(crvs);
Rhino.RhinoApp.RunScript("-_Export \n\"" + path + "\\" + filename + fileType + "\"\n _Enter", true);
}
}
A = contourTree;
I’m happy to help out with the code that isn’t working, but it just seemed like it was too complicated to begin with. If you have good reasons for it though then let’s figure out what went wrong with the tree approach.
Hi David, and thanks again for your patience !
Your help is really apreciated!
I tried it in a nested for loop now and try to understand the tree thing later with simpler excercises:sweat_smile:
The problem now is the export between line 108 -117. I suspect it has to be in another loop since it generates multiple times the same.
I hope its not too inconvinient to ask again
private void RunScript(bool export, List brep, List plane, string path, string fileType, string filename, ref object A, ref object B)
{
//get or create directory
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
//create filetype
if (!fileType.StartsWith("."))
{
fileType = "." + fileType;
}
//declare attributes
ObjectAttributes attr = RhinoDocument.CreateDefaultAttributes();
var doc = Rhino.RhinoDoc.ActiveDoc;
if (doc == null) return;
var contours = new List<Curve>();
for (int i = 0; i < plane.Count; i++)
{
for (int j = 0; j < brep.Count; j++)
{
//get the contours
Curve[] crvs = Brep.CreateContourCurves(brep[j], plane[i]);
contours.AddRange(crvs);
}
//filename like planeHeight
string filenameHeight = filename + plane[i].Origin.Z.ToString();
foreach (Curve c in contours)
{
var bakedC = doc.Objects.AddCurve(c, attr);
doc.Objects.Select(bakedC);
Rhino.RhinoApp.RunScript("-_Export \n\"" + path + "\\" + filenameHeight + fileType + "\"\n _Enter", true);
}
doc.Objects.UnselectAll();
}
A = contours;