private static double GetPositionOnShape(XFormData xform, VisioAutomation.Scripting.Layout.RelativePosition pos) { var r = xform.GetRectangle(); switch (pos) { case VisioAutomation.Scripting.Layout.RelativePosition.PinY: return(xform.PinY); case VisioAutomation.Scripting.Layout.RelativePosition.PinX: return(xform.PinX); case VisioAutomation.Scripting.Layout.RelativePosition.Left: return(r.Left); case VisioAutomation.Scripting.Layout.RelativePosition.Right: return(r.Right); case VisioAutomation.Scripting.Layout.RelativePosition.Top: return(r.Top); case VisioAutomation.Scripting.Layout.RelativePosition.Bottom: return(r.Bottom); } throw new System.ArgumentOutOfRangeException(nameof(pos)); }
internal static List <int> SortShapesByPosition(IVisio.Page page, TargetShapeIDs targets, VisioAutomation.Scripting.Layout.RelativePosition pos) { // First get the transforms of the shapes on the given axis var xforms = XFormData.Get(page, targets); // Then, sort the shapeids pased on the corresponding value in the results var sorted_shape_ids = Enumerable.Range(0, targets.ShapeIDs.Count) .Select(i => new { index = i, shapeid = targets.ShapeIDs[i], pos = ArrangeHelper.GetPositionOnShape(xforms[i], pos) }) .OrderBy(i => i.pos) .Select(i => i.shapeid) .ToList(); return(sorted_shape_ids); }