Cut hole on a Brep


#1

Hello everybody.
I have a problem that I go crazy.


I have the brep of step 1. I want to cut a second hole next what there is. See the step 2, the blue line is the hole that I want to cut. For make the hole I use the following code.

	protected override Result RunCommand(RhinoDoc doc, RunMode mode)
	{
		try
		{

			_plugIn = (AgutCAM2PlugIn)PlugIn;
			ObjRef crvRef;
			Result res = RhinoGet.GetOneObject("Select cut curve", false, ObjectType.Curve, out crvRef);
			if (res != Result.Success)
				return res;
			Curve curvaCorte = crvRef.Curve();

			ObjRef brepRef;
			res = RhinoGet.GetOneObject("Select brep to be cut", false, ObjectType.Brep, out brepRef);
			Brep imagen_brep = brepRef.Brep();

                        //Start to cut
			Brep[] listaImagenes;
			Surface extrusion_corte_imagen = Surface.CreateExtrusion(curvaCorte, new Vector3d(0, 0, 0.25));

			listaImagenes = imagen_brep.Split(extrusion_corte_imagen.ToBrep(), 0.25);
			if (!listaImagenes.Any())
			{
				throw new Exception("Piedra->crearPiedrasApartirDeBreps->No se ha podido cortar la imagen");
			}


			//Print
			RhinoFunctions.AñadirBrepACapa(RhinoDoc.ActiveDoc, listaImagenes[0], "out 1" );
			RhinoFunctions.AñadirBrepACapa(RhinoDoc.ActiveDoc, listaImagenes[1], "out 2" );
			



		}
		catch (Exception ex)
		{

		}
		return Result.Success;
	}

The result of cut is the brep of step 3. It is wrong. The right result should be 3 B, don’t?
But, if I make a hole( blue line) on the brep 3, the result is the brep of step 4. In this case the code works like I hope. Although the final outcome is wrong because the brep of step 3 was alredy wrong.
Someone can help me, please.
This is the document. You can make a test and see what I say.

DocForo.3dm (51.1 KB)


(Radovan Grmusa) #2

Hi

Problem is somehow with first cut-hole you have in 1. (& 2).
When I use your brep from 1 and untrim inside cut-hole i got brep in 10.
Then I use your cut-polyline, place it on brep 10 and cut it with your plugin command. Result is in 11.
Then I move cut-polyLine to next position (new postion up-left corner = old position up-right corner) - see 11b.
Then I cut it again with your plugin command and got 12.
Everything works OK.

So, solve the issue of first hole (whoa nd how created it) or recreate everything form the begining but use same cut-polyline…

RadovanDocForo2.3dm (126.1 KB)


#3

Thank you very much for you answare RadovangG.

Yes, the problem is the first brep. But, What is wrong in the first brep how I can solve it via code(c#)?.
I am unable to know what is happening,

Thanks again.


(Radovan Grmusa) #4

I do not know where if porblem exactly.
Brep/brep operations (split/trim/boolean operations) sometimes produce weird resulting breps.
It happens not only with code but when using Rhino manualy, via rhino UI commands.
How did you create brep in 1 -> how did you make first cut hole?
Is it done by same polyline?
R


#5

I use the same algorithm, but I cannot reproduce the error starting with original brip with my isolate code. But, the wrong brep is there. See this picture. It is strange, is it a bug of Rhino?

Thanks


#6

Please someone can help me.
Does anyone know what is happening here?

Thanks a lot


(Radovan Grmusa) #7

Hi
Brep in 3 (as result of brep.split in your C# code) is “weird” one.
If you do the same operation in Rhino UI ( Split command) everything ends OK, brep looks good.
If you do the same operation with Grasshopper again everythign is OK.
And this is strange behaviour, it looks like problem is in C#/Rhinocommon code.
At the same time topology of brep 1 looks good to me.
Maybe somebody form McNeel can help you.
R


(Dale Fugier) #8

Hi @mprades,

This sample take a different approach to trimming planar surfaces - you might see if this is helpful to you.

https://github.com/mcneel/rhino-developer-samples/blob/master/rhinocommon/cs/SampleCsCommands/SampleCsPlanarFaceLoops.cs

– Dale


#9

Thank you very much Dale. I going to take a look.