How to make region or boundary from curves in Rhino script

How to make region or boundary from curves in Rhino script ?
RVB have command Rhino.CurveBooleanUnion (arrCurves [, blnDelete]) but arrCurves are closed, planar curves.

You can’t with Rhinoscript native methods. What you can do is script

Rhino.Command ("_CurveBoolean..."),

however, that needs a point mouse-clicked on screen somewhere outside the figure.

I work around this by getting the bounding box of the entire geometry, getting a corner of that, moving that point a bit further to the outside to be sure, then converting it to a string and feeding it into the command string of CurveBoolean. I can post an example later, but in the middle of stuff right now…

–Mitch

You can try the below code:

Option Explicit

Call Main()
Sub Main()
    
    Dim strMsg, arrCurves, strCmd, blnResult
    Dim strObj, arrObjs, b, arrTmp, arrBorders()
    
    strMsg = "Select lines or curves"
    arrCurves = Rhino.GetObjects(strMsg, 4, False, True, True)
    If IsNull(arrCurves) Then Exit Sub
    
    strCmd = "_TestGetPlanarRegions"
    blnResult = Rhino.Command(strCmd, False)
    
    If blnResult = True Then
        arrObjs = Rhino.LastCreatedObjects(False)
        If Not IsArray(arrObjs) Then Exit Sub
        
        b = 0
        For Each strObj In arrObjs
            arrTmp = Rhino.DuplicateEdgeCurves(strObj, False)
            If IsArray(arrTmp) Then
                ReDim Preserve arrBorders(b)
                arrBorders(b) = Rhino.JoinCurves(arrTmp, True)(0)
                b = b + 1
            End If    
        Next
        
        Rhino.DeleteObjects arrObjs
        Rhino.SelectObjects arrBorders

    End If

End Sub

I´ve tested this only in perspective viewport with simple cases, eg. all curves have to be coplanar.

c.

2 Likes

Thanks all for fast reply.
Fisrt time i use Rhino.Command ("_CurveBoolean") with loop 200 times, function is finished running time of 30 seconds.
Second time i use Rhino.Command(_TestGetPlanarRegions, False) with loop 200 times,function is finished running time of 8 seconds.
To Clement : What are you find Rhino command _TestGetPlanarRegions? I search in Rhino 5 help file not this command ?

Hi mutsukokono,

Test… commands are not listed in the helpfile, they are developer commands added for testing purposes only and can make your Rhino unstable or even crash. That particular command never caused any trouble here. But in general, Test Commands should only be used if you are really knowing what you do and have no other option.

Btw. To gain more speed from the script i´ve posted above, you might add at the top of the script:

Rhino.EnableRedraw False

and

Rhino.EnableRedraw True

at the end of the script. This would make it a lot faster as it disables redrawing the viewport after every surface border has been duplicated (and joined). After this you must enable redraw or Rhino will not react on anything.

c.

Do the same (Rhino.EnableRedraw False) with the CurveBooleanScript and compare the time as well…