@komondormrex wrote:
and what is exactly the purpose of set_bound function?
It appears to be a "shrinkwrap" routine, making an outline around the entirety of a selection set. But if I understand what it's doing, it may require that the selection set are all connected, like the left side of this image from simulating what it does [not from the routine directly, since I don't have the sub-routines]:

The red objects are the selection set. It draws the temporary box outboard of everything [dashed grey], uses BOUNDARY to wrap everything, Erases the outer-perimeter result as the Last object, saves what then remains as the last object [blue] to the 'bound' variable, and Erases the temporary outboard rectangle.
But if the selected objects don't all touch, the outer-perimeter result from BOUNDARY can't be relied on to be the last object and be Erased! In the right half, BOUNDARY resulted in four objects, and the last one, to be Erased, was not the outer-perimeter one, but the one over the quadrilateral. The one that was then Last, and would be saved to 'bound,' was the blue one over the Circle. The two yellow ones, over the Ellipse and the outer perimeter, remain!
In this case it may be a result of the fact that one of the selected objects is an Ellipse, so it had to make Regions instead of Polylines. Apparently that messes with the drawn order of the result -- with one that can make Polylines, in very limited trial it seems the outer-perimeter one is always the Last object. So it seems if the selected objects will only and always be Polyline-able things [never an Ellipse or Spline or Region derived from either of those], then the outer-perimeter Polyline will successfully be Erased. But what then goes into the 'bound' variable will still be what wraps only part of the original selection.
Kent Cooper, AIA