Dynamo Python Division Class
Table of Contents

Summary

These are master classes for creating panel subdivisions using the Design Script library in Dynamo. With these classes, users can create panel and centerline structures.

Panels

#Copyright(c) 2015, Nathan Miller
# The Proving Ground, http://theprovingground.org
 
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
 
# Panel division class
class PanelDivision:
 
    # DIAMOND DIVISION
    def DiamondDivision(self, srf, udiv, vdiv):
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
 
        quads = []
        polys = []
        panels = []
        for i in range(0,int(udiv+1)):
            for j in range(0,int(vdiv+1)):
                if (i+j)%2 == 0:
                    ptA = srf.PointAtParameter(0,0)
                    ptB = srf.PointAtParameter(0,0)
                    ptC = srf.PointAtParameter(0,0)
                    ptD = srf.PointAtParameter(0,0)
 
                    if i>0:
                        ptA = srf.PointAtParameter((i-1)*ustep,j*vstep)
                    else:
                        ptB = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if j>0:
                        ptB = srf.PointAtParameter(i*ustep,(j-1)*vstep)
                    else:
                        ptB = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if i<udiv:
                        ptC = srf.PointAtParameter((i+1)*ustep,j*vstep)
                    else:
                        ptC = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if j<=(vdiv -1):
                        ptD = srf.PointAtParameter(i*ustep,(j+1)*vstep)
                    else:
                        ptD = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if i>0 and j>0 and i<udiv and j<=(vdiv-1):
                        quad = []
                        #Append to quad
                        quad.append(ptA)
                        quad.append(ptB)
                        quad.append(ptC)
                        quad.append(ptD)
                        #Append quads
                        quads.append(quad)
 
                        #polygons
                        poly = Polygon.ByPoints(quad)
                        polys.append(poly)
 
                        #panels
                        panel = Surface.ByPerimeterPoints(quad)
                        panels.append(panel)
        self.quads = quads
        self.polys = polys
        self.panels = panels
 
    # DIAMOND EDGE DIVISION
    def DiamondEdgeDivision(self, srf, udiv, vdiv):
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
 
        quads = []
        polys = []
        panels = []
        for i in range(0,int(udiv+1)):
            for j in range(0,int(vdiv+1)):
                if (i+j)%2 == 0:
                    ptA = srf.PointAtParameter(0,0)
                    ptB = srf.PointAtParameter(0,0)
                    ptC = srf.PointAtParameter(0,0)
                    ptD = srf.PointAtParameter(0,0)
 
                    if i>0:
                        ptA = srf.PointAtParameter((i-1)*ustep,j*vstep)
                    else:
                        ptB = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if j>0:
                        ptB = srf.PointAtParameter(i*ustep,(j-1)*vstep)
                    else:
                        ptB = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if i<udiv:
                        ptC = srf.PointAtParameter((i+1)*ustep,j*vstep)
                    else:
                        ptC = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if j<=(vdiv -1):
                        ptD = srf.PointAtParameter(i*ustep,(j+1)*vstep)
                    else:
                        ptD = srf.PointAtParameter(i*ustep,j*vstep)
 
                    if i>0 and j>0 and i<udiv and j<vdiv:
                        quad = []
                    else:
                        if i==0 and j==0:
                            quad = []
                            #Append to quad
                            quad.append(ptB)
                            quad.append(ptC)
                            quad.append(ptD)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if i==0 and j==vdiv:
                            quad = []
                            #Append to quad
                            quad.append(ptB)
                            quad.append(ptC)
                            quad.append(ptD)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if i==udiv and j==0:
                            quad = []
                            #Append to quad
                            quad.append(ptC)
                            quad.append(ptD)
                            quad.append(ptA)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if i==udiv and j==vdiv:
                            quad = []
                            #Append to quad
                            quad.append(ptA)
                            quad.append(ptB)
                            quad.append(ptC)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if i == 0 and j > 0 and j < vdiv:
                            quad = []
                            #Append to quad
                            quad.append(ptB)
                            quad.append(ptC)
                            quad.append(ptD)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if i == udiv and j > 0 and j < vdiv:
                            quad = []
                            #Append to quad
                            quad.append(ptA)
                            quad.append(ptB)
                            quad.append(ptD)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if j == 0 and i > 0 and i < udiv:
                            quad = []
                            #Append to quad
                            quad.append(ptA)
                            quad.append(ptC)
                            quad.append(ptD)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
 
                        if j == vdiv and i > 0 and i < udiv:
                            quad = []
                            #Append to quad
                            quad.append(ptA)
                            quad.append(ptB)
                            quad.append(ptC)
                            #Append quads
                            quads.append(quad)
 
                            #polygons
                            poly = Polygon.ByPoints(quad)
                            polys.append(poly)
 
                            #panels
                            panel = Surface.ByPerimeterPoints(quad)
                            panels.append(panel)
        self.panels = panels
        self.quads = quads
        self.polys = polys
 
    # STAGGERED QUAD DIVISION
    def StaggeredQuadDivision(self, srf, udiv, vdiv):
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
 
        quads = []
        polys = []
        panels = []
        for i in range(0,int(udiv)):
            for j in range(0,int(vdiv)):
                # Condition 1
                if j%2 == 0:
                    ptA = srf.PointAtParameter(i*ustep,j*vstep)
                    ptB = srf.PointAtParameter((i+1)*ustep,j*vstep)
                    ptC = srf.PointAtParameter((i+1)*ustep,(j+1)*vstep)
                    ptD = srf.PointAtParameter(i*ustep,(j+1)*vstep)
 
                    quad = []
                    #Append to quad
                    quad.append(ptA)
                    quad.append(ptB)
                    quad.append(ptC)
                    quad.append(ptD)
                    #Append quads
                    quads.append(quad)
 
                    #polygons
                    poly = Polygon.ByPoints(quad)
                    polys.append(poly)
 
                    #panels
                    panel = Surface.ByPerimeterPoints(quad)
                    panels.append(panel)
 
                # Condition 2
                if j%2 == 1:
                    if i < (udiv-1):
                        ptA = srf.PointAtParameter((i+0.5)*ustep,j*vstep)
                        ptB = srf.PointAtParameter((i+1.5)*ustep,j*vstep)
                        ptC = srf.PointAtParameter((i+1.5)*ustep,(j+1)*vstep)
                        ptD = srf.PointAtParameter((i+0.5)*ustep,(j+1)*vstep)
 
                        quad = []
                        #Append to quad
                        quad.append(ptA)
                        quad.append(ptB)
                        quad.append(ptC)
                        quad.append(ptD)
                        #Append quads
                        quads.append(quad)
 
                        #polygons
                        poly = Polygon.ByPoints(quad)
                        polys.append(poly)
 
                        #panels
                        panel = Surface.ByPerimeterPoints(quad)
                        panels.append(panel)
 
                    # Condition 3
                    if i == 0:
                        ptA = srf.PointAtParameter(i*ustep,j*vstep)
                        ptB = srf.PointAtParameter((i+0.5)*ustep,j*vstep)
                        ptC = srf.PointAtParameter((i+0.5)*ustep,(j+1)*vstep)
                        ptD = srf.PointAtParameter(i*ustep,(j+1)*vstep)
 
                        quad = []
                        #Append to quad
                        quad.append(ptA)
                        quad.append(ptB)
                        quad.append(ptC)
                        quad.append(ptD)
                        #Append quads
                        quads.append(quad)
 
                        #polygons
                        poly = Polygon.ByPoints(quad)
                        polys.append(poly)
 
                        #panels
                        panel = Surface.ByPerimeterPoints(quad)
                        panels.append(panel)
 
                    # Condition 4
                    if i == udiv-1:
                        ptA = srf.PointAtParameter((i+0.5)*ustep,j*vstep)
                        ptB = srf.PointAtParameter((i+1)*ustep,j*vstep)
                        ptC = srf.PointAtParameter((i+1)*ustep,(j+1)*vstep)
                        ptD = srf.PointAtParameter((i+0.5)*ustep,(j+1)*vstep)
 
                        quad = []
                        #Append to quad
                        quad.append(ptA)
                        quad.append(ptB)
                        quad.append(ptC)
                        quad.append(ptD)
                        #Append quads
                        quads.append(quad)
 
                        #polygons
                        poly = Polygon.ByPoints(quad)
                        polys.append(poly)
 
                        #panels
                        panel = Surface.ByPerimeterPoints(quad)
                        panels.append(panel)
 
        self.quads = quads
        self.polys = polys
        self.panels = panels
 
    # TRIANGULAR DIVISION
    def TriDivision(self, srf, udiv, vdiv):
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
 
        tris = []
        polys = []
        panels = []
        for i in range(0,int(udiv)):
            for j in range(0,int(vdiv)):
 
                triA = []
                triB = []
 
                #XYZ Tris A
                myXYZ1A = srf.PointAtParameter(i*ustep, j*vstep)
                myXYZ1B = srf.PointAtParameter((i+1)*ustep,j*vstep)
                myXYZ1C = srf.PointAtParameter((i+1)*ustep,(j+1)*vstep)
 
                #XYZ Tris B
                myXYZ2A = srf.PointAtParameter((i+1)*ustep,(j+1)*vstep)
                myXYZ2B = srf.PointAtParameter(i*ustep,(j+1)*vstep)
                myXYZ2C = srf.PointAtParameter(i*ustep, j*vstep)
 
                #Append to tri
                triA.append(myXYZ1A)
                triA.append(myXYZ1B)
                triA.append(myXYZ1C)
 
                triB.append(myXYZ2A)
                triB.append(myXYZ2B)
                triB.append(myXYZ2C)
 
                #Append tris
                tris.append(triA)
                tris.append(triB)
 
                #Polygons
                polyA = Polygon.ByPoints(triA)
                polyB = Polygon.ByPoints(triB)
                polys.append(polyA)
                polys.append(polyB)
 
                #Panels
                panelA = Surface.ByPerimeterPoints(triA)
                panelB = Surface.ByPerimeterPoints(triB)
                panels.append(panelA)
                panels.append(panelB)
 
        self.tris = tris
        self.polys = polys
        self.panels = panels
 
    #QUAD PANEL DIVISION
    def QuadDivision(self, srf, udiv, vdiv):
        panels = []
        polys = []
        quads = []
 
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
        for i in range(0,int(udiv)):
            for j in range(0,int(vdiv)):
                quad = []
                #XYZ Quads
                myXYZA = srf.PointAtParameter(i*ustep, j*vstep)
                myXYZB = srf.PointAtParameter((i+1)*ustep,j*vstep)
                myXYZC = srf.PointAtParameter((i+1)*ustep,(j+1)*vstep)
                myXYZD = srf.PointAtParameter(i*ustep,(j+1)*vstep)
                #Append to quad
                quad.append(myXYZA)
                quad.append(myXYZB)
                quad.append(myXYZC)
                quad.append(myXYZD)
                #Append quads
                quads.append(quad)
 
                #polygons
                poly = Polygon.ByPoints(quad)
                polys.append(poly)
 
                #panels
                panel = Surface.ByPerimeterPoints(quad)
                panels.append(panel)
 
        self.quads = quads
        self.polys = polys
        self.panels = panels

Structure

#Copyright(c) 2015, Nathan Miller
# The Proving Ground, http://theprovingground.org
 
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
 
# Panel division class
class CenterlineDivision:
 
    # BRACED 1D GRID
    def BracedGrid1dDivision(self, srf, udiv, vdiv):
        lnsA = []
        lnsB = []
        lnsC = []
 
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
        for i in range(0,int(udiv)+1):
            for j in range(0,int(vdiv)+1):
                lnB = []
                lnA = []
                lnC = []
 
                ptA = srf.PointAtParameter(i*ustep, j*vstep)
                if i<udiv:
                    ptB = srf.PointAtParameter((i+1)*ustep, j*vstep)
                    lnA.append(ptA)
                    lnA.append(ptB)
 
                    ln = Line.ByBestFitThroughPoints(lnA)
                    lnsA.append(ln)
                if j<vdiv:
                    ptB = srf.PointAtParameter(i*ustep, (j+1)*vstep)
                    lnB.append(ptA)
                    lnB.append(ptB)
 
                    ln = Line.ByBestFitThroughPoints(lnB)
                    lnsB.append(ln)
                if i<udiv and j<vdiv:
                    bptA = srf.PointAtParameter(i * ustep, j * vstep)
                    bptB = srf.PointAtParameter((i + 1) * ustep, (j + 1) * vstep)
                    lnC.append(bptA)
                    lnC.append(bptB)
 
                    ln = Line.ByBestFitThroughPoints(lnC)
                    lnsC.append(ln)
 
        self.lnsA = lnsA
        self.lnsB = lnsB
        self.lnsC = lnsC
 
    # BRACED 2D GRID DIVISION
    def BracedGrid2dDivision(self, srf, udiv, vdiv):
        lnsA = []
        lnsB = []
        lnsC = []
 
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
        for i in range(0,int(udiv)+1):
            for j in range(0,int(vdiv)+1):
 
                ptA = srf.PointAtParameter(i*ustep, j*vstep)
                if i<udiv:
                    ptB = srf.PointAtParameter((i + 1) * ustep, j * vstep)
                    ln = Line.ByStartPointEndPoint(ptA, ptB)
                    lnsA.append(ln)
                if j < vdiv:
                    ptB = srf.PointAtParameter(i * ustep, (j + 1) * vstep)
                    ln = Line.ByStartPointEndPoint(ptA,ptB)
                    lnsB.append(ln)
 
                if i<udiv and j<vdiv:
                    bptA = srf.PointAtParameter(i * ustep, j * vstep)
                    bptB = srf.PointAtParameter((i + 1) * ustep, j * vstep)
                    bptC = srf.PointAtParameter((i + 1) * ustep, (j + 1) * vstep)
                    bptD = srf.PointAtParameter(i * ustep, (j + 1) * vstep)
                    mpt = srf.PointAtParameter((i * ustep) + (0.5 * ustep), (j * vstep) + (0.5 * vstep))
 
                    blnA = Line.ByStartPointEndPoint(bptA, mpt)
                    blnB = Line.ByStartPointEndPoint(bptB, mpt)
                    blnC = Line.ByStartPointEndPoint(bptC, mpt)
                    blnD = Line.ByStartPointEndPoint(bptD, mpt)
 
                    lnsC.append(blnA)
                    lnsC.append(blnB)
                    lnsC.append(blnC)
                    lnsC.append(blnD)
 
        self.lnsA = lnsA
        self.lnsB = lnsB
        self.lnsC = lnsC
 
    # DIAGRID DIVISION
    def DiagridDivision(self, srf, udiv, vdiv, bool):
        lns = []
 
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
 
        for i in range(0,int(udiv)+1):
            for j in range(0,int(vdiv)+1):
 
                if (i+j)%2 == bool and i<udiv:
                    ptA = srf.PointAtParameter(i*ustep, j*vstep)
                    if j>0:
                        ptB = srf.PointAtParameter((i+1)*ustep,(j-1)*vstep)
                        ln = Line.ByStartPointEndPoint(ptA, ptB)
                        lns.append(ln)
                    if j<vdiv:
                        ptB = srf.PointAtParameter((i+1)*ustep,(j+1)*vstep)
                        ln = Line.ByStartPointEndPoint(ptA,ptB)
                        lns.append(ln)
        self.lns = lns
 
    # GRID DIVISION
    def GridDivision(self, srf, udiv, vdiv):
        lnsA = []
        lnsB = []
 
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
 
        for i in range(0,int(udiv)+1):
            for j in range(0,int(vdiv)+1):
                lnB = []
                lnA = []
 
                ptA = srf.PointAtParameter(i*ustep, j*vstep)
                if i<udiv:
                    ptB = srf.PointAtParameter((i+1)*ustep, j*vstep)
                    lnA.append(ptA)
                    lnA.append(ptB)
 
                    ln = Line.ByBestFitThroughPoints(lnA)
                    lnsA.append(ln)
                if j<vdiv:
                    ptB = srf.PointAtParameter(i*ustep, (j+1)*vstep)
                    lnB.append(ptA)
                    lnB.append(ptB)
                    ln = Line.ByBestFitThroughPoints(lnB)
                    lnsB.append(ln)
        self.lnsA = lnsA
        self.lnsB = lnsB
 
    # SPACE TRUSS DIVISION
    def SpaceTrussDivision(self, srf, udiv, vdiv, depth):
        lnsA = []
        lnsB = []
        lnsC = []
        lnsD = []
        lnsE = []
 
        ustep = 1.0/udiv
        vstep = 1.0/vdiv
        oset = srf.Offset(depth)
        for i in range(0,int(udiv)+1):
            for j in range(0,int(vdiv)+1):
 
                ptA = srf.PointAtParameter(i*ustep, j*vstep)
                if i<udiv:
                    ptB = srf.PointAtParameter((i + 1) * ustep, j * vstep)
                    ln = Line.ByStartPointEndPoint(ptA, ptB)
                    lnsA.append(ln)
                if j < vdiv:
                    ptB = srf.PointAtParameter(i * ustep, (j + 1) * vstep)
                    ln = Line.ByStartPointEndPoint(ptA,ptB)
                    lnsB.append(ln)
 
                if i<udiv and j<vdiv:
                    lptA = oset.PointAtParameter((i * ustep) + (0.5 * ustep), (j * vstep) + (0.5 * vstep))
                    if i<(udiv-1):
                        lptB = oset.PointAtParameter(((i + 1) * ustep) + (0.5 * ustep), (j * vstep) + (0.5 * vstep))
                        ln = Line.ByStartPointEndPoint(lptA, lptB)
                        lnsC.append(ln)
                    if j<(vdiv-1):
                        lptB = oset.PointAtParameter((i * ustep) + (0.5 * ustep), ((j + 1) * vstep) + (0.5 * vstep))
                        ln = Line.ByStartPointEndPoint(lptA, lptB)
                        lnsD.append(ln)
 
                    bptA = srf.PointAtParameter(i * ustep, j * vstep)
                    bptB = srf.PointAtParameter((i + 1) * ustep, j * vstep)
                    bptC = srf.PointAtParameter((i + 1) * ustep, (j + 1) * vstep)
                    bptD = srf.PointAtParameter(i * ustep, (j + 1) * vstep)
                    mpt = oset.PointAtParameter((i * ustep) + (0.5 * ustep), (j * vstep) + (0.5 * vstep)) 
 
                    blnA = Line.ByStartPointEndPoint(bptA, mpt)
                    blnB = Line.ByStartPointEndPoint(bptB, mpt)
                    blnC = Line.ByStartPointEndPoint(bptC, mpt)
                    blnD = Line.ByStartPointEndPoint(bptD, mpt)
 
                    lnsE.append(blnA)
                    lnsE.append(blnB)
                    lnsE.append(blnC)
                    lnsE.append(blnD)
 
        self.lnsA = lnsA
        self.lnsB = lnsB
        self.lnsC = lnsC
        self.lnsD = lnsD
        self.lnsE = lnsE
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License