Grasshopper

algorithmic modeling for Rhino

Hi everyone-

I'm using GUID's stored as strings in Excel to manage a really big project, which can't all fit in a single definition.  Basically, I'm using Excel to retain information about each object (tree info, relationships to certain other objects, etc.) after it's been baked, so that our team can hand tool some of the results, delete certain objects, etc.  I'm using the doc.objects.find(guid) function right now - which works fine when I feed a string into the VB component and set the input as a GUID, but am having a hard time casting my strings from Excel into the GUID directly in the VB component.  Hopefully it's easy to do and I can whack my palm on my face, as often I do.  Here's my script...I get the "specified cast is not valid" error at: Dim obj As Guid = xlSheet.Range(strGUIDColumn & I).Value.

 

If activate = True Then


      Dim xlApp, xlSheet As Object      

xlApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
Dim strSheet As String = "MEM_6"      

Dim strGUIDColumn As String = "C"      

Dim strDeleteColumn As String = "F"

Dim intCheck As Int16 = xlApp.Worksheets("META").Range("B4").Value

Dim I As Int16

xlSheet = xlApp.Worksheets(strSheet)

 

For I = 2 To intCheck + 1


Dim obj As Guid = xlSheet.Range(strGUIDColumn & I).Value <- returns my casting error

If doc.Objects.Find(obj) Is Nothing Then

xlSheet.Range(strDeleteColumn & I).Value = "X"        

End If


Next

 

End If

 

thanks!

Views: 972

Replies to This Discussion

Hi Dave, there's a guid constructor that takes a string as an argument, as an example

 

Dim obj as Guid = new System.Guid("{1B7C5769-8A1D-4f27-96D1-633539C29900}")

(or similar) should work.

 

Cheers,

Jon

Got it!  fantastic.  What's interesting as well is that I can't reference the string directly from Excel as I was doing above (gives me an overload/narrowing conversion error).  But if I create a distinct string variable and populate it first, then feed it into the GUID, it works fine.  Here's the full fix:

 

Dim strGUID As String = xlSheet.Range(strGUIDColumn & I).Value

Dim obj As guid = New System.Guid(strGUID)

 

If doc.Objects.Find(obj) Is Nothing Then 

xlSheet.Range(strDeleteColumn & I).Value = "X"

End If

 

Thanks again!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service