algorithmic modeling for Rhino
Hello smart people,
I'm having an issue working with vectors in Python for GH,
The following code groups the same vectors in raw python:
____________________________________________________
from collections import defaultdict
example_list = [[1,2,4], [1,2,3], [3,4,3], [1,2,3], [5,7,1], [3,4,3], [5,7,1], [1,2,4], [9,4,9], [9,3,9], [9,4,9]]
d = defaultdict(list)
for item in example_list:
d[tuple(item)].append(item)
groupedlist = sorted(d[x] for x in d)
print groupedlist
# Returns [[[1, 2, 3], [1, 2, 3]], [[1, 2, 4], [1, 2, 4]], [[3, 4, 3], [3, 4, 3]], [[5, 7, 1], [5, 7, 1]], [[9, 3, 9]], [[9, 4, 9], [9, 4, 9]]]
____________________________________________________
However working with python inside GH the code fails as (I'm assuming the id is included in the list ie.
[<Rhino.Geometry.Point3d object at 0x0000000000000BD0 [1611664.12669822,2952929.94466619,5788.70761766478]>]
If I print my object[0] i get just the vector, i.e [1611664.12669822,2952929.94466619,5788.70761766478]
However if i append my object, (for i in xrange (len(X)... list.append(my object[x])
The id included!?
[<Rhino.Geometry.Point3d object at 0x0000000000000BD0 [1611664.12669822,2952929.94466619,5788.70761766478]>]
Perhaps I'm over complicating this and should just use GH to group objects with the same position...
Also sometimes when getting vectors I receive long numbers such as.. 9.0122222900391e(10), and another times I don't.... Same file, script, geometry etc..
I'm quite a noobie in python for GH so any help or pointers are welcome...
Thank you in advance!
Tags:
Hi Si
as a little pointer for the next time, please read these suggestions.
You can get the same result with Point3d's and Vector3d's: they are sortable.
all the work in your definition is done by the sorted() function.
I'm attaching an example with a similar definition.
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by