Grasshopper

algorithmic modeling for Rhino

Is it possible to modify a gh_path after it has been initialized? or must a New gh_path be created each time?
 to give a trivial example:

    Dim dt As New DataTree(Of On3dPoint)
    Dim pth As New GH_Path(0,1)
    Dim pt As New on3dpoint (0, 0, 0)

    dt.Add(pt, pth)
    pth=(0,2)
    dt.Add(pt, pth)

    a = dt.Item(pth, 0)

returns: Value of type 'Integer' cannot be converted to 'Grasshopper.Kernel.Data.GH_Path'

Views: 1627

Replies to This Discussion

Hi Trevor,

yes, you can modify the values inside a path and even change the length of a path. However, it really takes no time at all to construct a new one, and changing paths is dangerous as GH_Path is a class and may this be used by other objects.

You can use the Dimension property to get or set a specific index:

Dim pth As New GH_Path(0, 1)
...
pth.Dimension(1) = 2


or just:

pth(1) = 2

since Dimension is the default property.

Finally, you can use InternalPath to get or set the actual array of Integers. Still, I definitely recommend using a constructor rather than modifying paths.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks for the reply, that's good to know.

I really only wanted to modify it as a way of cleaning up extra lines. In that case I was looking for the previous three points added to the tree (to compare the spanning vectors) and what I really wanted to do was 'tree.item(pth,index)' for paths (i,x), (i-1,x), and (i-2, x) and it seemed redundant to make three separate paths
But why not use:

Dim pth As New GH_Path(0, 0)
....
pth = New GH_Path(0, 1)
...
pth = New GH_Path(0, 2)


etc.

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

On a related note, I'm trying to use the GH_Pth.Indices property to convert a data tree into a nested list in python. When I run the code and print the list:

pathvalues = []

for path in treepathlist:
        pathvalues.append(path.Indices)

I get:

print pathvalues
[Array[int]((0, 1)), Array[int]((0, 3)), Array[int]((0, 5)),  etc . . . .

I tried adding the array module "import Array" and added the code:

for path in treepathlist:
    myarray = (path.Indices)
    mylist = array.tolist(myarray)

I got the error Runtime error (ArgumentTypeException): expected array, got Array[int]

What is the Array[int] object How can I convert it to the more pythonic list?

Thanks!

I found a solution here: Data Tree Discussion

the code below works:

for path in treepathlist:
    patharray = (path.Indices)
    myList = [item for item in patharray]
    pathvalues.append(myList)

Curious to know what it is doing through, and why this would work.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service