Birmingham City University (Carys)

  • anchor

    Truss Script (Peter Jenkins)

    By Birmingham City Uni D7
    Mar 11, '10 5:38 PM EST

    I had one person who was interested in my automatic trussing script from the previous post, so I'll post it below.

    It's for Rhino, so the language is pretty much VisualBasic. Please not that, in my experience, copying and pasting code from blogs often results in syntax errors, particularly with punctuation characters (e.g. quotation marks get all messed up). This script definitely works, so if it doesn't work, it'll be simple character fixes rather than real code flaws.

    Option Explicit
    'Base triangulation script written by
    'Edited for 2 surfaces, cross-trussing and changeable U & V values by Peter Jenkins

    Call srfPanelsTriangles()

    Sub srfPanelsTriangles()

    Dim strSrf1 : strSrf1 = Rhino.GetObject("First surface object please", 8)
    If IsNull(strSrf1) Then Exit Sub

    Dim strSrf2 : strSrf2 = Rhino.GetObject("Second one please", 8)
    If IsNull(strSrf2) Then Exit Sub

    Dim numUSpans : numUSpans = Rhino.GetInteger("How many surface spans in U direction", 15, 6, 50)
    If IsNull(numUSpans) Then Exit Sub

    Dim numVSpans : numVSpans = Rhino.GetInteger("And in V direction", 15, 6, 50)
    If IsNull(numVSpans) Then Exit Sub

    Rhino.print "Yeeeeeeeah Boi!!!"
    Rhino.enableRedraw False

    ' Get U vals
    Dim arrSrfDomU1 : arrSrfDomU1 = Rhino.SurfaceDomain(strSrf1,0)
    Dim uMin1 : uMin1 = arrSrfDomU1(0)
    Dim uMax1 : uMax1 = arrSrfDomU1(1)
    Dim uStep1 : uStep1 = (uMax1-uMin1) / numUSpans

    Dim arrSrfDomU2 : arrSrfDomU2 = Rhino.SurfaceDomain(strSrf2,0)
    Dim uMin2 : uMin2 = arrSrfDomU2(0)
    Dim uMax2 : uMax2 = arrSrfDomU2(1)
    Dim uStep2 : uStep2 = (uMax2-uMin2) / numUSpans

    ' Get V vals
    Dim arrSrfDomV1 : arrSrfDomV1 = Rhino.SurfaceDomain(strSrf1,1)
    Dim vMin1 : vMin1 = arrSrfDomV1(0)
    Dim vMax1 : vMax1 = arrSrfDomV1(1)
    Dim vStep1 : vStep1 = (vMax1-vMin1) / numVSpans

    Dim arrSrfDomV2 : arrSrfDomV2 = Rhino.SurfaceDomain(strSrf2,1)
    Dim vMin2 : vMin2 = arrSrfDomV2(0)
    Dim vMax2 : vMax2 = arrSrfDomV2(1)
    Dim vStep2 : vStep2 = (vMax2-vMin2) / numVSpans

    ' Create nodes
    Dim i,j,l
    Dim k : k = uMin2
    Dim arr1EvalPt01, arr1EvalPt02, arr1EvalPt03, arr1EvalPt04, arr1EvalPt05, arr1EvalPt06, arrCnrPts
    Dim arr2EvalPt01, arr2EvalPt02, arr2EvalPt03, arr2EvalPt04, arr2EvalPt05, arr2EvalPt06

    For i = uMin1 To uMax1 Step uStep1

    l = vMin2

    For j = vMin1 To vMax1 Step vStep1

    ' Triangulating first points on surfaces
    arr1EvalPt01 = Rhino.EvaluateSurface( strSrf1, Array(i,j) )
    arr1EvalPt02 = Rhino.EvaluateSurface( strSrf1, Array(i,j+vStep1) )
    arr1EvalPt03 = Rhino.EvaluateSurface( strSrf1, Array(i+uStep1,j) )

    arr2EvalPt01 = Rhino.EvaluateSurface( strSrf2, Array(k,l) )
    arr2EvalPt02 = Rhino.EvaluateSurface( strSrf2, Array(k,l+vStep2) )
    arr2EvalPt03 = Rhino.EvaluateSurface( strSrf2, Array(k+uStep2,l) )

    ' create surface triangles
    ' first surface
    Call Rhino.AddLine(arr1EvalPt01, arr1EvalPt02)
    Call Rhino.AddLine(arr1EvalPt01, arr1EvalPt03)
    Call Rhino.AddLine(arr1EvalPt03, arr1EvalPt02)

    ' second surface
    Call Rhino.AddLine(arr2EvalPt01, arr2EvalPt02)
    Call Rhino.AddLine(arr2EvalPt01, arr2EvalPt03)
    Call Rhino.AddLine(arr2EvalPt03, arr2EvalPt02)

    ' create trusses between surfaces
    Call Rhino.AddLine(arr1EvalPt01, arr2EvalPt01)
    Call Rhino.AddLine(arr1EvalPt01, arr2EvalPt02)
    Call Rhino.AddLine(arr1EvalPt01, arr2EvalPt03)

    l = l + vStep2

    Next ' end j loop

    k = k + uStep2

    Next ' end i loop

    Rhino.enableRedraw True
    Rhino.print "!!! SCRIPT COMPLETED !!!"

    End Sub

    • 1 Comment

    • jacob

      I always enjoy the personal touch each coder put in his script.

      (re: Yeeeeeeeeeeeah Boi!)

      Mar 12, 10 10:28 pm

      Block this user

      Are you sure you want to block this user and hide all related comments throughout the site?

    • Back to Entry List...
  • ×Search in:

Affiliated with:

Authored by:

  • Birmingham City Uni D7

Other blogs affiliated with Birmingham City University:

Recent Entries