I’m trying to create a graph to collect the viewport locations in a given sheet and then renumber the detail view according their location on sheet.
So far I can collect the viewports and their centroid location. However I’m struggling to obtain the left bottom corner of the viewport and I’ve no clue of how to -once the coordinates are sorted- sort the viewports list following the same order as the coordinates list (given 2 lists of the same number of elements make the sort order on one match the other).
The graph currently works fine when renumbering views in the selection order.
What I’m trying to figure out is the upper half of the graph, from the Viewport.LocationData node onwards.
Yes, I’m using that node in a different approach and works fine (sorry, everything is included in the same graph so it may be confusing).
I’m using it because it’s a WIP file for me and everything is there (first I got it working with Spring.SelectElements(ordered) and now I want to try an automatic approach with Viewport.LocationData.
My question was about the upper half of the graph (please ignore the Spring.SelectElements(ordered) stuff). Starting from Viewport.LocationData.
The script below will sort the Viewports starting from top left. Then you can rename them accordingly using the other part of the script you already have.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
Viewports=IN[0]
Pts=IN[1]
Coordinates=[[pt.X, pt.Y,vp] for vp, pt in zip (Viewports,Pts)]
Coordinates.sort(key=lambda x: (-x[1], x[0]))
OUT=[Viewport[2] for Viewport in Coordinates]
However not always sorts views as desired. I think it would work better by sorting the bottom left corner coordinate of the viewports instead of the center, as every viewport can be different in size.
I’ll try that.
EDIT:
Works much better sorting by the bounding box minimum point, still not perfect as sometimes requires the human factor to decide or the viewports are not perfectly aligned… Thanks @salvatoredragotta !