.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fatal error

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
213 Views, 3 Replies

fatal error

I get a fatal error when exiting autocad, however the block does insert fine. Does anyone see anything wrong with my code?

Private Sub cmbBlockName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbBlockName.SelectedIndexChanged
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim fName As String = "c:\program files\autocad 2007\306sidewallsection.dwg"

Dim Trans As Transaction = Doc.TransactionManager.StartTransaction
Dim DB As Database = New Database(False, False)
DB.ReadDwgFile(fName, FileShare.Read, True, Nothing)
Dim ED As Autodesk.AutoCAD.EditorInput.Editor
ED = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim InsertPoint As PromptPointResult

Try
Dim idBTR As ObjectId = Doc.Database.Insert("306sidewallsection", DB, False)
Dim BT As BlockTable = Trans.GetObject(Doc.Database.BlockTableId, OpenMode.ForRead)
Dim BTR As BlockTableRecord = Trans.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Me.Hide()
InsertPoint = ED.GetPoint("Pick Insertion Point")
Me.Show()
Dim BRef As BlockReference = New BlockReference(InsertPoint.Value, idBTR)
BTR.AppendEntity(BRef)
Doc.TransactionManager.AddNewlyCreatedDBObject(BRef, True)
Catch ex As System.Exception
Finally
Trans.Commit()
Trans.Dispose()
End Try
End Sub


thanks


pat
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

This works for me.

Imports AcDb = Autodesk.AutoCAD.DatabaseServices
Imports AcGe = Autodesk.AutoCAD.Geometry
Imports System.IO

Module Module1
Friend Function InsertDrawing(ByVal dwgName As String, ByVal insPt As
AcGe.Point3d, _
ByVal scale As AcGe.Scale3d, ByVal rot As Double) As AcDb.ObjectId
Dim blkName As String = Path.GetFileNameWithoutExtension(dwgName)
Dim id As AcDb.ObjectId = Nothing
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Try
Dim bt As AcDb.BlockTable = tr.GetObject(db.BlockTableId,
AcDb.OpenMode.ForRead, True)
If Not bt.Has(blkName) Then
Using sourceDb As AcDb.Database = New AcDb.Database(False,
False)
sourceDb.ReadDwgFile(dwgName, FileShare.Read, True, "")
id = db.Insert(dwgName, sourceDb, False)
Dim blk As AcDb.BlockTableRecord = tr.GetObject(id,
AcDb.OpenMode.ForWrite, False, True)
blk.Name = blkName
End Using
Else
id = bt.Item(blkName)
End If
Dim btr As AcDb.BlockTableRecord =
tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite, True)
Dim bref As AcDb.BlockReference = New
AcDb.BlockReference(insPt, id)
bref.ScaleFactors = scale
bref.Rotation = rot
btr.AppendEntity(bref)
tr.AddNewlyCreatedDBObject(bref, True)
tr.Commit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
End Function
End Module

tp



escreveu na mensagem
news:5397002@discussion.autodesk.com...
I get a fatal error when exiting autocad, however the block does insert
fine. Does anyone see anything wrong with my code?

Private Sub cmbBlockName_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles cmbBlockName.SelectedIndexChanged
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim fName As String = "c:\program files\autocad
2007\306sidewallsection.dwg"

Dim Trans As Transaction = Doc.TransactionManager.StartTransaction
Dim DB As Database = New Database(False, False)
DB.ReadDwgFile(fName, FileShare.Read, True, Nothing)
Dim ED As Autodesk.AutoCAD.EditorInput.Editor
ED =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim InsertPoint As PromptPointResult

Try
Dim idBTR As ObjectId =
Doc.Database.Insert("306sidewallsection", DB, False)
Dim BT As BlockTable =
Trans.GetObject(Doc.Database.BlockTableId, OpenMode.ForRead)
Dim BTR As BlockTableRecord =
Trans.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Me.Hide()
InsertPoint = ED.GetPoint("Pick Insertion Point")
Me.Show()
Dim BRef As BlockReference = New
BlockReference(InsertPoint.Value, idBTR)
BTR.AppendEntity(BRef)
Doc.TransactionManager.AddNewlyCreatedDBObject(BRef, True)
Catch ex As System.Exception
Finally
Trans.Commit()
Trans.Dispose()
End Try
End Sub


thanks


pat
Message 3 of 4
Anonymous
in reply to: Anonymous

Thanks, appears the big item is using which I have not seen much in VB. Looks like end using is like using the method dispose?
Looks like you use it on the transaction and database, any other objects it would work good for?

thanks

pat
Message 4 of 4
Anonymous
in reply to: Anonymous

Hey Patrick,
After you're finished with them, call Dispose() on all databases that you
create .
--
Bobby C. Jones

wrote in message news:5397002@discussion.autodesk.com...
I get a fatal error when exiting autocad, however the block does insert
fine. Does anyone see anything wrong with my code?

Private Sub cmbBlockName_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles cmbBlockName.SelectedIndexChanged
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim fName As String = "c:\program files\autocad
2007\306sidewallsection.dwg"

Dim Trans As Transaction = Doc.TransactionManager.StartTransaction
Dim DB As Database = New Database(False, False)
DB.ReadDwgFile(fName, FileShare.Read, True, Nothing)
Dim ED As Autodesk.AutoCAD.EditorInput.Editor
ED =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim InsertPoint As PromptPointResult

Try
Dim idBTR As ObjectId =
Doc.Database.Insert("306sidewallsection", DB, False)
Dim BT As BlockTable =
Trans.GetObject(Doc.Database.BlockTableId, OpenMode.ForRead)
Dim BTR As BlockTableRecord =
Trans.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Me.Hide()
InsertPoint = ED.GetPoint("Pick Insertion Point")
Me.Show()
Dim BRef As BlockReference = New
BlockReference(InsertPoint.Value, idBTR)
BTR.AppendEntity(BRef)
Doc.TransactionManager.AddNewlyCreatedDBObject(BRef, True)
Catch ex As System.Exception
Finally
Trans.Commit()
Trans.Dispose()
End Try
End Sub


thanks


pat

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost