Make polyline segments even integers

Hey everybody,

I’m new in Grasshopper and I have this problem that I just can’t wrap my head around.

What I want to do is to draw a random polyline in Rhino, set that pline into Grasshopper, and then for Grasshopper to round the individual polyline-segments into even integers.
I seem to be able to do that, but I run into problems when I want this new line to be continuous, i.e. where a new line starts from the previous new line’s endpoint.

In my world, this should be possible, since I have both the new lengths and the vectors. What I lack is the new end points, that will of course react to every new line!
(I guess I can manually react to every new line and put in a new “line”, but that’s not much fun, is it? :slight_smile: )

I hope it is clear what I want to do. I’ve uploaded the script (that I know does not work :expressionless: ) and some images that hopefully makes it understandable.

Thanks in advance!

  • J


Just for clarification, the purple lines in the image is the “manually” changed way! (10.9 KB)

The easiest way to do this could be looping, I used Anemone’s FastLoop for it, you find it on Food4Rhino.

190901_round_help_re (11.7 KB)

1 Like

So… I know these forums are not meant to make other people do your work, but it is very difficult to keep that moral standard, when people like you are so quick and efficient! :smiley:

Unfortunately, a ‘thank you’ is all I can repay you with… So THANK YOU!

You can also use K2 for this. (11.9 KB)

1 Like

You can do it without any plugins actually: (17.8 KB)

Only annoying bit is you have to add a zero-length vector at index 0 into that mass additional partial list. Otherwise the first segment of the polyline goes missing.

Another addition you may want to add is to change the expression from S*CInt(L/S) into Max(S, S*CInt(L/S)) just so that if a segment happens to be shorter than half your unit length, it doesn’t disappear entirely. Or maybe that’s what you want to happen, I don’t know.


I’m not sure I understand that script as “intuitively” as the other one, but on the other hand, I haven’t even started out with Kangaroo yet and I hear the possibilities there are amazing.

Do you know why the result is not the same as the other one / my drawing? It seems that the lenghts are the same, but that the starting point of the first line is changed for some reason?

Add Anchorgoal would help to resolve the problem. (13.5 KB)


That is extremely useful, because it’s easier for me to understand what is actually going on. One component that I don’t understand, however, is the “Mass addition”, and that almost seams to be the key!

Do you know how / where I can read up on this?

Thanks a lot, all the solutions teach me a lot about Grasshopper!

Thank you David, today I learned about CInt :astonished:

Mass addition just adds a bunch of numbers together from a list in the order of the list. The partial results (Pr) are just the result of each step of the addition until reaching the result.

say you want to add

The result is 10

The partial results are

Or, as in this case, it adds up vectors instead.

Hey David (or anybody, for that matter!),
Sorry to bother you again, but I have a follow-up question that I have tried to resolve myself for the whole day… :

Is there a way to insert a split in that line, that follows another “rule”, and have all of the system react to that?

For example:
The split should be “1” (following a new rule), and I would like the original line to react, so that the rest (apart from the “1”-split) is still divisible by 2.

Do you understand my question? And how would I go about that?

  • Jarl

Other solution (10.1 KB)

Hey Seghier,

Thanks for the reply - that seems to work as well! Do you know what I can do if I want one of the lengths to follow another rule, but still have the other lengths react to this (so that specific lines will be divisible by 2 and others by 3, etc., as per my question above)

I can’t seem to understand this “looping around” that occurs in all the scripts, you all are helping me with :confused:

I don’t understand what you mean exactly ; but there is no looping in the definition
the script find the vectors and move every line to the right place

Hello again,

Sorry I didn’t get back to you, but I tried once again to resolve it, without luck. I’m still using David’s script, as I couldn’t make the ends meet in yours after I performed the “splits”, :fearful:

What I am trying to do is to make “splits” in my line that follow another rule. In this case, the lines that follow another rule are the lines formed in between the points of the “split boxes”. These particular lines, I want to round to nearest “3” instead of nearest “2”.

I found a way to grab the particular lengths after the line was formed, and adjust these, but the problems was of course, that then the other lengths were changed as well.

I hope it is remotely understandable, I really appreciate this help. (14.5 KB)

Which one you want ?

Well, I’ll keep in Neo’s spirit and choose the red line :smiley: !

Ok , the odd numbers with 3 possibilities + even numbers (16.7 KB)

Arh, thanks again, Seghier.

I am not sure if I explained my problem well enough, or if I don’t understand the script.

What I wished to do was to only change the lengths, that are occuring from the “split boxes” into “divisible by 3”, whereas the others would remain unchained as “divisible by 2”. As such, the lengths would be:


But you have helped me so much already, so you don’t have to worry! I don’t even know if it is possible :open_mouth: