Grasshopper

algorithmic modeling for Rhino

What is the correct input format for defining data tree paths by string inputs? I have some basic code that is supposed to take in a tree, number of branches and number of items then divide the flattened tree by the number of items per branch. It's pretty basic code, but I can't seem to get the string input to generate the correct paths. Any help is appreciated. I placed a Print() after the strTemp variable and it appears to be producing the correct path numbering (at least as far as I understand how they are supposed to be) as the number slider inputs change so I pretty sure the code is good, I just can't find the string format to create the correct paths.

  Private Sub RunScript(ByVal L As DataTree(Of Object), ByVal P As Integer, ByVal I As Integer, ByRef A As Object) 

    Dim objList As New DataTree(Of Object)
    Dim objPath As New GH_Path
    Dim iP, iI As Integer
    Dim strTemp As String

    iP = 0
    iI = 0
    strtemp = ""
    For Each it As Object In L.AllData
      strTemp = "(" & iP & "," & iI & ")"

      objPath.FromString(strTemp)
      objlist.Add(it, objPath)

      If iI < I - 1 Then
        iI = iI + 1
      Else
        iI = 0
        If iP = P - 1 Then
          Exit For
        Else
          iP = iP + 1
        End If
      End If

      strTemp = ""

    Next it

    A = objList

  End Sub 

Views: 1786

Replies to This Discussion

I'm also passing curves to this tree input and it's decomposing them into their lengths when displayed in a Panel rather than something like "Arc-like Curve"
Ok, figured most of it out myself ...

1) got rid of the String and replaced it with New GH_Path(iP)
2) got rid of the iI value in the path

Still not sure why it's decomposing the curves though.


Code ....

Private Sub RunScript(ByVal L As DataTree(Of Object), ByVal P As Integer, ByVal I As Integer, ByRef A As Object)

Dim objList As New DataTree(Of Object)
Dim objPath As New GH_Path
Dim iP, iI As Integer

iP = 0
iI = 0
For Each it As Object In L.AllData

objPath = New GH_Path(iP)
objlist.Add(it, objPath)
If iI < I - 1 Then
iI = iI + 1
Else
iI = 0
If iP = P - 1 Then
Exit For
Else
iP = iP + 1
End If
End If
strTemp = ""
Next it
A = objList
End Sub
I don't see why it would convert your arcs to numbers. Ran a few tests here without any problems. I do know the code you posted is not the code you are running, as there is a compiler error (strTemp is not defined). Are you sure you posted the right code?

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Yea the code is the same except I removed the strtemp Dim when I posted it without removing the otherwise unused strTemp = "" line.

I found the reason it's converting. I have the input pulling from a Number component. I had pulled this in from someone else's definition for reordering a list in the manner I am trying. I was using the same component to verify the output but it's labelled and I didn't realize it was a number component. So problem solved!

Thanks!
You already solved this the proper way by using a GH_Path constructor, but the FromString method requires paths to be defined in this format:

{A;B;C;...;Z}

So curly brackets at both ends, individual numbers separated by semi-colons. In fact the FromString method is somewhat more flexible, but if you're using it from code you should use the above formatting in order to avoid having the fuzzy-string-comparer kick in.

--
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