Grasshopper

algorithmic modeling for Rhino

Well I do not understand why this does not work and the information I found on the Internet has confused me more, so I ask...

Then, what I want is to make a loop with an input variable, internal variables for equations and an output variable, whose data are put into input variable. Can this be done? To explain better, the pseudocode...


> list of original values.
> Start loop.
> Equations.
> New list of values.
> End loop. -> The new values replace the original values and the loop repeats.

I have somthing like this:

ByVal x as list(of double) 'input values like range10 0 to 1.

Dim xloop As New list (Of Double) 'temporal variable.
Dim xout As New List (Of Double) 'exit values.

For i As int32 = 0 To limit

  xloop.clear()
  xout.clear()

  xloop = x
  For j As int32 = 0 To x.count - 1
    xout.add(xloop.item(j) + 1) 'this represent in my real code a lot of variables and formulas, but I think for this problem case is the same thing.
  Next
  x = xout
Next

A = x

But this does not work. Could anyone help me?
Thank you so much.

Views: 1365

Replies to This Discussion

Could someone give me a clue?

Do you mean that you have a fixed length list that you want to update repeatedly? If so, you can just change the objects directly in your starting list.

For i As Int = 0 to Limit

For j as Int = 0 to LoopList.Count -1

LoopList(j) = LoopList(j) * whatever you're doing to it

Next j

Next i

A = LoopList

Thank you very much David, has been helpful to me.
Unfortunately, my problem now (and before) is to link the loop with a counter and the corresponding timer component. It seems that doing this:

ByVal iter as integer 'input value for example 20.
Dim counter as int32 = 0
counter = counter + iter

For i as int32 = 0 to counter '(0 to 20, 0 to 40, 0 to 60...)
(,,,) 'loop
Next

At each new timer iteration, resets all, increasing exponentially runtime. In contrast with this:

For i as int32 = counter to counter + iter '(0 to 20, 20 to 40, 40 to 60....)
(,,,) 'loop
Next

In each timer iteration is repeated with the same values, so it is not a loop, is a loop repeteción.

So what I need is that each new timer iteration, the loop runs "iter" times (such as 0 to 20, 20 to 40, 40 to 60 ....), but the output values of previous loop starting the new loop. This is possible?

If I understand what you're trying to do correctly, then it's this. The key for using the timer within the GH scripting components is to declare the variables you want to remain from iteration to iteration in the '<Custom additional code> section. 

Here, with LoopRange = 5, it will output:

at Counter = 0: (0,1,2,3,4,5)

at Counter = 1: (0,1,2,3,4,5,0,2,4,6,8,10)

etc...

Private Sub RunScript(ByVal Reset As Boolean, ByVal LoopRange As Object, ByRef C As Object, ByRef D As Object)

If Reset = True Then

Counter = 0
Output.Clear

Else

Counter += 1

For I As Int32 = 0 To LoopRange

Output.Add(I * Counter) 'just to see the separation between each iteration

Next

End If

C = Counter
D = Output

End Sub

'<Custom additional code>

Dim Counter As Int32
Dim Output As New List(Of Double)

Is this what you're looking for?

Attachments:

No, that was not what I needed. Imagine you have a list of n values, which transform with some operations in a new list of values, then this new list is stored, and re-run operations with this new list of values and rerun operations the new list of new values...
I broke my head to find a solution, but for my little experience is very dirty. What I did was store each new values in a tree, extracting the last branch to take at the beginning of the loop, and clear the tree to avoid unnecessary data store. That said, I do not know if my script will be understood, because I found the solution after trying and error, in a fucking loop mind!


But many thanks for your help David :)

Private Sub RunScript(ByVal dat As List(Of Double), ByVal play As Boolean, ByVal pause As Boolean, ByRef R As Object) 


If play = True And pause = False Then
count = count + 1
pararTimer = False
Else If play = False Then
count = 0
outpath.clear()
tree.clear()
pararTimer = True
Else pause = True
pararTimer = True
End If

(...)
'----------------------------------------------------

print(count)
For iter As Int32 = count To count

x.clear()
xl.clear()
If tree.Pathexists(0) Then
print("existe")
For i As int32 = 0 To dat.count - 1
x.add(tree.branch(0).item(i))
Next
Else
print("no existe")
x.addRange(dat)

End If

For i As int32 = 0 To dat.count - 1
x(i) = x(i) + 1 'representing operations.
Next

For i As int32 = 0 To dat.count - 1
xl.add(x(i) * (iter + 1)) 'representing operations and changing variable list.
Next

outPath.addRange(xl, New gh_path(iter))
tree.clear()

If outPath.branchCount > 0 Then
tree.addRange(outPath.branch(outPath.branchCount - 1), New gh_path (0))

End If
R = tree
outpath.clear()
Next

End Sub

'<Custom additional code>
Dim tree As New datatree (Of Double)
Dim outPath As New datatree (Of Double)
Dim xl As New list (Of Double)
Dim x As New list (Of Double)
Dim count As Integer = 0
Dim timer As New System.Windows.Forms.Timer
Dim pararTimer As Boolean

Attachments:

This is what I am looking for. Any idea how to accomplish this for python?

I just need to buckle down and get into C# already but I'm in a Nash Equilibrium.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service