Grasshopper

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

Views: 1161

Replies to This Discussion

It seams as though somewhere along they way GH's compilation process got a bit more "finicky" about some of the "loose" calls that were typical of the initial way that I resolved the Excel connection way back when.  Basically, some of those instances that you're dealing with in your code are typed as Objects and don't have any specific methods exposed.  They are the correct COM object underneath, but you have to do a bit of casting to get the object as the necessary type to be able to call the appropriate methods.  This does require jumping through a few hoops to get this done correctly.  I'll forward you some PMs that I exchanged with another user on this not too long ago.

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.

 

 

Same issue here.  Damien, did you post your solution somewhere?

 

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.  

 

http://neoarchaic.net/2011/01/gh-excel-suite/

 

Thanks, I will look into that, because I'm actually still getting some strange behavior (i.e., not working with no error messages) in some of my usages but not others...

 

Marc

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service