Author Topic: eAlreadyInDb error  (Read 3872 times)

0 Members and 1 Guest are viewing this topic.

cannorth

  • Guest
eAlreadyInDb error
« on: September 25, 2013, 11:21:04 AM »
I have a problem with this code.  On the last line of the code I receive the error:
eAlreadyInDb

What could be the problem?

Code: [Select]
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim brID As ObjectId
        Dim btr As BlockTableRecord
        Dim modelspace As BlockTableRecord
        Dim i As Integer

        Try

            bt = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
            modelspace = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)

            Dim int_tile_mode As Integer

            int_tile_mode = CInt(Application.GetSystemVariable("TILEMODE"))

            If int_tile_mode = 1 Then
                btr = CType(tr.GetObject(bt(BlockTableRecord.ModelSpace), Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite), BlockTableRecord)
            Else
                btr = CType(tr.GetObject(bt(BlockTableRecord.PaperSpace), Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite), BlockTableRecord)
            End If

            brID = modelspace.AppendEntity(blockRef)
            tr.AddNewlyCreatedDBObject(blockRef, True)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: eAlreadyInDb error
« Reply #1 on: September 25, 2013, 01:33:25 PM »
Hi,

Probably 'blockRef' has already been added to the Database...

It's really hard to say more with the upper snippet where 'blockRef' never appears before the last two lines...
Speaking English as a French Frog

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: eAlreadyInDb error
« Reply #2 on: September 25, 2013, 04:38:44 PM »
Ditto to gile's comment on not seeing where you get blockRef from, but I'm also wondering why you're querying TILEMODE to get either model or paper space when you could just use the Database.CurrentSpaceId property