ReadDwgFile函数 在AutoCAD2006下的问题
报错-----尝试读取或写入受保护的内存。这通常指示其他内存已损坏。查了一下原来的帖子说是函数本身有问题,还有能解决的办法没,想复制块到数据库中,然后插入块
原来用2010的,但是有个小程序要用06写,有木有什么解决办法
Dim documents As DocumentCollection = Application.DocumentManager Dim editor As Editor = documents.MdiActiveDocument.Editor Dim database As Database = documents.MdiActiveDocument.Database Dim sourceDb As New Database(False, False) Dim ex As Autodesk.AutoCAD.Runtime.Exception Try sourceDb.ReadDwgFile(sourceFileName, FileShare.Write, True, Nothing) Dim ids As ObjectIdCollection = New ObjectIdCollection() Dim manager As Autodesk.AutoCAD.DatabaseServices.TransactionManager = sourceDb.TransactionManager Dim transaction As Transaction = manager.StartTransaction Using transaction Dim table As BlockTable = CType(manager.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, False), BlockTable) Dim id As ObjectId For Each id In table Dim record As BlockTableRecord = CType(manager.GetObject(id, OpenMode.ForRead, False), BlockTableRecord) If Not record.IsAnonymous And Not record.IsLayout Then ids.Add(id) record.Dispose() End If Next transaction.Commit() table.Dispose() transaction.Dispose() End Using 'Dim mapping As New IdMapping 'Dim cloning As New DuplicateRecordCloning sourceDb.WblockCloneObjects(ids, database.BlockTableId, DuplicateRecordCloning.Replace, False) 'doctemp.CloseAndDiscard() 'doctemp.Dispose() Catch ex editor.WriteMessage("复制出错" + ex.Message) End Try sourceDb.Dispose() database.Dispose()
调试状态下有问题,非调试状态正常
页:
[1]