Ciao a tutti,
sto provando a scrivere un' applicazione per leggere blocchi da disegni autocad ed importarli nel disegno corrente.
Non riesco a capire il motivo dell' errore nella funzione di Insert:
Code:
<Autodesk.AutoCAD.Runtime.CommandMethod("INSERISCI")> _
Public Shared Sub Inserisci()
Dim tDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim tDocDB As DatabaseServices.Database = tDoc.Database
Dim tDocLock As ApplicationServices.DocumentLock = Nothing
Dim tTrAct As DatabaseServices.Transaction = Nothing
Dim tDwgFileName As String = "C:\Users\UTENTE\Documents\VB.NET\HelloWorld\test1.dwg"
Dim tBlockName As String = "test1"
Dim tBlTabRecID As ObjectId = Nothing
Dim tDB As DatabaseServices.Database = Nothing
Try
If IO.File.Exists(tDwgFileName) Then
tDocLock = tDoc.LockDocument
tTrAct = tDoc.TransactionManager.StartTransaction
tDB = New Database(False, True)
tDB.ReadDwgFile(tDwgFileName, IO.FileShare.None, True, "")
tDocDB.Insert(Matrix3d.Displacement(New Vector3d(0, 0, 0)), tDB, True) '<-------- OK!
'Errore!
tBlTabRecID = tDocDB.Insert(tBlockName, tDB, False) <------ Errore eSelfReference!
tTrAct.Commit()
Else
MsgBox("File: " & tDwgFileName & " could not be found!")
End If
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox("ReadFromDWG:" & ex.Message & vbNewLine & ex.StackTrace)
Finally
If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
If tDocLock IsNot Nothing Then tDocLock.Dispose() : tDocLock = Nothing
End Try
End Sub
Cosa sbaglio??
Grazie!