Hi,I'm doing the program about to copy the unopen DWG file to the active dwg file,I've already see the blog from
http://through-the-interface.typepad.com/through_the_interface/2006/08/import_blocks_f.html
I use the above code in my program,it success,but all the blocks in the unopen dwg file copy to the new dwg file.it's not what i want.
so now have the issue
Here the code:
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim acEditor As Editor = acDoc.Editor Dim acDatabase As Database = acDoc.Database Dim pPtRes As PromptPointResult Dim pPtOpts As PromptPointOptions = New PromptPointOptions("") Dim FilePath As String = "D:\2RD\PMDS\PMDS\Resources\PFD.dwg" Dim FileName As String = " PFD.dwg" Dim BlockName As String = "0920101" pPtOpts.Message = vbLf & "Insert Point of Block:" pPtRes = acEditor.GetPoint(pPtOpts) Dim InsertPt As Point3d = pPtRes.Value If pPtRes.Status = PromptStatus.Cancel Then Exit Sub End If Using (acDoc.LockDocument) Using sourceDb As New Database(False, False) sourceDb.ReadDwgFile(FilePath, System.IO.FileShare.Read, True, Nothing) sourceDb.CloseInput(True) Using trans As Transaction = acDatabase.TransactionManager.StartTransaction Dim acBlockTable As BlockTable = DirectCast(trans.GetObject(acDatabase.BlockTableId, OpenMode.ForWrite), BlockTable) If acBlockTable.Has(BlockName) = True Then Dim Block As BlockReference = New BlockReference(InsertPt, sourceDb(BlockName)) Block.ScaleFactors = New Scale3d(1, 1, 1) Block.Rotation = 0 Dim ModelSpace As BlockTableRecord = trans.GetObject(acDatabase.CurrentSpaceId, OpenMode.ForWrite) ModelSpace.AppendEntity(Block) trans.AddNewlyCreatedDBObject(Block, True) trans.Commit() Else Dim db As New Database(False, False) db.ReadDwgFile(FilePath, IO.FileShare.Read, False, "") Dim id As ObjectId = sourceDb.Insert(FileName, db, False) If id.IsValid = False Then Exit Sub End If Dim Block As BlockReference = New BlockReference(InsertPt, acBlockTable(BlockName)) Block.ScaleFactors = New Scale3d(1, 1, 1) Block.Rotation = 0 Dim ModelSpace As BlockTableRecord = trans.GetObject(acDatabase.CurrentSpaceId, OpenMode.ForWrite) ModelSpace.AppendEntity(Block) trans.AddNewlyCreatedDBObject(Block, True) trans.Commit() End If End Using End Using End Using
Dim Block As BlockReference = New BlockReference(InsertPt, sourceDb(BlockName)) sourceDb in the sourceDb(BlockName) have the problem that “Autodesk.AutoCAD.DatabaseServices.Database don't hanve the default attribute,and therefore can not be indexed"
How can i solve the problem with VB.NET ?where the problem ?what should I do ? so thanks!