Grasshopper

algorithmic modeling for Rhino

Recently i have started to re-script the code, i originally wrote in java, into grasshopper and i am having trouble on how to create arrays in grasshopper...is there a specific command in grasshopper for array or using VB and C#??

 

i have attached the part of java code that i am trying to re-script...its very simple, if there is a way of creating a string of array in grasshopper...

 

Views: 14787

Reply to This

Replies to This Discussion

I am trying to create an array using curve data, with the output being a list of comma delimited text strings.

Each string (line) in the output has five values K, X, Y, Z, and R

P is the curve order, which needs to go in the first line only.

Each value K is one element of the knot vector

XYZ is an individual control point. Each point gets its own line/string in the output list

R is the weight of the XYZ point defined in the same line

I can get all these data into separate lists easily enough using the buttons etc. But getting them into the proper order and moving stepwise down the data to generate the desired output string list is eluding me so far.

My thought is to make an array of columns.

Column one is a list of knot values.

Column two is a list of X values.

Column 3 = list of Y values

Column 4=z values

Column 5 is weight values

etc

The idea would be to read the first value in each list into a list of five elements, then make a string out of it. The second value of each column into a separate string on the next line, then the third value from each column into the third string in the output list and so on.The last few values in the output list will contain knot vector elements only, as there are more of these than there are control points. Some of these curves are very long, with many control points, like hundreds and hundreds.

It seems I should be able to pull the lists of interest and combine them into a tree somehow; so far all I have been able to manage is to get them into a single list by starting with control points, then weaving each list of interest successively into the growing list. I'm thinking I need to get the list for each parameter into an individual branch, then read a path across the branches at each index value. But I am missing something about the terminology. I have watched a few videos and it makes sense when people are pulling nested geometry out of models, but this is a little different. More of a data management issue. I'm sure if I wrestle with it I will get it, but it may not be pretty. Any pointers appreciated. A couple of approaches are attached. Not sure whether to loop a list subset through the data or do something else. Thanks,

Karl in LA

Attachments:

Hi Karl,

Is this what you are looking for? Each branch in the tree has P,K,X,Y,Z,W values and each value in the string is separated by a ", " ... 

Attachments:

Thanks very much that is very close.

I could not discover how to hook more than two inputs to the same weave function, so thanks for clearing that up. The pComp function was also hiding out in the vectors tab where I overlooked it, so that helps. Your approach is much more sensible than creating a single list and trying to sort through it by subset etc. It is pretty much what I had envisioned.

Two remaining items:

In the final list the curve degree only has to be mentioned once per curve, at the start of the very first line. I haven't thought of an elegant way to do that just yet. Currently it is included in every output string.

Another problem: If there is no matching x,y,z point for a knot element, the remainder of the string should be empty. Instead I am getting duplicated xyz data for the extra knot vectors, and the weight and feed constant are included on those strings/branches as well (but should not be). I have tried to find a way to turn off the wrap function, include nulls in the output from the weave, etc. but nothing seems to help. What am I doing wrong?

Attachments:

Well the curve degree is now a separate branch and won't repeat in other branches...

I don't know how Knot works, there are two extra values, if you don't want them you can always cull them, but have to know which ones to cull (that doesn't have corresponding x,y,z values) probably the first and last  value (its just an assumption, i might be wrong)

Attachments:

Hi Khizer,

Thanks very much for your help. Frankly, I do not understand knots either. I need to do some reading.

I also need to clarify my thinking on branches and paths also. Clearly I do not want degree to not repeat, but I thought that grafting something in a weave input placed it on a separate branch also. I suppose those are sub-branches or something. I lack a clear idea in my head of what corresponds to the "rows" of my array and what corresponds to the columns, as far as the outputs above.

Thanks again, really appreciate your help. It is very close to what I need, but I need to do a bit of research on the knots to be certain on the desired reporting format.

No problem Karl, 

I think you'll understand grafting, simplify, flattening and other operations in this link... 

http://www.grasshopper3d.com/forum/topics/path-mapper-help-1

It shows how path mapper works but it also shows what actually happens when you graft or simplify a list... 

This last method is really cool haha~ Is it that grasshopper C# component doesn't support multi-dimensional arrays, like other development environments do?

The Grasshopper C# component does not re-implement C# bottom up. What you write is genuine C# which is compiled using the standard C# compiler. There are two limitations you typically run into:

  1. You cannot use C# features associated with versions higher than the version loaded by Rhino. I think in both Rhino5 and RhinoWip you can use whatever ships with the .NET 4.0 framework, and at least .NET 3.5
  2. The code editor we use does not understand all language constructs you are typically allowed to use. This means that there will be errors in the editor, even though the code compiles fine. This is something we hope to improve drastically in future versions of Rhino/Grasshopper.

You can use multi-dimensional arrays all you want, just just cannot assign them to outputs and expect them to be automatically converted into data trees.

I also have some advice regarding writing code with intricate data structures such as your 2D array.

It typically helps a great deal to write your own class that takes care of all the mundane operations regarding a data structure. This makes any function that uses the data structure a lot more readable. You can wrap your 2D array up in a class and provide a bunch of safe functions to access/query this data. Makes the top level function far more readable.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Attachments:

Thanks a lot man... i really owe you ... now i can start re-scripting the whole code... i'll try to create classes from now on...

 

There is one more thing i wanted to ask, the random is not working, it is supposed to chose randomly right and left or top and bottom if both the neighbors are empty, and when compiled again, should give different results ( as in this case, it would rotate ) , but its not, do you know why?

The way I set up the random sequence is that it always returns the same sequence. This is because I use a constant seed value in the System.Random constructor. If you want to have control over the randomness, you should add an extra integer input to your script that is used to seed the random generator. This way you can change the randomness without recompiling and you don't have to worry it changes if you don't want it to. You'll notice that all components in Grasshopper that use some form of random behaviour always have a Seed input.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Its done...:)

Is there any way to rearrange the grid to fit in some sort shape ( for example a trapezoid, like the one in picture ) ?

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2020   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service