- 积分
- 1098
- 明经币
- 个
- 注册时间
- 2007-4-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2014-6-17 09:04:17
|
显示全部楼层
我的代码如下:
Public Sub Read_Dwg()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim ObjId As ObjectId
Using acLckDoc As DocumentLock = doc.LockDocument()
Dim trx As Transaction = db.TransactionManager.StartTransaction
Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Dim dbInsert As Database = New Database(False, True)
Dim dwgName As String = "C:\Program Files\AutoCAD 2010\Sample\Dynamic Blocks\Mechanical - Metric.dwg"
dbInsert.ReadDwgFile(dwgName, FileOpenMode.OpenForReadAndAllShare, True, String.Empty)
ObjId = db.Insert(Path.GetFileNameWithoutExtension(dwgName), dbInsert, True)
Dim trx1 As Transaction = dbInsert.TransactionManager.StartTransaction
Dim bt1 As BlockTable = dbInsert.BlockTableId.GetObject(OpenMode.ForRead)
Dim btrMs1 As BlockTableRecord = bt1(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
For Each ID As ObjectId In btrMs1
Dim ent As Entity = trx1.GetObject(ID, OpenMode.ForRead)
If ((ent.GetType() Is GetType(BlockReference))) Then
'MessageBox.Show(ent.GetType.ToString + "--" + ent.BlockName)
Dim bref As BlockReference = ent
bref.ResetBlock()
btrMs.AppendEntity(bref.Clone)
trx.AddNewlyCreatedDBObject(bref, True)
trx.Commit()
End If
Next
End Using
End Sub
代码执行后,总是报错。提示:eAlreadyInDb.
请大家帮看看,怎么处理啊!
谢谢! |
|