Forgot password?

Create an account!


« back

RhinoScript – Export to Excel


Please log in to write a message.

  • 6. Arrow.111 (Jul 16, 2011 23.18):

    Dear KSchillaci, do you have any positive result with this script? Are you able to share it?

  • 5. KSchillaci (Jun 29, 2011 19.16):

    It is a collection of points in the layer yes. That works but when I add it to the excel It is only exporting one value for x,y, and z and putting that value in all the respective boxes.

    For i = 0 To Ubound(arrDeadAnts)
                    arrPoint(i) = PointCoordinates(arrDeadAnts(i))
                            objXL.Cells(intIndex, 1).Value = arrPoint(0)
                            objXL.Cells(intIndex, 2).Value = arrPoint(1)
                            objXL.Cells(intIndex, 3).Value = arrPoint(2)
                            intIndex = intIndex + 1
  • 4. Johannes (Jun 29, 2011 18.54):

    which kind of objects are on the layer you get arrDeadAnts from?
    the function Rhino.PointCoordinates requires a string (the identifier of one point). you need to collect the coordinates in a loop structure into an array if you have a collection of points on that layer.

    Dim i
    ReDim arrPoint(Ubound(arrDeadAnts))

    For i = 0 to Ubound(arrDeadAnts)
    arrPoint(i) = PointCoordinates(arrDeadAnts(i))


  • 3. KSchillaci (Jun 29, 2011 18.39):

    I see what you are saying. I want arrPoint to contain all the Point coordinates for the Points on the strDeadAnts layer. Those x,y,z coordinates are what I want to export to excel.

    I changed the variables around saying arrPoint = PointCoordinates(arrDeadAnts)
    to get the point coordinates of the objects. However it requires a string. So i tried Rhino.Pt2Str(arrDeadAnts) but this is not a one-dimensional array.

    A little confused as to the right way to format this.

  • 2. Johannes (Jun 29, 2011 17.15):


    what do you expect in arrPoint? take a look on line 37 -44.

    strDeadAnts = LayerName
    arrDeadAnts = Objects on that Layer (ID)
    arrPoint = PointCoordinates from the Layername ????

    For Each strDeadAnts(before Layername) In arrPoint(nothing) ????

    there is something messed up.

  • 1. KSchillaci (Jun 29, 2011 13.20):

    I am trying to export a set of Point Coordinates to excel and I cant figure out why it is failing. The issue is line 79 where it and the message reads strDeadAnts not a collection?

    Any help is appreciated.

    Option Explicit
    'Script written by <Kyle Schillaci>
    'Script copyrighted by <Kyle Schillaci>
    'Script version Thursday, 16 June 2011 11:31:11

    Call Main()
    Sub Main()
            'Insert Data Plot constraints as Polygon/Curve
            Dim Surface
            Dim PlotConstraints : PlotConstraints=Rhino.GetObjects("select polygon for Plot Constraints ",4)
            If isNull (PlotConstraints) Then Exit Sub
            'Convert Plot to Planar Surface
            Dim PlotSurface,arrCenter
            PlotSurface = Rhino.AddPlanarSrf(PlotConstraints)
            arrCenter = Rhino.SurfaceAreaCentroid(PlotSurface(0))
            If IsArray(arrCenter) Then
                    Rhino.AddPoint arrCenter(0)
            End If
            Dim strTrailLayer : strTrailLayer = Rhino.GetLayer("Pick Trail Layer")
            Dim VisLayer : VisLayer = Rhino.LayerVisible(strTrailLayer,True)
            Dim x  : x = Rhino.GetInteger("Number of Trails: ")
            Dim arrPoints,i,arrTrails,j
            ReDim arrPoints(x-1) 'Total Number of Trails
            For i = 0 To x-1                'For first value in array to Total number of trails, get objects.
                    arrPoints(i) = Rhino.GetPoints(True, True, "Select Points for Trail " & i)
                    arrTrails = Rhino.addinterpcurve(arrPoints(i))
            VisLayer = Rhino.LayerVisible(strTrailLayer,False)
            Dim strDeadAnts, arrDeadAnts,SelectAnts
            strDeadAnts = Rhino.GetLayer("Choose Dead Ant Layer")
            Dim VisLayerAnts : VisLayerAnts = Rhino.LayerVisible(strDeadAnts,True)
            arrDeadAnts = Rhino.ObjectsByLayer(strDeadAnts)
            Dim arrPoint,arrDist
            arrPoint = Rhino.PointCoordinates(strDeadAnts) 
            Call ExportPointsToExcel(arrPoint,strDeadAnts)
            'Write a Function for Changing the Spore Count?
    End Sub

    Function ExportPointsToExcel(ByVal arrPoint, ByVal strDeadAnts)
            Const rhPoint = 1
            Dim objXL
            Set objXL = CreateObject("Excel.Application")
            objXL.Visible = True
            objXL.Columns(1).ColumnWidth = 20
            objXL.Columns(2).ColumnWidth = 20
            objXL.Columns(3).ColumnWidth = 20
            objXL.Cells(1, 1).Value = "X"
            objXL.Cells(1, 2).Value = "Y"
            objXL.Cells(1, 3).Value = "Z"
            objXL.Selection.Font.Bold = True
            objXL.Selection.Interior.ColorIndex = 1
            objXL.Selection.Interior.Pattern = 1 'xlSolid
            objXL.Selection.Font.ColorIndex = 2
            objXL.Selection.HorizontalAlignment = &hFFFFEFDD ' xlLeft

            Dim intIndex
            intIndex = 2
            Dim arrPt
            For Each strDeadAnts In arrPoint
                    arrPoint = Rhino.PointCoordinates(strDeadAnts)
                    objXL.Cells(intIndex, 1).Value = arrPt(0)
                    objXL.Cells(intIndex, 2).Value = arrPt(1)
                    objXL.Cells(intIndex, 3).Value = arrPt(2)
                    intIndex = intIndex + 1
            objXL.UserControl = True
    End Function


Why are these buttons gray?