Grasshopper

algorithmic modeling for Rhino

How to get the index of a Path as Integer inside a VB.net component

I can´t find the method. Probably it´s as easy as it seems... Thanks in advance!


    Dim pathindexes As New List (Of Integer)
    For g As Int32=0 To x.BranchCount - 1
      Dim pathindex As Integer
      pathindex = x.Path(g).???????
      pathindexes.Add(pathindex)

    Next

    A = pathindexes

Views: 1084

Attachments:

Replies to This Discussion

Hi Paul,

 

this is a bit weird:

 

Dim pathindex As Int32
pathindex = x.Path(g).ToString

 

if pathindex is defined as an integer, you cannot assign a string to it. You can only assign integers or types that know how to upcast themselves to integers (such as shorts and bytes).

 

A path in a datatree is an array of integers, not a single number. So, when you ask for x.Path(g) you get an instance of a GH_Path class, which stores a bunch of integers on the inside and provides some methods of accessing and modifying them. Both of the following two approaches create a new list of integers filled with the first number in each path:

 

Dim indices As New List(Of Int32)
For i As Int32 = 0 To x.BranchCount - 1
  indices.Add(x.Path(i)(0))
Next
A = indices

'---------------------------
Dim indices As New List(Of Int32)
For Each path As GH_Path In x.Paths
  indices.Add(path(0))
Next
A = indices

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Thank you very much, David.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service