Grasshopper

algorithmic modeling for Rhino

Maybe I am missing something, but I cannot get the "item index" component to return any value other than -1. I've tried strings, numbers, integers... no luck. Anyone also having this problem, or able to get it to work appropriately?

Views: 2945

Replies to This Discussion

Hi Andy,

it only works at the moment if the data is the same instance. So basically it allows you to keep track of data as it is being juggled or trimmed (for example in Jitter, Cull or Sort components), but you cannot use item index (yet anyway) to find similar data in a list.

I know this is a problem, but fixing it either involved a massive hack or a big change to the Grasshopper Data SDK.

--
David Rutten
david@mcneel.com
Seattle, WA
well there you go. I can hack around it in the case of numbers, but I'd like to figure out a way to do it for strings as well - is there a clever way to easily convert a string into a unique numerical value?
This would be very easy with scripting. I attached a one line VB script that does what you need. It works on a lot of data types, but not all of them.

--
David Rutten
david@mcneel.com
Seattle, WA
Attachments:
Ah, of course. Thanks David!

I had the same expectation as Andrew, thinking that Item.Index would return the indices for a matching value within a data tree. And for some reason I couldn't get the VB script to return more than the first instance of the item.

 

So for anyone who wants this function in the mean time, here's a cluster I put together. It gives all data tree indices for a searched item.

 

And, the reason I wanted this was for a search and replace through a data tree. So here's that also.

 

(Sorry it doesn't work for strings, just numbers and booleans as far as I know.)

 

 

 

Attachments:

Help a lot!

Many Thanks!

VERY CLEVER GABE..

thanks a lot for sharing...

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service