Problem with the CopyTrimCurves function

Dear Community,

I have a problem within the following lines of code. I am trying to redraw surfaces with the given trims but a diferent refinement. When I have a small amount of surfaces everything works properly, but when there are a lot of surfaces the program stops with an SEHException. But not emediatly and not always. I figured out that the problem comes from the CopyTrimCurves function, because when I decomented this line everything worked good.

So my questions are the following:

  • Can I avoid the CopyTrimCurves function or are I using it wrong?

  • also the way how I get to the right surface depending to the right face seems quite unfancy - is there a better way to do this?

    foreach (var surface in ((Brep) element.Geometry).Surfaces)
    {
    var ud = surface.UserData.Find(typeof (UserDataSurface)) as UserDataSurface;
    if (ud == null)
    continue;

       foreach (var support in ud.myElementDataSurface.verticeSupports)
       {
           drawPointSupport(e, surface.PointAt(support.u, support.v), support.dispX, support.dispY, support.dispZ);
       }
    
      if (ud.myElementDataSurface.elementProperty == null)
           continue;
    
    var newsurface = surface.Rebuild(
            ud.myElementDataSurface.elementProperty.refinment.PDeg + surface.Degree(0),
            ud.myElementDataSurface.elementProperty.refinment.QDeg + surface.Degree(1),
            ud.myElementDataSurface.elementProperty.refinment.minElementU + surface.ToNurbsSurface().Points.CountU,
           ud.myElementDataSurface.elementProperty.refinment.minElementV + surface.ToNurbsSurface().Points.CountV);
    
    
    foreach (var face in ((Brep)element.Geometry).Faces)
    {
          var gt = ((Brep)element.Geometry).Surfaces[face.SurfaceIndex];
          if (gt == surface)
         {
             var nsurface = Brep.CopyTrimCurves(face, newsurface, 0.0001);
             if (nsurface.IsValid)
            {
                e.Display.DrawBrepWires(nsurface.ToBrep(), Color.Aqua);
            }
         break; 
     }
    

    }
    }

Thanks a lot for your help!

Cheers, Tobi

Do you get a more descriptive error than SEHException? Are you running the release version of Rhino?

Well actually just the SEHException. When I deactivate the ‘just debug own code’ it gives me some OutOfRange Exceptions but that does not help me a lot. The interessting thing is that this error does not occur allways, but after some modification (e.g. move, rotate,…). I can now for sure say that this error comes out of the CopyTrimCurves function. Is there a way to copy the trims and curves by myself, I would need this also for a different part of the plugin where I have the trimdata just as text data.
I am generally running in Debug64. But I tried it as well in the release version. I am using Rhino 5.

Thanks for your help,
Tobias

I have no Idea about the CopyTrimCurves function but

in the Brep class and BrepFace class you can acces the Trims and Curves via the Loop, Trims, Edges or Curves3D property
http://developer.rhino3d.com/api/RhinoCommonWin/html/T_Rhino_Geometry_Brep.htm
and as far as I’ve seen some of some are setable or editable,
might be an Idea

cheers Yoshy