Hello Everyone!,
Long time reader, first time having anything I couldn’t quite grasp by the examples provided in the forum;
For context:
I’m at a c# beginners level; I’m trying to generate my own set of “batteries” by bundling several GH functions into c# tools (in order to get familiar with the language) to deal with tasks that I’m often presented with. This time around, I’m trying to achieve filtering a List of Breps, and returning only the Closest Brep face to the dot product of the normal and a given vector given a certain treshold, nothing otherworldly.
But for the life of me, I’m having trouble with relating the two lists that I extract from the breps (faces and dot products of the vectors) since the lists I need to filter, all happen inside the nested loops of one another and I can’t find the way to retrieve them.
Please excuse the noob request.
This is how I normally go about it in GH:
And this is my c# code with a few comments that I hope are not too dumb to add for experienced programmers:
private void RunScript(List breps, Point3d testUV, Vector3d matchAxis, double treshold, ref object A, ref object B, ref object C)
{
//Get Geometry List as Brep
List <BrepFace> brepFaces = new List <BrepFace>();
//For each Brep, get the individual face information into a new List using .AddRange
for(int i = 0; i < breps.Count; i++)
{
brepFaces.AddRange(breps[i].Faces);
List <Vector3d> bFaceNormals = new List <Vector3d>();
//For each face, reparametrize domain and extract normal at 0.5,0.5
foreach(BrepFace bFace in brepFaces)
{
bFace.SetDomain(0, new Interval(0, 1));
bFace.SetDomain(1, new Interval(0, 1));
Vector3d bFaceNormal = bFace.NormalAt(0.5, 0.5);
bFaceNormals.Add(bFaceNormal);
} B = bFaceNormals;// <----------------------------------
List <Double> dotPts = new List <Double>();
foreach (Vector3d bNorm in bFaceNormals)
{
Double dotPt = Vector3d.Multiply(bNorm, matchAxis);
dotPts.Add(dotPt);
} C = dotPts;// <---------------------------------------
//This is the part I have no idea how to get to work
/*if(dotPts[i] >= treshold){Print(dotPts[i].ToString()); A = brepFaces[i];}*/
} //A = brepFaces;// <-------------------------------------
Thank you in advance for the tips,
My best regards,
Jaime.