Grasshopper

algorithmic modeling for Rhino

Hei there!

 

I'm reading external data from a txt file. The problem is that the String (GPS latitude) does not only contain numbers but somtimes an "X". (if it is not connected)

 

Can anybody think of a way to replace all the "X"s with the value of the prior item?

 

The problem is that it kills the String to Number function and the lines generated are very buggy.

 

Thanks everybody!

 

mias

 

 

Views: 615

Attachments:

Replies to This Discussion

Replace branch component ?

yes exactly! i attached a screenshot and in the branch the "X" should be replaced by the previous entry. is "repace branch component" a function? I don't know that one!

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hei David!

 

This works great! Thanks for the help. One problem remains: sometimes there are two or more "X"s in the list next to each other - and it is not replacing all of them, but only the last of the series. Can you help again?

 

Thank you so much!

Ouch, if you need this to work on an indefinite sequence of potential X's, I fear you might need some form of scripting. I attached a ghx file with two scripts. One (the upper one) repeats the last string literal that doesn't match "X".

 

The lower one works on numbers only (though it requires Text strings as input) and it will actually interpolate the numbers at X based on the surrounding valid numbers.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Hei David!

 

This works great!!! Thank you so much for the help!

 

Hallo again!

 

this - i guess - is the simplest question but still I can't figure it out. How can I replace - or create a list  - the has the items index as value. (for the entire lenght of the list)

 

Thank you - & sorry!

mias

 

"items index as value" ?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Series Component set to List Length - 1.

(sorry cannot show example at the moment.)

Thank you!

Hei there!

 

Another thing that I cannot work out: In the file David provided (the script) I try to add a "else if" clause...

 

I cannot figure out what I'm doing wrong there.

 

Here's the code:

 

 

    For i As Int32 = 0 To data.Count - 1
      If (data(i) = "X") Then
        data(i) = lastKnownGoodValue
      Else If (data(i) > 600) Then
        data(i) = lastKnownGoodValue
        Else
        lastKnownGoodValue = data(i)
      End If
    Next

 

 Thank you so much!

 

mias

I think the problem might be that data(i) has been converted to a string to compare to the "X" value and therefore will not work as a value to be greater than 600. Try CInt(data(i)) > 600.

Someone else jump in here if I'm wrong with the data type mismatch as I don't do VB script components much

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service