Grasshopper

algorithmic modeling for Rhino

Is there a way to declare global variables to the VBScript button in grasshopper? Or we just have to use argument to call all the variables in a class??

Views: 8903

Replies to This Discussion

Hi Khizer,

 

I'm not entirely sure what you're after, but you can put static variables inside the RunScript method. The value assigned to these variables will persist between subsequent calls to RunScript:

 

Static m_data As List(Of Double)

If (m_data Is Nothing) Then m_data = New List(Of Double)

m_data.Add(x)

 

 

You can also put variables in the class body, rather than the RunScript body. This means they'll be accessible from all functions inside the Script_Instance class. You'll need to put these additional code block:

 

'<Custom additional code>

Private m_data As New List(Of Double)

'</Custom additional code>

 

If you have a lot of data that 'belongs' together, I recommend you write a small class or structure that encapsulates it:

 

'<Custom additional code>

Public Class MySpecialData

  Public m_data As New List(Of Double)

  Public m_name As String

  Public m_index As Int32

  Public m_offset As Double

  Public m_shape As Rhino.Geometry.Brep

End Class

...

'</Custom additional code>

 

Put this class in the additional block and you can use it inside all the functions within the Script_Instance class.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Well by global, i meant variables that can be used in Run-Script and in class body both... actually the problem i am having,are the values from slider in grasshopper, like xaxis,yaxis, RndmSeeder, when are put to VB-Script, they are declared in Run-Script, thus when making classes it was hard to call them in class body, so i was thinking if there is a way to make them global, so i dont have to call them individually in every class and Run-Script

Nope, I still don't get it. Are you talking about making your own data-type that 'wraps up' multiple variables? Similar to the Grasshopper Loft and Meshing options?

 

 

 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I think i should explain the issue with reference to the file where i wanted to apply it... 

 

Here's the file, David you might remember the A3Array file, its the extension, i was translating the code from java, when i encountered these issues...

 

In VB.net script, i wanted to make functions so as to call them whenever i required to use them in my main program within that VB script, instead of copy and pasting them ... but i couldn't take the variables from Main program to functions (the bottom part of the VB Script area where additional functions and classes go), and call functions appropriately... i tried to script it in the way David advised me to, but couldn't (maybe due to my limited programming background) .. so how do i make them into functions (things i mentioned in the code) ?

 

Another problem that i am having is the '3 search and growth part' its not working, i am also attaching a video, of how it should work...( generated by my java program, although the one in grasshopper don't have all the function in it yet, but it should work in the similar way with the current version of GH file...) Here red squares are 1, blue = 2 and yellow=3, according to the conditions 3 should grow way quicker than the red.... i think it's not following the condition at line 508

 

Here's the link to the video

http://www.youtube.com/watch?v=HkKMImNOATM

Why is it not picking up the if statement for 3 check and growth, is there a logical error??

Do you mean you want to declare variables in one component and then use them in another?  I can think of some ways of doing that which might work, but I wouldn't recommend it since it's kinda unnecessary and goes completely against the way grasshopper is supposed to work - changing one of them won't trigger an update, you can't be certain which order components will be fired in etc...

I think i should explain the issue with reference to the file where i wanted to apply it... 

 

Here's the file, i was translating the code from java, when i encountered these issues...

 

In VB.net script, i wanted to make functions so as to call them whenever i required to use them in my main program within that VB script, instead of copy and pasting them ... but i couldn't take the variables from Main program to functions (the bottom part of the VB Script area where additional functions and classes go), and call functions appropriately... i tried to script it in the way David advised me to, but couldn't (maybe due to my limited programming background) .. so how do i make them into functions (things i mentioned in the code) ?

 

Another problem that i am having is the '3 search and growth part' its not working, i am also attaching a video, of how it should work...( generated by my java program, although the one in grasshopper don't have all the function in it yet, but it should work in the similar way with the current version of GH file...) Here red squares are 1, blue = 2 and yellow=3, according to the conditions 3 should grow way quicker than the red.... i think it's not following the condition at line 508

 

Here's the link to the video

http://www.youtube.com/watch?v=HkKMImNOATM

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service