Grasshopper

algorithmic modeling for Rhino

I'm trying to create an application for non-grasshopper users and want to minimize the installation process.  So I'd like to limit myself to using grasshopper and python and allow users to provide input from an excel form I develop.  

If I'm using incorrect terminology please correct, I'm still relatively new to grasshopper and python.  Trying to use the .NET COM interop facilities as described in the link below I'm unable to figure out how to update based on the SheetChange event.

http://www.ironpython.info/index.php?title=Interacting_with_Excel#F...

Below is a generic version of what I'm working with that should print the value in cell "A1" of the active worksheet in the active workbook.

Any insight is appreciated.

import clr
clr.AddReference("Microsoft.Office.Interop.Excel")

from System.Runtime.InteropServices import Marshal

excel = Marshal.GetActiveObject("Excel.Application")

workbook = excel.ActiveWorkbook

def onSheetChange():
    print workbook.ActiveSheet.Range["a1"].Value2

Excel.WorkbookEvents_Event.add_SheetChange(workbook,onSheetChange)

Views: 1761

Replies to This Discussion

Jason I don't know how to use the Interop, which I imagine would be easier to do in C#, but there are a few python libraries which read excel files. http://www.python-excel.org/ this will get you going... the later versions may not work with IronPython.

Another approach is to use csv's, which can still be opened and edited like an excel sheet, and then read in fairly easily. https://docs.python.org/2/library/csv.html

The last approach, if you need to get something working quickly, is to use one of the few components already written for reading/writing to excel sheets. I'm currently doing this on a project, and will someday implement my own reader. It is not a bad idea though to do it this way because you get some time to see exactly how you want to format the incoming data.


I hope this helps somewhat. There are others who are better versed, but this may help get you started.

Thank you both for responding.  I've been using the GHexcel component to move beyond this issue and set things up downstream.  Is there a way to peak inside such components and view the solution? I'd prefer to learn and come up with a home cooked solutions where reasonable.  For now I might explore VB.net and see where it takes me.  I'm not really clear yet on the idea of memory leaks or registering/unregistering events if there is anything you can recommend to help clarify the topic. 

Are there any resources you recommend for vb specific to grasshopper and custom gh components?  I have some past experience in VB so wouldn't be starting from scratch.

* switch to c# or vb and create a custom component within vs -> use the gh template and follow the excel examples on msdn.com, override AddedToDocument/RemovedFromDocument - and register there..

There are multiple plug-ins for Grasshopper that already do what you are asking for. Try downloading TT Lunchbox or David Mans' Bumblebee. 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service