public class LineNormalizer
{
public static void SetLinesByDefault(Database db)
{
using ( Transaction tr = db.TransactionManager.StartTransaction() )
{
BlockTable bt = (BlockTable) tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
foreach ( ObjectId btrId in bt )
{
BlockTableRecord btr = (BlockTableRecord) tr.GetObject(btrId, OpenMode.ForWrite);
if ( btr.IsFromExternalReference )
{
continue;
}
foreach ( ObjectId id in btr )
{
Entity ent = (Entity) tr.GetObject(id, OpenMode.ForWrite, false, true);
ent.Linetype = "ByLayer";
ent.LineWeight = LineWeight.ByLayer;
ent.Color = Color.FromColorIndex(ColorMethod.ByLayer, 256);
ent.LinetypeScale = 1;
ent.Layer = "0";
if ( ent is Line )
{
Line line = (Line) tr.GetObject(id, OpenMode.ForWrite, false, true);
Polyline polyline = new Polyline();
polyline.SetDatabaseDefaults();
polyline.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
polyline.AddVertexAt(1, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);
polyline.LineWeight = line.LineWeight;
polyline.Layer = line.Layer;
btr.AppendEntity(polyline);
tr.AddNewlyCreatedDBObject(polyline, true);
Line line1 = tr.GetObject(line.ObjectId, OpenMode.ForWrite) as Line;
line1.Erase(true);
}
}
}
tr.Commit();
}
}
}