private string createFlag(Document doc) { string dbnamestr = null; Database db = doc.Database; DBPoint flag = null; //创建点 using (Transaction tm = db.TransactionManager.StartTransaction()) { flag = new DBPoint(new Point3d(0, 0, 0)); flag.Layer = "-735"; flag.Visible = false; BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); btr.AppendEntity(flag); tm.AddNewlyCreatedDBObject(flag, true); tm.Commit(); } ////扩展数据 Guid guid = Guid.NewGuid(); DataTable dt = new DataTable(); dt.TableName = "database flag"; dt.AppendColumn(CellType.Bool, "hasDatabase"); dt.AppendColumn(CellType.CharPtr, "databaseName"); DataCellCollection row = new DataCellCollection(); DataCell hasDatabase = new DataCell(); DataCell databaseName = new DataCell(); hasDatabase.SetBool(true); dbnamestr = guid.ToString(); databaseName.SetString(dbnamestr); row.Add(hasDatabase); row.Add(databaseName); dt.AppendRow(row, true); using (Transaction tm = db.TransactionManager.StartTransaction()) { Entity entity = (Entity)tm.GetObject(flag.ObjectId, OpenMode.ForWrite, false); if (entity.ExtensionDictionary == new ObjectId()) { entity.CreateExtensionDictionary(); } DBDictionary extensionDic = (DBDictionary)tm.GetObject(flag.ExtensionDictionary, OpenMode.ForWrite, false); extensionDic.SetAt("database flag", dt); tm.AddNewlyCreatedDBObject(dt, true); ////锁定,冻结图层 LayerTable lt = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead, false); LayerTableRecord ltr = (LayerTableRecord)tm.GetObject(lt["-735"], OpenMode.ForWrite, false); ltr.IsFrozen = true; tm.Commit(); } return(dbnamestr); }