Grasshopper

algorithmic modeling for Rhino

Is it possible within grasshopper to create or access variables through a string? In other languages/applications I'd use eval() and it would look something like this.


 Private Sub RunScript(ByVal x As List(Of Integer), ByRef A As Object, ByRef B As Object)
 
   Dim intlist0 As New List(Of Integer), intlist1 As New List(Of Integer)
   Dim modval As Integer

    For Each val As Integer In x
      modval = val Mod 2
      Dim varStr As String = "intlist" & modval

      Eval(varStr + ".add(" + val + ")")
    Next

    a = intlist0
    b = intlist1

---
or
---

For i as Integer =0 to 100
Eval("dim varName" + i + " as new On3dPoint")
Next

What I've been able to find online suggests probably not... but maybe

Views: 296

Replies to This Discussion

Eval() is the hallmark of an interpreter. DotNET code is compiled, not interpreted (not yet at least, the Microsoft C# and VB DLR is still in early beta stages).

I actually do this with VB Scripts in Grasshopper, but it's not particularly easy. You have to build completely correct source code, then compile it into a dll using the DotNET VB or C# compiler (they ship with the framework), then load the dll and call into it.

It's not a particularly quick way of running code, unless you know that you only have to compile once for multiple calls.

If you're looking to evaluate simple expressions, you can use the Grasshopper Expression Parser (Grasshopper.Kernel.Expressions namespace). But it supports only a few variable types and functions.

--
David Rutten
david@mcneel.com
Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service