algorithmic modeling for Rhino
Hi guys,
I have a VB script I've been using for a while, and just recently it stopped working. Last working configuration was Rhino 5, GH 0.8.0007, Kangaroo 0051, Excel 2010. I upgraded the Rhino 5 beta version today and kangaroo to a new beta version. Somewhere in there the VB script stopped working, with the following error:
error: Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) (line:0)
Any ideas?
VB Script is as follows:
Dim xlApp As Object
    Dim CellValues As New List(Of Object)
    Dim CellColorsInt As New List(Of Integer)
    Dim CellColorsOnColor As New List(Of OnColor)
    Dim i As Int32
    Dim RowRange As Int32
    RowRange = (ERow - SRow)
    'Grab a running instance of Excel
    xlApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
    'Some error checking...in case Excel isn't running
    If IsNothing(xlApp) Then Exit Sub
    'In order to access the data into Excel you have to navigate through
    'its object heirarchy.  Getting the Application is just the first step.
    'After that you need to achieve a workbook (typically the active one, or you
    'could open one if you knew which one you needed...watch out with that though).
    'Once you have the workbook, you will need to retrieve a sheet so that you can begin
    'to read or write data to it.
    'getting the workbook is best done through getting ActiveWorkbook method
    Dim wb As Object = xlApp.ActiveWorkbook
    If IsNothing(wb) Then Exit Sub
    'Getting the sheet is best done through the ActiveSheet method
    Dim sheet As Object = wb.ActiveSheet
    If IsNothing(sheet) Then Exit Sub
    For i = 0 To RowRange
      CellValues.Add(sheet.Cells(SRow + i, Column).Value)
      'CellColors.Add(xlApp.Worksheets(1).Cells(SRow + i, Column).Interior.Color)
      'Print("colR = {0}", colR(i * ColumnRange + j))
      'If you want to get the colors, that's fine, but they will get kicked
      'back as an integer, which isn't very useful within GH.
      'This is how you were getting them before...the integer list
      CellColorsInt.Add(sheet.Cells(SRow + i, Column).Interior.color)
      'This is how to translate those to an OnColor...
      'get the integer version of the color first.
      Dim intCellColor As Integer
      intCellColor = sheet.Cells(SRow + i, Column).Interior.color
      CellColorsInt.Add(intCellColor)
      'Use the Color translator to get a system.drawing color, which
      'can be used within the OnColor constructor
      Dim OnColorCellColor As New OnColor(System.Drawing.ColorTranslator.FromWin32(intCellColor))
      CellColorsOnColor.Add(OnColorCellColor)
    Next
    val = CellValues
    col = CellColorsOnColor
    colInt = CellColorsInt
  End Sub
Tags:
Thanks Damien,
Hopefully I will be able to decipher the IMs and manage to implement the changes. I'm not a .NET master like yourself and many others on this forum, I tend to cobble things together laboriously. :P
Wish there was a good way to learn .NET. I still have not found even a decent primer that explains the differences between methods, classes, etc. You'd think that would be simple to find, but alas... all I can seem to find is a million tutorials on how to make a "Hello, World!" windows application. Boo.
Daniel --
It turns out that I was running a second instance of Rhino 5 in the background that was in the Open Template dialog state. After quitting all instances and restarting, my problem went away. Don't know if this was just a fluke, but perhaps you have something funny going on as well, such as Rhino 4 and 5 open at the same time with 2 instances of GH running, or something like that. Check it out. Otherwise, I never heard from Damien regarding casting...
Marc
There is a very thorough example here that works well and appears to do some strange things (to me) with casting etc.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
    © 2025               Created by Scott Davidson.             
    Powered by