Convert Surface to Brep inside Python component

I know on the Python component input you can set the data input type from surface to Brep if the code in your python such as BrepFace.IsPointOnFace but you are inputting a surface but how to you do change the type from a surface to Brep with Rhino common code. As i need my input to stay as a surface for most of the code but just change to a brep to check if the Closest point on a surface is within the trim boundary using BrepFace.IsPointOnFace.

I know I can use Gh components in python code so could call the Point In Trim Component, but as this is not the first time I have come up against this issue I though I would ask.

Assuming your input typehint is set as ‘Surface’ and named ‘surface’ then you would to it like this:

import Rhino

brep = Rhino.Geometry.Brep.CreateFromSurface(surface)
# do stuff with your brep
print brep

Thanks, That’s just what i was searching for i knew it would be something simple but just could not find it in the SDK.

You should just be able to do

brep = surface.ToBrep()

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Surface_ToBrep.htm

1 Like

Following on from this is it possible for this new Brep to keep the trim boundaries of the original input surface as currently it untrims the surface so when your trying to find if a point is inside a trim boundary on the brep it always is as the surface becomes untrimmed :frowning:

Hi @mattgaydon,

Surfaces do not have trims - Breps have trims.

If you have a surface, that you obtained from a Brep (or BrepFace) and then call Brep.CreateFromSurface, then your new Brep will not contain the trimming information from the original Brep.

If maintaining the trimming information is important, than perhaps using Brep.CopyTrimCurves is a better approach.

– Dale

I’m starting with a trimmed surface but was trying to find away to check is a surface closest point was on the trimmed surface or not.

As not to go off-topic i will post the code i have as a new question as maybe i am using the wrong workflow completely.

Just to be clear, if your input type is surface it will always lose trim data because as @dale said, surfaces don’t have trim data. If you want to get the trim data through the input you need to use brep, because a trimmed surface is a brep.

Ah ok, so my issue is now in the other direction. Brep > Surface. As if I set it as Brep all the surface commands in my code break. I only need it to be a Brep for one line of code.

UPDATE: Found the Answer, this gives me back the untrimmed surface I can use on the rest of the code.

brepFace = brep.Faces[0]
surface = brepFace.DuplicateSurface()

Here’s the code in question.