- 积分
- 527
- 明经币
- 个
- 注册时间
- 2012-7-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
下面的代码,运行提示eKeyNotFound,PFD的DWG文件中我将块命名为9020101,其中代码都能看明白。有几处疑惑,1:BlockName是PFD.DWG文件中的块名称么?还是其ID,如果是ID,我应该用什么编辑其ID?ArxDbg2010?
2:单击一个按钮CLICK用CALL调用该过程。该按钮下没有其他代码。我想问下问题出现在哪?麻烦解答下疑惑。。下面是代码:- Public Sub InserBlock()
- Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
- Dim acDatabase As Database = acDoc.Database
- Dim acEditor As Editor = acDoc.Editor
- Dim pPtRes As PromptPointResult
- Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
- pPtOpts.Message = vbLf & "请选择插入点:"
- pPtRes = acEditor.GetPoint(pPtOpts)
- Dim InsertPt As Point3d = pPtRes.Value
- If pPtRes.Status = PromptStatus.Cancel Then
- Exit Sub
- End If
- Using trans As Transaction = acDatabase.TransactionManager.StartTransaction
- Dim acBlockTable As BlockTable = trans.GetObject(acDatabase.BlockTableId, OpenMode.ForRead)
- Dim FilePath As String = "D:\2RD\PMDS\PMDS\Resources\PFD.dwg"
- Dim FileName As String = "PFD.dwg"
- Dim BlockName As String = "TextBox1.Text"
- If acBlockTable.Has(BlockName) = True Then
- 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()
- Else
- Dim db As New Database(False, False)
- db.ReadDwgFile(FilePath, IO.FileShare.Read, False, "")
- Dim id As ObjectId = acDatabase.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 Sub
|
|