this is becoming my own blog site - eh?
ok, after a couple hours of many tests, I figured out the disposal of objects used to make the drawables must be handled carefully.
Since you will always be tracking the drawables in some list, to use for erase later, you must not dispose of the line, arc, mtext or whatever, until you set it to a new object, like this:
(note that I also added the viewport stuff so it only affects current one)
public static bool TrDrawLines(List<double[]> pts, int color, bool highlight, out List<Drawable> lstDraws)
{
lstDraws = null;
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TransientManager tm = TransientManager.CurrentTransientManager;
IntegerCollection ic = new IntegerCollection();
int vpn = System.Convert.ToInt32(AcAp.GetSystemVariable("CVPORT"));
ic.Add(vpn);
AcDb.Line ln;
using (Transaction tr = db.TransactionManager.StartTransaction()) {
try {
lstDraws = new List<Drawable>();
for (int i = 0; i < pts.Count - 1; i++) {
ln = new Line(new Point3d(pts[i]), new Point3d(pts[i + 1]));
ln.ColorIndex = color;
Drawable d = (Drawable)ln;
if (highlight)
tm.AddTransient(d, TransientDrawingMode.Highlight, 0, ic);
else
tm.AddTransient(d, TransientDrawingMode.DirectShortTerm, 0, ic);
lstDraws.Add(d);
}
tr.Commit();
return true;
}
catch { return false; }
finally {
ln = new Line(); //critical, do not delete this
ln.Dispose();
}
}
}