麻烦看下代码从外部CAD文件插入块有啥错误
下面的代码,运行提示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 1:BlockName是PFD.DWG文件中的块名称么?这个是blockName是文件的块名。每个实体的ID是dwg文件数据库自动生成的,我不知道你要改ID是什么意思
2.单击一个按钮CLICK用CALL调用该过程。该按钮下没有其他代码。Else以后的代码,最后拿一个ID,我不太清楚这个方法的作用是什么。 epwt 发表于 2014-10-31 14:50 static/image/common/back.gif
1:BlockName是PFD.DWG文件中的块名称么?这个是blockName是文件的块名。每个实体的ID是dwg文件数据库自动生 ...
BLOCKNAME是PFD.DWG中的块的名称,我的意思是我现在不知道我自己在程序中设置的块的名称和PFD.DWG的块名称怎么对应起来。之所以提修改ID,是怕程序中设置的块的名称和PFD.DWG的块名称不能通过程序中的代码联系起来 epwt 发表于 2014-10-31 14:50 static/image/common/back.gif
1:BlockName是PFD.DWG文件中的块名称么?这个是blockName是文件的块名。每个实体的ID是dwg文件数据库自动生 ...
2这块 我的那个贴错了 应该Filename修改成Blockname,是检查PFD.DWG文件是否存在刚才要插入的那个块。如果没有,则退出。 epwt 发表于 2014-10-31 14:50 static/image/common/back.gif
1:BlockName是PFD.DWG文件中的块名称么?这个是blockName是文件的块名。每个实体的ID是dwg文件数据库自动生 ...
现在问题是所有的PFD.DWG文件中的块都进来了
页:
[1]