Compare Dictionarie

Hello,

I have a dictionarie with some curve propeties (set by usertext)

[<System.Guid object at 0x00000000000000C4 [148232bc-2865-4485-a6eb-4e2a83780164]>, ‘1’, ‘0’, 0.0]
[<System.Guid object at 0x00000000000000C5 [241feee7-dac0-4f59-8112-a4245a419cb2]>, ‘1’, ‘0’, -90.0]
[<System.Guid object at 0x00000000000000C6 [52737932-ff4e-4a65-b470-acf9806231a9]>, ‘1’, ‘0’, 180.0]
[<System.Guid object at 0x00000000000000C7 [5ba12812-598e-4de3-b69e-16f5b84b3b7a]>, ‘1’, ‘0’, 90.0]
[<System.Guid object at 0x00000000000000C8 [a322ae80-8555-4b93-be24-c1a4e7014c84]>, ‘1’, ‘0’, -1.3027551975274573e-14]
[<System.Guid object at 0x00000000000000C9 [24d14812-4f0d-4310-bd5f-26057ceda174]>, ‘1’, ‘0’, 180.0]
[<System.Guid object at 0x00000000000000CA [161f0e4e-a3d5-4b79-b968-7295d3e1d2f9]>, ‘1’, ‘0’, 90.0]
[<System.Guid object at 0x00000000000000CB [c76eb94a-c741-46c7-ac54-9c52b54a5c0b]>, ‘5’, ‘0’, 0.0]
[<System.Guid object at 0x00000000000000CC [e9fbe23f-53f3-4f4a-ab32-9392f4526dc7]>, ‘5’, ‘0’, 90.0]
[<System.Guid object at 0x00000000000000CD [5a9ba258-ae2d-4590-9c70-782146b04ce8]>, ‘1’, ‘0’, 0.0]
[<System.Guid object at 0x00000000000000CE [9b2984ce-f46d-47ae-b778-ef87920ba7e7]>, ‘1’, ‘0’, -90.0]
[<System.Guid object at 0x00000000000000CF [23dfb070-a953-40c4-afd4-3aa2b3c0e195]>, ‘1’, ‘0’, 90.0]

The frist parameter is the gui id, and the rest is some random values

so, now I need join all curves that have the same values, and set the old usertext values on
the new curve, and delete the all the old one.

Any idea?

import Rhino.Geometry.Curve as Curve
Grouping = {}
NewCurves = []
for l in L:
    if tuple(L[1:]) not in Grouping.keys(): Grouping[tuple(L[1:])] = [L[0]]
    else: Grouping[tuple(L[1:])].append(L[0])
for t in Grouping.items():
    NewCurves.append((t[0],Curve.JoinCurves(t[1])))

this is more like a pseudo-code. didn’t test it nor do i have your data
L is your list of lists you posted
make sure you watch out for what comes out of Curve.JoinCurves() You need to turn GUID into Curve object tho.
if all goes well, your NewCurves will be a list of tuples, each of which has the number trio (a tuple itself) as the first item and the joined curve as the second.

Thank you,

I change L for my list, and test, return error

“Message: list objects are unhashable”

this error is on line :slight_smile:

if tuple(lista[1:]) not in Grouping.keys(): Grouping[tuple(lista[1:])] = [lista[0]]

What type error is this?

That’s why I’m using the tuple() to turn list into a tuple
Can you somehow embed your data and share it?
I suspect there is some list nesting going on

import rhinoscriptsyntax as rs
import Rhino.Geometry.Curve as Curve

Objs=rs.GetObjects(“Get lines”)
L=

for i in Objs:
Pstart= rs.CurveStartPoint(i)
Pend = rs.CurveEndPoint(i)
orient = rs.Angle(Pstart, Pend)
tool= rs.GetUserText(i,“tool”)
angulo= rs.GetUserText(i,“angulo”)
L.append ([i,tool , angulo,orient[0] ])

Grouping = {}
NewCurves =
for l in L:
if tuple(L[1:]) not in Grouping.keys(): Grouping[tuple(L[1:])] = [L[0]]
else: Grouping[tuple(L[1:])].append(L[0])

for t in Grouping.items():
NewCurves.append((t[0],Curve.JoinCurves(t[1])))

line teste.3dm (57.4 KB)

This is one basic example

I’m terribly sorry. I had a typo…
anyhow, this would work, i hope

import rhinoscriptsyntax as rs

objs = rs.GetObjects('lines')
L = []

for i in objs:
    s = rs.CurveStartPoint(i)
    e = rs.CurveEndPoint(i)
    orient = rs.Angle(s,e)
    tool = rs.GetUserText(i,'tool')
    angulo = rs.GetUserText(i,'angulo')
    L.append([i,tool,angulo,round(orient[0],3)])

Grouping = {}
NewCrvs = []
for l in L:
    if tuple(l[1:]) not in Grouping.keys(): Grouping[tuple(l[1:])] = [l[0]]
    else: Grouping[tuple(l[1:])].append(l[0])

for t in Grouping.items():
    if len(t[1])>=2: idlist = rs.JoinCurves(t[1])
    else: idlist = t[1]
    for c in idlist:
        rs.SetUserText(c,'tool',t[0][0])
        rs.SetUserText(c,'angulo',t[0][1])

in your provided example tho, many lines are not touching so it wouldn’t join.

Thank you,

I have another problem.

On this file:
Issue.3dm (20.3 KB)

I have two lines, with same direction, but is read the angle the script return 0 for one and -180 for other

L= rs.GetObject("")
Pstart= rs.CurveStartPoint(L)
Pend = rs.CurveEndPoint(L)
orient = rs.Angle(Pstart, Pend)

print orient[0]

Why does this happen?

Seams that the angle reader iis only in between 0 and 180.

Thank you

not sure
but if this is what you are looking for…


just use rs.VectorAngle()