public static void NormalizeLinetypes()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database db = acDoc.Database;
using ( Transaction tr = db.TransactionManager.StartTransaction() )
{
ObjectId linetypeToChange = GetLinetype();
ObjectId targetLinetype = GetLinetype();
BlockTable bt = (BlockTable) tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
foreach ( ObjectId btrId in bt )
{
BlockTableRecord btr = (BlockTableRecord) tr.GetObject(btrId, OpenMode.ForWrite);
foreach ( ObjectId id in btr )
{
Entity ent = (Entity) tr.GetObject(id, OpenMode.ForWrite);
if ( ent != null && ent.LinetypeId == linetypeToChange )
{
ent.LinetypeId = targetLinetype;
ent.LineWeight = LineWeight.ByLayer;
ent.LinetypeScale = 1;
ent.Color = Color.FromColorIndex(ColorMethod.ByLayer, 256);
}
}
}
tr.Commit();
}
}
private static ObjectId GetLinetype()
{
LinetypeDialog ltd = new LinetypeDialog();
DialogResult dr = ltd.ShowDialog();
if ( dr == DialogResult.OK )
{
ObjectId selected = ltd.Linetype;
return selected;
}
else
{
return default(ObjectId);
}
}