I am trying to sort panels’ sequence by the distance of panel to a specific pt.
However I have never use dictionary before.
I have no idea how to create dictionary.
Now I have a list of panels’ guid and a list of distance value.
Is there any way to convert 2 lists into a dictionary?
Or there is another more easier way to create a dictionary?
Here is my code:
import rhinoscriptsyntax as rs
Ref_pt = rs.GetPoint(“Pick a pt for sorting sequence”) #pt for distance checking
panels = rs.GetObjects(“Pick panels to assign name”,8,True) #get all panels’ id
dists = []
for panel in panels: #calculate the distance between the reference pt and every panel
ctrPt = rs.SurfaceAreaCentroid(panel) #Find panel centroid
dist = rs.Distance(Ref_pt,ctrPt) #check distance
dists.append(dist)
sorted_panels = sorted(panels,key=dists) #sort panel sequence by the distance to the ref pt
for panel in sorted_panels:
rs.SelectObject(panel)
rs.Command("_SelNone")
Appreciate for any help or suggestions.
Thank you in advance.
If you want to sort the panels by distance, I would suggest you don’t necessarily need a dictionary…
Use the zip function as above to zip each panel ID with its distance, the distance being the first index of the tuple. Then sort the resulting list. The panels will get sorted synchronously with the distances… Something like:
Do you know some website I can find that can explain functions like zip?
Don’t know what does zip function do.
Don’t think I can get help on the rhinopython help file…