Forgot password?

Create an account!


« back

RhinoScript – SplitBrep fails: help debugging, please


Please log in to write a message.

  • 1. ledisnomad (Aug 22, 2011 20.14):

    I know that there are plenty of examples out there, but to improve my Rhinoscripting abilities, I wanted to make my own "eggcrate" script. If you create a surface that is mostly x-y and choose 4 divisions in each direction it works. Choose 5 and suddenly it throws an error. Even more strange, it works for 6-8, but not for 9-13. I haven't tried any higher than that. I've traced it back to the SplitBrep call in line 120, but I can't figure out why. You can see in the image the red "rib" and blue cylinder: those are the two Breps being used for the failed SplitBrep call using 5 divisions in each direction. Any help would be greatly appreciated.

    Call EggCrate()
    Sub EggCrate()
            'Get user input
            Dim strSrf : strSrf = Rhino.GetObject("Select surface from which to create eggcrate",8)
            If IsNull(strSrf) Then Exit Sub
            Dim intDivsU : intDivsU = Rhino.GetInteger("How many divisions in the U direction?",5)
            If IsNull(intDivsU) Then Exit Sub
            Dim intDivsV : intDivsV = Rhino.GetInteger("How many divisions in the V direction?",5)
            If IsNull(intDivsV) Then Exit Sub
            Dim dblThickness : dblThickness = Rhino.GetReal("How thick is the material?",0.1)
            If IsNull(dblThickness) Then Exit Sub
            Dim arrBBox : arrBBox = Rhino.BoundingBox(strSrf)
            Call Rhino.EnableRedraw(False)
            Dim dblDomainU, dblSpacingU, arrPlaneU, arrContourCrvsU
            Dim dblDomainV, dblSpacingV, arrPlaneV, arrContourCrvsV
            dblDomainU = Rhino.Distance(arrBBox(0),arrBBox(3))
            dblSpacingU = dblDomainU/intDivsU
            arrPlaneU = Rhino.PlaneFromPoints(arrBBox(0),arrBBox(1),arrBBox(5))
            arrContourCrvsU = Rhino.AddSrfContourCrvs(strSrf, arrPlaneU, dblSpacingU)
            dblDomainV = Rhino.Distance(arrBBox(0),arrBBox(1))
            dblSpacingV = dblDomainV/intDivsV
            arrPlaneV = Rhino.PlaneFromPoints(arrBBox(0),arrBBox(3),arrBBox(7))
            arrContourCrvsV = Rhino.AddSrfContourCrvs(strSrf, arrPlaneV, dblSpacingV)
            Dim strPlanarSrf : strPlanarSrf = Rhino.AddSrfPt(Array(arrBBox(0),arrBBox(1),arrBBox(2),arrBBox(3)))
            Call Rhino.MoveObject(strPlanarSrf,Array(0,0,0),Array(0,0,-1))
            Dim loft
            'U RIBS
            Dim i, arrProjectedCrvU, arrRibsU()
            For i=0 To UBound(arrContourCrvsU)
                    arrProjectedCrvU = Rhino.ProjectCurveToSurface(arrContourCrvsU(i),strPlanarSrf, Array(0,0,-1))
                    Call Rhino.ReverseCurve(arrProjectedCrvU(0))
                    ReDim Preserve arrRibsU(i)
                    loft = Rhino.AddLoftSrf(Array(arrContourCrvsU(i),arrProjectedCrvU(0)))
                    arrRibsU(i) = loft(0)
            Call Rhino.DeleteObjects(arrContourCrvsU)
            Call Rhino.DeleteObjects(arrProjectedCrvU)
            'V RIBS
            Dim j, arrProjectedCrvV, arrRibsV()
            For j=0 To UBound(arrContourCrvsV)
                    arrProjectedCrvV = Rhino.ProjectCurveToSurface(arrContourCrvsV(j),strPlanarSrf, Array(0,0,-1))
                    Call Rhino.ReverseCurve(arrProjectedCrvV(0))
                    ReDim Preserve arrRibsV(j)
                    loft = Rhino.AddLoftSrf(Array(arrContourCrvsV(j),arrProjectedCrvV(0)))
                    arrRibsV(j) = loft(0)
            Call Rhino.DeleteObjects(arrContourCrvsV)
            Call Rhino.DeleteObjects(arrProjectedCrvV)
            Call Rhino.DeleteObject(strPlanarSrf)
            Dim arrNotched
            'Notch U ribs
            arrNotched = AddNotches(arrRibsU, arrRibsV, dblThickness, "top")
            'If I(boolNotches) Then Exit Sub
            'Notch V ribs
            Call AddNotches(arrRibsV, arrNotched, dblThickness, "bottom")
            'If Not(boolNotches) Then Exit Sub
            Call Rhino.EnableRedraw(True)

    End Sub

    Function AddNotches(arrRibs, arrCutters, dblThickness, strDir)
            Dim arrX, arrXCyl, strCircle, strCyl
            Dim ptStart, ptEnd, ptMid
            Dim return()
            Dim Rib, Cutter, intCounter
            intCounter = 0
            For Each Rib In arrRibs
                    For Each Cutter In arrCutters
                            arrX = Rhino.IntersectBreps(Rib, Cutter)
                            If IsCurve(arrX(0)) Then
                                    Call Rhino.ExtendCurveLength(arrX(0),0,2,(dblThickness))
                                    ptStart = Rhino.CurveStartPoint(arrX(0))
                                    ptEnd = Rhino.CurveEndPoint(arrX(0))
                                    ptMid = Rhino.CurveMidPoint(arrX(0))
                                    If (strDir = "top") Then
                                            strCyl = Rhino.AddCylinder(ptMid, ptStart, dblThickness)
                                            strCyl = Rhino.AddCylinder(ptEnd, ptStart, dblThickness)
                                    End If
                                    arrXCyl = Rhino.SplitBrep(Rib,strCyl)
                                    If IsNull(arrXCyl) Then
                                            Call Rhino.ObjectColor(Rib, RGB(200,0,0))
                                            Call Rhino.ObjectColor(strCyl, RGB(0,0,200))
                                    End If
                                    Call Rhino.DeleteObject(Rib)
                                    Rib = DeleteSmallerBrep(arrXCyl)
                                    Call Rhino.DeleteObject(strCyl)
                                    Call Rhino.DeleteObject(arrX(0))
                                    Call Rhino.Print("Error adding notches: ribs don't intersect")
                                    AddNotches = False
                                    Exit Function
                            End If
                    ReDim Preserve return(intCounter)
                    return(intCounter) = Rib
                    intCounter = intCounter + 1
            AddNotches = return
    End Function

    Function DeleteSmallerBrep(arrObj)
            Dim dblAreaA, dblAreaB
            dblAreaA = Rhino.SurfaceArea(arrObj(0))
            dblAreaB = Rhino.SurfaceArea(arrObj(1))
            If dblAreaA(0) < dblAreaB(0) Then
                    Call Rhino.DeleteObject(arrObj(0))
                    DeleteSmallerBrep = arrObj(1)
                    Call Rhino.DeleteObject(arrObj(1))
                    DeleteSmallerBrep = arrObj(0)
            End If

    End Function

Why are these buttons gray?