Having some trouble deleting all objects of a certain type from a GraphView. Using the following code which attempts to delete all objects of type “GraphPolygon”.
<br />GraphView canvas;
<br />
<br />foreach (GoObject obj in canvas.Doc.DefaultLayer)
<br />{
<br /> if (obj is GraphPolygon)
<br /> {
<br /> canvas.Doc.Remove(obj);
<br /> }
<br />}
<br />
For some reason it deletes all except for 1 of them.
You’re modifying the collection you are iterating… a no-no. Make it:
foreach (GoObject obj in canvas.Doc.DefaultLayer.CopyArray())
Hehe thanks. Oops that was a dumb mistake.