[CommandMethod("OffsetObject")]
public static void OffsetObject()
{
Point3d pt;
PromptPointResult ppr;
PromptPointOptions ppo = new PromptPointOptions("");
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ppo = new PromptPointOptions("");
ppo.Message = "\nEnter start point :";
ppr = ed.GetPoint(ppo);
if (System.Convert.ToInt32(Application.GetSystemVariable("WORLDUCS")) == 1)
pt = ppr.Value;
else
pt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
tr.Commit();
}
Point2d ptstart = new Point2d(pt.X, pt.Y);
ppo = new PromptPointOptions("");
ppo.Message = "\nEnter end point :";
ppo.UseBasePoint = true;
ppo.BasePoint = pt;
ppr = ed.GetPoint(ppo);
if (System.Convert.ToInt32(Application.GetSystemVariable("WORLDUCS")) == 1)
pt = ppr.Value;
else
pt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
Point2d ptend = new Point2d(pt.X, pt.Y);
using (Transaction acTrans = db.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(db.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
Polyline acPoly = new Polyline();
acPoly.SetDatabaseDefaults();
acPoly.AddVertexAt(0, ptstart, 0, 0, 0);
acPoly.AddVertexAt(1, ptend, 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly);
acTrans.AddNewlyCreatedDBObject(acPoly, true);
DBObjectCollection acDbObjColl = acPoly.GetOffsetCurves(12);
foreach (Entity acEnt in acDbObjColl)
{
acBlkTblRec.AppendEntity(acEnt);
acTrans.AddNewlyCreatedDBObject(acEnt, true);
acEnt.Layer = "3";
}
acPoly.Layer = "4";
acPoly.ConstantWidth = 6;
acTrans.Commit();
}
}