! _NoEcho _-Runscript ( Option Explicit 'Script written by Mitch 'Version Monday, March 26, 2012 Call RetrimSrfs() Sub RetrimSrfs() Dim arrObjs,strObj,dupBords,testPt,srfDivs,try2,gName Dim arrUTrim,strSrf,arrSplitSrfs,canDo,noCanDo srfDivs = 10 : try2 = 5 : canDo = 0 : noCanDo = 0 gName="RetrimSrfTempGroup" arrObjs = Rhino.GetObjects("Select surfaces to retrim", 8,, True) If Not IsArray(arrObjs) Then Exit Sub Call Rhino.UnselectAllObjects Call Rhino.EnableRedraw(False) If Not Rhino.IsGroup(gName) Then Call Rhino.AddGroup(gName) For Each strObj In arrObjs If Rhino.IsSurface(strObj) And Rhino.IsSurfaceTrimmed(strObj) Then dupBords = Rhino.DuplicateSurfaceborder(strObj) 'all borders Call Rhino.AddObjectsToGroup(dupBords,gName) testPt = FindTestPoint(strObj, dupBords, srfDivs) If IsNull(testPt) Then testPt = FindTestPoint(strObj, dupBords, srfDivs * try2) End If If Not IsNull(testPt) Then Call Rhino.SelectObject(strObj) Call Rhino.Command("_-UntrimAll _KeepTrimObjects=_No SelID " & strObj & " _Enter", False) arrUTrim = Rhino.LastCreatedObjects 'should just be one surface Call Rhino.SelectObjects(arrUTrim) Call Rhino.Command("_Split _Shrink=_No _-SelGroup "&gName&" _Enter", False) arrSplitSrfs = Rhino.LastCreatedObjects For Each strSrf In arrSplitSrfs If Not Rhino.IsPointOnSurface(strSrf, testPt) Then Call Rhino.DeleteObject(strSrf) End If Next canDo = canDo + 1 Else noCanDo = noCanDo + 1 End If Call Rhino.DeleteObjects(dupBords) End If Call Rhino.UnselectAllObjects Next If Rhino.IsGroupEmpty(gname) Then Call Rhino.DeleteGroup(gName) Call Rhino.EnableRedraw(True) Call Rhino.Print(canDo & " surfaces retrimmed, " & noCanDo & " unable to be retrimmed") End Sub Function FindTestPoint(srf, crvs, divs) 'find test point that lies on visible trimmed portion of surface 'this point must also not lie on an edge FindTestPoint = Null Dim udom,vDom,pt,crv,u,v,blnOnCrv uDom = Rhino.SurfaceDomain(srf, 0) vDom = Rhino.SurfaceDomain(srf, 1) For u=uDom(0) To uDom(1) Step ((uDom(1) - uDom(0)) / divs) For v=vDom(0) To vDom(1) Step ((vDom(1) - vDom(0)) / divs) pt = Rhino.EvaluateSurface(srf, Array(u, v)) If Rhino.IsPointOnSurface(srf, pt) Then blnOnCrv = False For Each crv In crvs If Rhino.IsPointOnCurve(crv, pt) Then blnOnCrv = True : Exit For End If Next If Not blnOnCrv Then 'Call Rhino.AddPoint(pt) 'test FindTestPoint = pt : Exit Function End If End If Next Next End Function )