Grasshopper

algorithmic modeling for Rhino

Hello guys,

I have manage to send and receive one value from Grasshopper to Processing and convert it to float. Now I'm trying to send multiple values from grasshopper to processing and store it to an Array, do some calculations and send it back.

However I'm getting an error. I have tried to use the split() function from processing but with no luck.

Can anyone help me to solve this problem? I have also attached my files.

Thank you

Views: 2757

Attachments:

Replies to This Discussion

Hi,

i tried sending a longer string from grasshopper and then separate in processing.

each value will be separated from the other value with any char that you won't use (you are sending numbers in the string so i will separate values by the char 'x') 

for example

value1=123 and value2=456 and value3=789 

will be 

"123x456x789"

and in processing you will have to split the message whenever the program finds the char 'x'

String message = new String(data);  

String[] messageParts = message.split("x");

from here you can read any part from the array

float value1 = Float.valueOf(messageParts[0]).floatValue();

float value2 = Float.valueOf(messageParts[1]).floatValue();

float value3 = Float.valueOf(messageParts[2]).floatValue();

i am not really sure if it is the fastest way.

check the attached files

Attachments:

Hi Peter,

Thank you so much for your help! That helps me a lot. Just a question. Is not possible to have an array to store the values coming from grasshopper instead of store one by one?

For example:

value[i] = Float.valueOf(messageParts[i]).floatValue();

Thank you again

George

i modified the last gh file ... i think this way is easier 

for processing .. the code you retrive from this line

String[] messageParts = message.split("x");

is an array of string you can convert an array of string to an array of floats this way

String[] messageParts = message.split("x");

float[] value = new float[messageParts.length];

for(int i=0;i<value.length;i++)
      value[i] = Float.parseFloat(messageParts[i]);

now value contains all the values coming from the string 

Thank you Peter so much Peter now I got it. The way you show me in Grasshopper is much easier since I will have many values.

Thanks

George

Hello,

I have another issue. I like to send the values from Grasshopper sliders to Processing and do some calculations inside Processing.

After that sending back the values from Processing to Grasshopper and update my sliders values with the new values from processing. 

Actually what I'm doing is a loop until a number reaches 0. For example starts from 5 and follows this loop until get 0. Any idea of how to update sliders value in each loop and send it back?

i think it would be much simpler if you stated your initial values in processing; that way you won't have to change the value of the sliders after the first communication (which i don't think it'd be possible) instead of the sliders you will read the input values from the message.

I need multiple loops until I my value reaches 0 and then I need to stop the communication. Is that possible?

have you tried to build the send command inside the loop in processing ? 

for example:

for(int i=20;i>=0;i--){

    // rest of the code here //

    udps.send( message, ip, port );

}

whenever the loop ends it will stop sending messages ... 

Hi Peter,

Thank you for your answer.

Yes I have try that but the main problem is the other way around. I like to control the values sent from grasshopper to be send only once.

Now Grasshopper sends continously the slider values and I cannot control the values since after the calulations in processing it gets back the slider value.

Anyone knows how to send data from grasshopper to processing just once? I'm sending values from a slider and I'm doing some calculations on Processing until I reach a specific number but it doesn't work since each millisecond grasshopper sends the original values to processing.

Hi I was wondering is somebody still on working with UDP? Cos my processing sketch does not work, saying the library is incompatible for the processing version (3.3.6), and I did not find a newer version for the UDP library...

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service