Author Topic: Trying to insert block in current UCS  (Read 14933 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Trying to insert block in current UCS
« Reply #45 on: December 20, 2011, 07:01:01 PM »
The exact same behavior happens if you do it through the UI.
 
Maybe call
Database.ReloadXrefs

kaefer

  • Guest
Re: Trying to insert block in current UCS
« Reply #46 on: December 20, 2011, 07:07:23 PM »
Maybe call
Database.ReloadXrefs

Quote
Database.ReloadXrefs Method

Description

This function reloads the xrefs whose BlockTableRecord ObjectIds are in xrefIds

Quote
Database.ResolveXrefs Method

Description

This function resolves existing xrefs in the working database.

TJK44

  • Guest
Re: Trying to insert block in current UCS
« Reply #47 on: December 21, 2011, 10:14:15 AM »
Thank you kaefer and Jeff! I modified my code to use Database.ResolveXrefs and it reloaded the new ones. Here is the new code.

Code: [Select]
<CommandMethod("ImportPart")> _
Public Sub ImportPart()

                Dim fname As String = "R:\TEST\X-REF MASTER FILES\000022-01-01 TEST\000022-01-01 test drawing.dwg"


                Dim doc As Document = Application.DocumentManager.MdiActiveDocument
                Dim db As Database = doc.Database
                Dim ed As Editor = doc.Editor
                'Dim fname As String = "C:\Users\Jeff\Documents\Drawing1.dwg"
                Dim ObjId As ObjectId
                Using trx As Transaction = db.TransactionManager.StartTransaction
                    Using docLoc As DocumentLock = doc.LockDocument
                        Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                        Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
                        Using dbInsert As New Database(False, True)
                            dbInsert.ReadDwgFile(fname, IO.FileShare.Read, False, "")
                            ObjId = db.Insert(Path.GetFileNameWithoutExtension(fname), dbInsert, True)
                        End Using
                        Dim ppo As New PromptPointOptions(vbCrLf & "Insertion Point")
                        Dim ppr As PromptPointResult
                        ppr = ed.GetPoint(ppo)
                        If ppr.Status <> PromptStatus.OK Then
                            ed.WriteMessage(vbCrLf & "You decided to QUIT!")
                            Exit Sub
                        End If
                        Dim insertPt As Point3d = ppr.Value
                        Dim bref As New BlockReference(insertPt, ObjId)
                        btrMs.AppendEntity(bref)
                        trx.AddNewlyCreatedDBObject(bref, True)

                        trx.Commit()
                        bref.ExplodeToOwnerSpace()
                       
                        #############################
                        db.ResolveXrefs(False, False)
                        #############################

                    End Using
                End Using
            End If

        Catch ex As Exception

        End Try
    End Sub