I can't acces the link from sinc on the work's machine so I'll try it at home. In the meantime, I'm having a slight difficulty getting an offset version of my curve. Here's the code which crashes in the first line of my transaction whilst trying to cast the object to a curve (the object returned as a DBObjectcollection returned from the Curve.GetOffsetCurves() method.
Here's the offending code:
private static string getOffsetSide(BlockReference block)
{
double distToL;
double distToR;
//1. Offset curve a small amount in both directions
DBObjectCollection curveLCollection = SelectedCurve.GetOffsetCurves(1.0);
DBObjectCollection curveRCollection = SelectedCurve.GetOffsetCurves(-1.0);
//2. Add to current space
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Curve curveL = (Curve)trans.GetObject(curveLCollection[0].ObjectId, OpenMode.ForWrite);
Curve curveR = (Curve)trans.GetObject(curveRCollection[0].ObjectId, OpenMode.ForWrite);
BlockTableRecord currentSpace = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
currentSpace.AppendEntity(curveL);
currentSpace.AppendEntity(curveR);
//3. Measure distance to both curves
Point3d blockCentre = new Point3d(block.Position.X, block.Position.Y, 0);
Point3d curveLPoint = curveL.GetClosestPointTo(blockCentre, false);
Line lineToL = new Line(blockCentre, new Point3d(curveLPoint.X, curveLPoint.Y, 0));
distToL = lineToL.Length;
Point3d curveRPoint = curveR.GetClosestPointTo(blockCentre, false);
Line lineToR = new Line(blockCentre, new Point3d(curveRPoint.X, curveRPoint.Y, 0));
distToR = lineToR.Length;
//4 dispose of curves
curveL.Erase();
curveR.Erase();
trans.Abort();
}