GHPython offset polysurface created in Grasshopper

Hi,

I am trying to offset a brep / polysurface in gh using Python. I am referencing a bunch of curves into gh to manipulate, joining & extruding them up, and trying to create a brep from that by offsetting the extruded polysrf but when I use Offset Surface in gh (both the native & Pufferfish one), the polysurface created is not a single solid brep. However, when I manually offset that extruded polysrf in Rhino, the brep created is a single closed brep.

My current issue with the Rhino Common command is that CreateOffsetBrep requires a brep input, and when I input the brep component in gh, I am getting an error that says it is a GUID & not a brep. Is there a way to convert this info? Or perhaps a more elegant way to resolve this problem? The command I am running is:

a = Rhino.Geometry.Brep.CreateOffsetBrep(brep, dist, solid, ext, shr)

I have also included the Rhino & gh file to hopefully explain what I’m trying to achieve, and the attempts in gh I have tried - Pufferfish (not creating a single closed brep), scriptsyntax (which is a srf input only, so doesn’t inherently work I think?), and Rhino Common (which is giving a GUID error).

Thank you in advance for any feedback / suggestions / solutions!

220628_eg_offset-problem.gh (13.4 KB)
220628_eg_offset-problem.3dm (793.2 KB)

Hey @xinynh,

This is hacky but works;

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

cbrep = rs.coercebrep(brep)
tol = sc.doc.ModelAbsoluteTolerance

b = Rhino.Geometry.Brep.CreateOffsetBrep(cbrep, dist, solid, ext, tol)

a = b[0]

To convert from GUID to Brep I used the rs.coercebrep method. I also wasn’t sure what your shr input was doing, so I swapped it for the document tolerances instead. Lastly the CreatedOffSetBrep was returning an array so I returned the first index (i.e. b[0])

Hope this helps,

1 Like

Set the input parameter type hint to Brep:

The method still return none though. You can read the documentation and see if your input data is appropriate for the method. Edit: The input parameters were incorrect. With the overload you’re implementing the final argument is tolerance:


220628_eg_offset-problem.gh (15.4 KB)

3 Likes

Hi @AndersDeleuran,

Thanks heaps for your feedback & solution - much more elegant & simple! I had a quick question though, how did you know that the command was asking for 3 outputs (a, b, c)? I’ve taken a look at the API documentation, but I can’t see where it specified what the final argument(s) will be - so I’m not sure how to determine how I was outputting tolerance & how to avoid that mistake next time.

That can admittedly be a bit vague. But in this case we see that there are two out parameters as well as one return value, which in GHPython typically will return all three (sometimes you have to pass the out parameters as well):

I typically just inspect what is returned directly in the editor (e.g. using print, type(), len() etc.) and continue coding from there:

1 Like