截取我的trans类的函数,如果想单独使用,要改写下-
- public bool GetBlockDefFromFile(string filename, string blkdefname, bool over)
- {
- try
- {
- bool has = BlockTable.GetRecorId(blkdefname) != ObjectId.Null;
- if ((has && over) || !has)
- {
- using (DBTransaction t = new DBTransaction(filename))
- {
- ObjectId id = t.BlockTable.GetRecorId(blkdefname);
- BlockTableRecord btr = t.GetObject<BlockTableRecord>(id);
- if (!btr.IsAnonymous && !btr.IsLayout)
- {
- t.Database.WblockCloneObjects
- (
- new ObjectIdCollection { id },
- Database.BlockTableId,
- new IdMapping(),
- DuplicateRecordCloning.Replace,
- false
- );
- }
- }
- }
- return true;
- }
- catch
- { }
- return false;
- }
- public bool GetBlockDefFromFile(string filename, bool over)
- {
- try
- {
- FileInfo fi = new FileInfo(filename);
- string blkdefname = fi.Name;
- if (blkdefname.Contains("."))
- {
- blkdefname = blkdefname.Substring(0, blkdefname.LastIndexOf('.'));
- }
- bool has = BlockTable.GetRecorId(blkdefname) != ObjectId.Null;
- if ((has && over) || !has)
- {
- Database db = new Database();
- db.ReadDwgFile(filename, FileShare.Read, true, null);
- Database.Insert(BlockTableRecord.ModelSpace, blkdefname, db, false);
- }
- return true;
- }
- catch
- { }
- return false;
- }
|