Question eKeyNotFound Auto-CAD 2011

Powerboat

New member
Joined
Nov 22, 2010
Messages
3
Programming Experience
Beginner
I complied this subroutine with a teatcher.

This is to change WBlocks in other drawnings.

But this week it doesn't work.

I couldn't find why.

The message starts by "Dim XBlokId = XBlokken(NaamBlok)"



Tanx



Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Module Subroutines

Sub VervangBlok(ByVal doc As Document, ByVal NaamDwg As String, ByVal NaamBlok As String)
Try
Dim Xdwg = New Database
Xdwg.ReadDwgFile(NaamDwg, IO.FileShare.Read, True, "")

Using XTransactie = Xdwg.TransactionManager.StartTransaction()

Dim XBlokken As BlockTable

XBlokken = XTransactie.GetObject(Xdwg.BlockTableId, OpenMode.ForRead)
Dim XBlokId = XBlokken(NaamBlok)

Dim XBlok As BlockTableRecord
XBlok = XTransactie.GetObject(XBlokId, OpenMode.ForRead)

'Het blok in de externe tekening is bekend

'Dim doc = Application.DocumentManager.MdiActiveDocument
Dim dwg = doc.Database

Using doc.LockDocument()
Using transactie = doc.TransactionManager.StartTransaction()

Dim Blokken As BlockTable
Blokken = transactie.GetObject(dwg.BlockTableId, OpenMode.ForWrite)

'voeg de id's toe
Dim Objecten As New ObjectIdCollection

Objecten.Add(XBlok.ObjectId)

'Clone de id's van een tekening met de andere
Dim objMap As New IdMapping
dwg.WblockCloneObjects(Objecten, Blokken.ObjectId, objMap, DuplicateRecordCloning.Replace, False)

transactie.Commit()

End Using
End Using

End Using
Catch ex As Exception
MsgBox("Er ging iets fout: " & vbCrLf & ex.Message)

End Try

End Sub
End Module
 
Back
Top