明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 949|回复: 0

[事件] 外部导入一个块的问题

[复制链接]
发表于 2014-11-3 14:03 | 显示全部楼层 |阅读模式
我看了好多帖子,也看到了Kean的那篇文章关于从外部文件导入块到当前打开的文件,但是他那个是全部导入,我现在就想导入那个外部文件中的一个。我想知道我现在这个代码有啥问题?求求大神指导下啊?
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  3.         Dim destDB As Database = acDoc.Database
  4.         Dim acEditor As Editor = acDoc.Editor
  5.         Dim pPtRes As PromptPointResult
  6.         Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")

  7.         pPtOpts.Message = vbLf & "点:"
  8.         pPtRes = acEditor.GetPoint(pPtOpts)
  9.         Dim InsertPt As Point3d = pPtRes.Value

  10.         If pPtRes.Status = PromptStatus.Cancel Then
  11.             Exit Sub
  12.         End If

  13.         Dim FilePath As String = "D:\2RD\PMDS\PMDS\Resources\PFD.dwg"
  14.         Dim FileName As String = " PFD.dwg"
  15.         Dim BlockName As String = "0920101"
  16.         Dim sourceDb As New Database(True, True)
  17.         sourceDb.ReadDwgFile(FilePath, System.IO.FileShare.Read, True, "")
  18.         Dim blockId As New ObjectIdCollection()
  19.             Using (acDoc.LockDocument)
  20.                 Dim sourcetm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = sourceDb.TransactionManager
  21.                 Dim desttm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = destDB.TransactionManager

  22.                 Dim sourcemyT As Transaction = sourcetm.StartTransaction()
  23.                 Dim sourcebt As BlockTable = DirectCast(sourcetm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, False), BlockTable)

  24.                 For Each btrId As ObjectId In sourcebt
  25.                     Dim sourcebtc As BlockTableRecord = DirectCast(sourcetm.GetObject((sourcebt(BlockTableRecord.ModelSpace)), OpenMode.ForRead, False), BlockTableRecord)
  26.                     If sourcebtc.Name = BlockName Then
  27.                         blockId.Add(btrId)
  28.                         Dim mapping As New IdMapping()
  29.                         sourceDb.WblockCloneObjects(blockId, destDB.BlockTableId, mapping, DuplicateRecordCloning.Replace, False)
  30.                         Using destmyT As Transaction = desttm.StartTransaction()
  31.                             Dim destbt As BlockTable = DirectCast(desttm.GetObject(destDB.BlockTableId, OpenMode.ForWrite, True), BlockTable)
  32.                             Dim destbtc As BlockTableRecord = DirectCast(desttm.GetObject((destbt(BlockTableRecord.ModelSpace)), OpenMode.ForRead, False), BlockTableRecord)
  33.                             Dim Block As BlockReference = New BlockReference(InsertPt, destbt(BlockName))
  34.                             Block.ScaleFactors = New Scale3d(1, 1, 1)
  35.                             Block.Rotation = 0
  36.                             Dim ModelSpace As BlockTableRecord = desttm.GetObject(destDB.CurrentSpaceId, OpenMode.ForWrite)
  37.                             ModelSpace.AppendEntity(Block)
  38.                             destmyT.AddNewlyCreatedDBObject(Block, True)
  39.                             destmyT.Commit()
  40.                         End Using
  41.                     ElseIf Not sourcebtc.IsAnonymous AndAlso Not sourcebtc.IsLayout Then
  42.                              End If
  43.                     sourcebtc.Dispose()
  44.                 Next
  45.                 Me.Close()
  46.             End Using

  47.     End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 09:17 , Processed in 0.370583 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表