[GIS] What are thestery green lines in Layout View produced during ArcObjects script execution

arcgis-10.0arcgis-desktoparcobjectspython

Could any of ArcObjects guru tell me, what are these green lines on my Page Layout and what to do, or not to do, so they do not appear? See image attached.

I do used ArcObjects from Python. My script is converting data frame grids and graticules into graphics. As result I receive Group Element from which I need to extract single elements (text, lines etc.) in order to play with them. However, after this operation (which is carried out for 3 separate grids) I receive those mysterious green lines, which are not part of GraphicContainer. Actually, green lines appear only after conversion and extraction from one- graticule (WGS).

There is some guidance here about how to get rid of them, which works (cut and paste or delete and undelete all page elements). However, I would still like to avoid them in the first place. Also, after some configurations of cutting and pasting I figured that green lines do vanish when those 3 image elements (lower right corner) are deleted and restored.

Code suspected to be responsible for this:

pGCL.Reset() #reset graphics containere
pElem = pGCL.Next()
while pElem:
 pEP3 = CType(pElem, esriCarto.IElementProperties3)
 if pEP3.Name == '' and pEP3.Type == 'Group':
  pGE = CType(pElem, esriCarto.IGroupElement3)
  pGE_no = pGE.ElementCount
  for i in range(pGE_no):
   if pGE.ElementCount > 0:
    pGEe = pGE.Element[0]
    pGCL.MoveElementFromGroup(pGE, pGEe, 0)
   else: break
 pElem = pGCL.Next()

I know there is some discussion going on, whether GIS.SE is appropriate place for such technical, software specific questions. I apologize for this, however, I did not found satisfactory answer anywhere else.

Green lines in page Layout

Best Answer

This line looks suspicious to me:

for i in range(pGE_no):

If you remove the i'th element from the group, then increment i the next element isn't really the i+1 element. This might cause confusion.

To overcome this, try looping backwards, start at pGE_no, and decrement i.

Update

Also, since you are looping through all elements in the graphicscontainer, adding a new element to the top level of the container while you are nexting might be another cause of confusion. Instead, perhaps make a list of all grouplements, then loop through the list (instead of the graphicscontainer) calling MoveElementFromGroup . If you have nested groups things get a bit more complicated, you'll need to start with the leaves and prune those back first.