We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I have this .txt file, exported from grasshopper. I am trying to use PVectore to split data in txt file and make a spiderweb from that, but I see error "array index out of bounds:1" in line 26. Anybody knows what is wrong with this code?
This is the code:
import peasy.*;
PVector GHpoints[] = new PVector[100];
PeasyCam cam;
PVector[] jumpersB;
void setup() {
size (600,600,P3D);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(5);
cam.setMaximumDistance(20);
smooth ();
frameRate(100);
}
void draw(){
background (255);
import_GH();
spiderWeb();
}
void import_GH(){
String GH_PT[]=loadStrings("GH_PT.txt");
for (int x=GH_PT.length-1; x>=0; x--){
float point[] = float(split(GH_PT[x], ' '));
PVector Temp_PT = new PVector(point[0], point[1], point[2]);
GHpoints[x] = Temp_PT;
}}
void spiderWeb(){
for (int i=0; i<GHpoints.length-1; i++){
for (int b=0; b<GHpoints.length-1; b++){
if( jumpersB[i] != null){
if( jumpersB[b] != null){
PVector locA = jumpersB[i]; PVector locB = jumpersB[b];
float distance = PVector.dist(locA, locB);
if ((distance > 0) && (distance < 3)) {
stroke(100, 110);
strokeWeight(1);
line(locA.x, locA.y, locA.z, locB.x, locB.y, locB.z);
}}}}}}
Answers
You are calling a value in an array from a slot that doesn't exist. Make sure the max values of the variables you are using are the same as the size of the array.
which value you mean? I am quite new to processing and I am using this code from a tutorial I found in TU Delft website: wiki.bk.tudelft.nl/toi-pedia/Processing_Grasshopper_communication
Calling from an array looks like this:
When an array is initialized, it looks like this:
Setting the value of a slot in an array looks like this:
If slotNumber is greater than sizeOfArray or less than 0, then the log will return, "array index out of bounds:1" Either the array is not big enough, or the slotNumber is too high or low. So, what you have to do to get past that error is either to extend the bounds of the array by increasing the sizeOfArray, or decrease the amount of slots it is calling from.
The processing editor will highlight the line the error is on.
Ctrl-t in the editor will indent the code nicely so that it doesn't hurt to read.
Read the entry in the Common Questions part of the forum, it covers your error exactly.