Grasshopper

algorithmic modeling for Rhino

Hello,

I created a cluster (with a component vbscript inside) that creates each level of a zome . I would like each cluster sends me the level it generates by incrementing a global variable (FaceCourante) but I don't know where il must be initialized (NombreFace = 0)

( I'm a big novice vbScript ) .

It can not be the right method ?

Here is my code :

Private Sub RunScript(ByVal NbFaces As Object, ByRef DernierNiveau As Object)

DernierNiveau = False
Call incFaceCourante

If NbFaces = FaceCourante Then
DernierNiveau = True
End If

print("Niveau : " & FaceCourante & "/" & NbFaces)

End Sub

'
Public FaceCourante As Integer = 0

Sub incFaceCourante()
FaceCourante = FaceCourante + 1
End Sub


Is what you would have a solution to my problem ?
thank you
Pierre

Views: 610

Replies to This Discussion

no one has any idea?

The FaceCourante variable you have declared is a class level variable, meaning that as long as the Script class instance isn't disposed of it will remain alive. This is probably what you want. the value should increase every time the RunScript method is called. 

One problem might be that your NbFaces input is of type Object. I think you want it to be of type Int32. I'm not quite sure how the equality test works for an object and an integer. You can set the typehint via the input parameter context menu. Given that change, the following code should work:

Private Sub RunScript(ByVal NbFaces As Int32, ByRef DernierNiveau As Object)

  FaceCourante += 1

  DernierNiveau = (NbFaces = FaceCourante)

  Print(String.Format("Niveau: {0}/{1}", FaceCourante, NbFaces))

End Sub

Private FaceCourante As Integer = 0

If you declare FaceCourante as Private Shared instead, then it will not be associated by any specific instance of your script, but rather it will be shared amongst all instances of your script. However since Grasshopper is in charge of constructing and disposing your script class, this may lead to unexpected results.

If you want a value to be truly global, then the best thing to do is write it to a fixed location on the hard disk.

Thank you for your help, but it did not work as I wanted with vbScript . suddenly, I created a cluster that decrements a list, when it reaches one, I stop generating the next level, It works.
Thanks again
Pierre

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service