- string sourceFileName = "c:\\aa.dwg";
- Database sourceDb = new Database(false, true);
- sourceDb.ReadDwgFile(sourceFileName, System.IO.FileShare.None, true, null);
- using (Transaction trans = sourceDb.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(sourceDb.BlockTableId, OpenMode.ForWrite, true);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, true);
- foreach (ObjectId btrId in btr)
- {
- Entity ent = (Entity)trans.GetObject(btrId, OpenMode.ForWrite, true);
- if (ent.GetType() == typeof(Polyline))
- {
- Polyline pl = (Polyline)ent;
- pl.ColorIndex = 1;
- }
- }
- trans.Commit();
- }
- sourceDb.SaveAs("c:\\aa.dwg", DwgVersion.Current);
这段代码更改实体属性是可以的,但是当我读取实体扩展记录的时候读不到。 |