Forgot password?

Create an account!


« back

RhinoScript – Help with a script for Rhino


Please log in to write a message.

  • 3. Charly (Nov 02, 2015 16.08):

    Thank you for you help Seba, it works perfectly!! Thank you very much

  • 2. pulgarata (Oct 30, 2015 14.16):

    Hi Charly,
    To print each coordinate in a different column you have to replace this lines:

    xlApp.Cells(j + 2, 3).value = strcoord
    xlApp.Cells(j + 2, 4).value = strcoord
    xlApp.Cells(j + 2, 5).Value = strcoord

    with this:

    xlApp.Cells(j + 2, 3).value = arrcoord(0)(0)
    xlApp.Cells(j + 2, 4).value = arrcoord(0)(1)
    xlApp.Cells(j + 2, 5).Value = arrcoord(0)(2)

    Do you need print all the information in only one excel file?
    If you want this, you have to put out of the "For-Next" bucle all the lines about the xls file.



  • 1. Charly (Oct 30, 2015 13.20):

    Hello all,

    I write because I need help with a script that I'm making for Rhino. The script calculates de area of the elements of each layer and print them into an excel file. It is necesary to have openned an Excel file previously. It works without problems, but I want to improve it making the following actions:

    -The script must open an Excel file automatically, and must ask where we want to save it (the excel file).
    -The script prints the x,y,z coordinates ot the centroid of each surface in an only column, but it should printe each coordinate in a differente column (a column for the "x" coordinate, another for the "y" and another for the "z").

    The script is the following. Please, could you help me with the two improvements that I need to make? Thank you a lot

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version sábado, 26 de mayo de 2012 12:16:58

    Call Main()
    Sub Main()
    Dim capas,numcapas,strlayer,arrobj,strobject,arrarea,strarea,arrcoord,strcoord,j,xlapp,xlsheet,xlbook,arrlobjects,centroidlayer,layercoord
    capas = rhino.LayerNames
    numcapas = rhino.LayerCount
    j = 0

    For Each strlayer In capas
    Rhino.CurrentLayer strLayer

    ' If Not isnull (centroidlayer) Then
    ' layercoord=rhino.Pt2Str(centroidlayer(0))
    ' End If

    'RHINO.Print strLayer
    If Not Rhino.IsLayerEmpty(strLayer) Then

    arrobj = rhino.objectsbylayer(strlayer, False)
    For Each strobject In arrobj
    arrarea = rhino.SurfaceArea(strobject)
    If Not IsNull(arrarea) Then
    strarea = rhino.Pt2Str(arrarea)
    End If
    arrcoord = rhino.SurfaceAreaCentroid(strobject)
    If Not isnull(arrcoord) Then
    strcoord = rhino.Pt2Str(arrcoord(0))
    End If

    ' rhino.print(strcoord)
    ' Open Excel object
    On Error Resume Next
    Set xlApp = GetObject(, "excel.application")
    If err Then
    Rhino.print "Excel not found. Operation aborted!"
    Exit Sub
    End If
    On Error GoTo 0
    xlApp.Visible = True

    Set xlBook = xlApp.ActiveWorkbook
    Set xlSheet = xlBook.ActiveSheet

    'Place titles on sheet
    xlApp.Cells(1, 1).Value = "CAPA"
    xlApp.Cells(1, 2).Value = "Surface Area"
    xlApp.Cells(1, 3).Value = "X centroide"
    xlApp.Cells(1, 4).value = "Y centroide"
    xlApp.Cells(1, 5).value = "Z centroide"
    xlApp.Cells(1, 6).Value = "Centroide Global por Capa"

    'Extract Properties of Surfaces
    xlApp.Cells(j + 2, 1).Value = strlayer
    xlApp.Cells(j + 2, 2).Value = arrarea
    xlApp.Cells(j + 2, 3).value = strcoord
    xlApp.Cells(j + 2, 4).value = strcoord
    xlApp.Cells(j + 2, 5).Value = strcoord

    j = j + 1

    'xlApp.Quit ' If closing excel is required
    Set xlApp = Nothing ' the application, then release the reference.
    End If
    End Sub


Why are these buttons gray?