Option Explicit 'Script written by Luis Gil 'Script copyrighted by Luis Gil, www.legil.org 'Script version 1.0 'A begining step in laying out laser cutter templates. This script will cut a desired 'number of sections in the U and V directions through the selected objects, labels them, 'and creates a new layer for them. 'This is helpful for creating an "eggcrate" model of the shape. The shapes can later 'be flatten and notched to be sent out to a laser cutter. A script to help in that is 'also available at www.legil.org or email me: luis@legil.org Call sectionObject Sub sectionObject Dim strObjects : strObjects = Rhino.GetObjects("Select surface or polysurface to section", 8 + 16) Dim arrBounding : arrBounding = Rhino.BoundingBox(strObjects) Dim dblDomainU : dblDomainU = Rhino.Distance(arrBounding(0), arrBounding(1)) Dim dblDomainV : dblDomainV = Rhino.Distance(arrBounding(0), arrBounding(3)) Dim dblDomainW : dblDomainW = Rhino.Distance(arrBounding(0), arrBounding(4)) Dim intCutsU : intCutsU = Rhino.GetInteger("How many sections in U direction?", 10) Dim intCutsV : intCutsV = Rhino.GetInteger("How many sections in V direction?", 10) Dim intCutsW : intCutsW = Rhino.GetInteger("How many sections in W direction?", 10) Dim strCutPlaneU : strCutPlaneU = Rhino.PlaneFromPoints(arrBounding(0), arrBounding(1), arrBounding(5)) Dim strCutPlaneV : strCutPlaneV = Rhino.PlaneFromPoints(arrBounding(0), arrBounding(3), arrBounding(7)) Dim strCutPlaneW : strCutPlaneW = Rhino.PlaneFromPoints(arrBounding(0), arrBounding(1), arrBounding(3)) If Not (intCutsU = 0) Then Dim dblStepU : dblStepU = dblDomainU / (intCutsU) Rhino.AddLayer "u_Sections" End If If Not (intCutsV = 0) Then Dim dblStepV : dblStepV = dblDomainV / (intCutsV) Rhino.AddLayer "v_Sections" End If If Not (intCutsW = 0) Then Dim dblStepW : dblStepW = dblDomainW / intCutsW Rhino.AddLayer "w_Sections" End If Dim i, t, j, q Dim intVCount : intVCount = 1 Dim intUCount : intUCount = 1 Dim intWCount : intWCount = 1 Dim strView : strView = Rhino.CurrentView Dim strLayer : strLayer = Rhino.CurrentLayer 'Rhino.EnableRedraw False For j = 0 To UBound(strObjects) If Not (intCutsV = 0) Then Rhino.CurrentLayer "v_Sections" For i = .125 To dblDomainV Step dblStepV Dim arrVectorV : arrVectorV = Rhino.VectorCreate(arrBounding(3), arrBounding(0)) Dim vecUnit : vecUnit = Rhino.VectorUnitize(arrVectorV) Dim arrVecMove: arrVecMove = Rhino.VectorScale(vecUnit, i) Dim arrNewOrigin : arrNewOrigin = Rhino.PointAdd(arrBounding(0), arrVecMove) Dim newCutPlane : newCutPlane = Rhino.MovePlane(strCutPlaneU, arrNewOrigin) Dim arrSectionCut : arrSectionCut = Rhino.AddSrfSectionCrvs(strObjects(j), newCutPlane) If Not IsNull(arrSectionCut) Then Dim arrCutBounding : arrCutBounding = Rhino.BoundingBox(arrSectionCut) Dim arrTextOrigin : arrTextOrigin = arrCutBounding(4) Dim cPlaneRestore : cPlaneRestore = Rhino.ViewCPlane(strView, newCutPlane) Dim strText : strText = Rhino.AddText("v_" & intVCount, arrTextOrigin) Rhino.ObjectColor strText, RGB(255, 0, 0) intVCount = intVCount + 1 Rhino.ViewCPlane strView, cPlaneRestore End If Next End If If Not (intCutsU = 0) Then Rhino.CurrentLayer "u_Sections" For t = 0 To dblDomainU Step dblStepU Dim arrVectorU : arrVectorU = Rhino.VectorCreate(arrBounding(1), arrBounding(0)) Dim vecUnitb : vecUnitb = Rhino.VectorUnitize(arrVectorU) Dim arrVecMoveb: arrVecMoveb = Rhino.VectorScale(vecUnitb, t) Dim arrNewOriginb : arrNewOriginb = Rhino.PointAdd(arrBounding(0), arrVecMoveb) Dim newCutPlaneb : newCutPlaneb = Rhino.MovePlane(strCutPlaneV, arrNewOriginb) Dim arrSectionCutb : arrSectionCutb = Rhino.AddSrfSectionCrvs(strObjects(j), newCutPlaneb) If Not IsNull(arrSectionCutb) Then Dim arrCutBoundingb : arrCutBoundingb = Rhino.BoundingBox(arrSectionCutb) Dim arrTextOriginb : arrTextOriginb = arrCutBoundingb(4) Dim cPlaneRestoreb : cPlaneRestoreb = Rhino.ViewCPlane(strView, newCutPlaneb) Dim strTextb : strTextB = Rhino.AddText("u_" & intUCount, arrTextOriginb) Rhino.ObjectColor strTextB, RGB(255, 0, 255) intUCount = intUCount + 1 Rhino.ViewCPlane strView, cPlaneRestoreb End If Next End If If Not (intCutsW = 0) Then Rhino.CurrentLayer "W_Sections" For q = 0 To dblDomainW Step dblStepW Dim arrVectorW : arrVectorW = Rhino.VectorCreate(arrBounding(4), arrBounding(0)) Dim vecUnitW : vecUnitW = Rhino.VectorUnitize(arrVectorW) Dim arrVecMoveW: arrVecMoveW = Rhino.VectorScale(vecUnitW, q) Dim arrNewOriginW : arrNewOriginW = Rhino.PointAdd(arrBounding(0), arrVecMoveW) Dim newCutPlaneW : newCutPlaneW = Rhino.MovePlane(strCutPlaneW, arrNewOriginW) Dim arrSectionCutW : arrSectionCutW = Rhino.AddSrfSectionCrvs(strObjects(j), newCutPlaneW) If Not IsNull(arrSectionCutb) Then Dim arrCutBoundingW : arrCutBoundingW = Rhino.BoundingBox(arrSectionCutW) Dim arrTextOriginW : arrTextOriginW = arrCutBoundingW(0) Dim cPlaneRestoreW : cPlaneRestoreW = Rhino.ViewCPlane(strView, newCutPlaneW) Dim strTextW : strTextW = Rhino.AddText("w_" & intWCount, arrTextOriginW) Rhino.ObjectColor strTextW, RGB(0, 255, 255) intWCount = intWCount + 1 Rhino.ViewCPlane strView, cPlaneRestoreW End If Next End If Next 'Rhino.EnableRedraw True Rhino.CurrentLayer "strLayer" End Sub