Grasshopper

algorithmic modeling for Rhino

Merge two lists which representing points with python/ programming merge element with python

I´m working with python in Rhino 3D and have following problem. I have two Lists representing points. List one for example:

StartPoints = [[x1,y1,z1],[x2,y2,z2],[x3,y3,z3]]

and the second list is:

EndPoints = [[x4,y4,z4],[x5,y5,z5],[x6,y6,z6]]

My goal is to join them in following form:

MergedPoints = [[x1,y1,z1],[x2,y2,z2],[x3,y3,z3],[x4,y4,z4],[x5,y5,z5]]

Everything I tried didn´t worked. When I use zip it gives me 3 branches with 3 elements. When I try to use map it says "Point3d is not callabe". My Goal is one List with 6 points just like the merge element in grasshopper would give. Thanks for your help!

Views: 1472

Replies to This Discussion

Try the coding forum: http://www.grasshopper3d.com/forum/categories/vb-c-and-python-codin...

Or look it up: http://stackoverflow.com/questions/1720421/how-to-append-list-to-se...

Python makes this ridiculously easy.

mergedlist = listone + listtwo

Or in your case: MergedPoints = S + E

Thats what I tried but didn´t worked for me ;)

OK, I see now why you have to get the two lists of end points before "P = S + E" will work.  It appears to me that the code you posted will jumble the sequence, though, instead of adding a list of end points to a list of start points.

Why use Python for this at all?

Because it will be a part of a bigger script which I only can build up with python.

I got it by my own.

import rhinoscriptsyntax as rs

merged = []

for i in range(0,len(C)):
    S = rs.CurveStartPoint(C[i])
    merged.append(S)
    E = rs.CurveStartPoint(C[i])
    merged.append(E)
P = merged


Absurdly complex compared to "P = S + E".

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service