'Here you set the name of the file which it will be saved laterDim NombreArchivo
NombreArchivo = Rhino.SaveFileName("Exportar", "Archivo Excel (*.xlsx)|*.xlsx||")IfIsNull(NombreArchivo)ThenExitSub

'With this lines it opens an excel file and it creates a new bookSet xlApp = CreateObject("excel.application")Set xlBook = xlApp.Workbooks.AddSet xlSheet = xlBook.ActiveSheet

For Each strlayer In capas
Rhino.CurrentLayer strLayer'-------------------------------------'FALTA INVESTIGAR-CONSEGUIR CENTROIDE DE VARIAS SURF A LA VEZ'arrlobjects=rhino.ObjectsByLayer(strlayer,False)'h=rhino.SelectObjects(arrlobjects)'centroidlayer=rhino.SurfaceAreaCentroid(h)

' If Not isnull (centroidlayer) Then' layercoord=rhino.Pt2Str(centroidlayer(0))' End If'--------------------------------------IfNot Rhino.IsLayerEmpty(strLayer)Then

I'm working on the following script for Rhino. The script should calculate the areas of the element in each layer, and export these areas and its coordinates into an Excel file. It also should open a blanc Excel file and ask you where do you want to sabe it. It works more or less, but it has many errors.
-The first is that if there is any other Excel file opened in the computer, it doesn't work, so it's necesary to close all the Excel files before.
-The second problema is that if there is more than one element in a layer, it prints the properties of these areas separately in the Excel file, but the objective is that it prints the "total" area in each layer.

The script is the following. Could anyone give a helping hand to me? Thank you very much

Charly

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

' 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)
Else
Rhino.DeleteObject(strObject)
End If
'rhino.print(strarea)
arrcoord = rhino.SurfaceAreaCentroid(strobject)
If Not isnull(arrcoord) Then
strcoord = rhino.Pt2Str(arrcoord(0))
End If

'xlApp.Quit ' If closing excel is required
Set xlApp = Nothing ' the application, then release the reference.
'---------------------------------------------------------------
Next
End If
Next
rhino.Print("FINISH!!!")
End Sub