if anyone needs join brep component that outputs indices of joined breps, here it is:
JoinBrepsIndex.gh (13.5 KB)
rhinocommon method
Brep JoinBreps(IEnumerable brepsToJoin, System.Double tolerance, System.Double angleTolerance, out List<int> indexMap)
using System;
using System.Collections.Generic;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
public class Script_Instance : GH_ScriptInstance
{
private void RunScript(
DataTree<Brep> breps,
double tolerance,
double angleTolerance,
ref object JoinedBreps,
ref object IndexMap)
{
DataTree<Brep> joinedTree = new DataTree<Brep>();
DataTree<int> indexMapTree = new DataTree<int>();
if (tolerance <= 0)
{
tolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance * 2.1;
}
if (angleTolerance <= 0)
{
angleTolerance = RhinoDoc.ActiveDoc.ModelAngleToleranceRadians;
}
for (int bi = 0; bi < breps.BranchCount; bi++)
{
GH_Path path = breps.Path(bi);
List<Brep> branch = breps.Branch(bi);
if (branch == null || branch.Count == 0) continue;
List<int[]> idxMap;
Brep[] joined = Brep.JoinBreps(branch, tolerance, angleTolerance, out idxMap);
if (joined != null && joined.Length > 0)
{
if (idxMap != null && idxMap.Count == joined.Length)
{
for (int j = 0; j < joined.Length; j++)
{
GH_Path resPath = new GH_Path(path).AppendElement(j);
joinedTree.Add(joined[j], resPath);
int[] indices = idxMap[j];
if (indices != null && indices.Length > 0)
{
foreach (int k in indices)
{
indexMapTree.Add(k, resPath);
}
}
}
}
else
{
for (int j = 0; j < joined.Length; j++)
{
GH_Path resPath = new GH_Path(path).AppendElement(j);
joinedTree.Add(joined[j], resPath);
indexMapTree.Add(j, resPath);
}
}
}
else
{
for (int i = 0; i < branch.Count; i++)
{
if (branch[i] == null) continue;
GH_Path resPath = new GH_Path(path).AppendElement(i);
joinedTree.Add(branch[i], resPath);
indexMapTree.Add(i, resPath);
}
}
}
JoinedBreps = joinedTree;
IndexMap = indexMapTree;
}
}
