Problem with mesh to brep

I have a function that generates mesh as the result. However, I need the result to be the input of another function which requires brep as the format of input. Therefore, I used a simple definition (picture 1) to convert mesh (picture 2) to brep. The function is able to serve the purpose but 1) it takes quite a long time ;2) not very stable when processing. Is there an other method that can convert mesh to brep? Thanks a lot.



indeed, post a file?

Also maybe check MeshToPolySurface component in the Pufferfish plug-in.