谢谢,但是我们现在项目用的是vba 我自己写了一段替换的程序,但总是执行不了,编译又没出现错误,请大侠们帮忙看看啊! '清空选择集合中已有的选择集,避免重名 Dim ssetObjDelete As AcadSelectionSet Dim ssetObjsCount As Integer Dim ssetObj As AcadSelectionSet If ThisDrawing.SelectionSets.Count <> 0 Then ' MsgBox "选择集的个数为: " & ThisDrawing.SelectionSets.Count For ssetObjsCount = ThisDrawing.SelectionSets.Count - 1 To 0 Step -1 On Error Resume Next Set ssetObjDelete = ThisDrawing.SelectionSets.Item(ssetObjsCount) If Err <> 0 Then Err.Clear SignError = -1 MsgBox "系统未能整理出足够的资源,请再执行一遍程序" & Chr(13) & Chr(10) & _ "清除第" & ssetObjsCount + 1 & " 个选择集时出现问题", 48, "系统提示" Exit Sub End If ssetObjDelete.Delete Next End If '///////////////////////////////////////////////////////////////////// Dim tmpSsetObjString As String Dim tmpSsetObjCount As Integer
tmpSsetObjCount = 0 ssetObjCreate: tmpSsetObjString = "a" & tmpSsetObjCount '创建选择集,注意输出的选择集名 On Error Resume Next Set ssetObj = ThisDrawing.SelectionSets.Add(tmpSsetObjString) If Err <> 0 Then Err.Clear ' MsgBox "创建第" & tmpSsetObjCount & " 个选择集时出现问题" tmpSsetObjCount = tmpSsetObjCount + 1 If tmpSsetObjCount = 10 Then SignError = -1 MsgBox "系统资源紧张,要求重新启动 AutoCAD Map 或 AutoCAD 再进入", , "系统提示" Exit Sub End If GoTo ssetObjCreate End If '/////////////////////////////////////////////////////////////////////// Dim tempEntity As AcadEntity Dim lstblock As AcadBlocks ' Dim tempI As Integer '把要被替换的图块(名为TK_CheckSign)加入到选择集中 Set lstblock = ThisDrawing.Blocks If lstblock.Count = 0 Then MsgBox "图形中没有对象" Exit Sub Else For tempI = 0 To lstblock.Count - 1 Set tempEntity = lstblock.Item(tempI) '获取签名标识块() If tempEntity.Name = "TK_CheckSign" Then ssetObj.AddItems tempEntity End If Next End If '替换过程 Dim basePoint(0 To 2) As Double Dim insertedBlock As AcadExternalReference Dim objItem As AcadBlock Dim PathName As String PathName = "D:/AutoCAD 2002/Sample/Drawing2.dwg" For Each objItem In ssetObj ' 获得块的插入点(不知道获得插入点的方法对不对) basePoint(0) = objItem.InsertionPoint(0) basePoint(1) = objItem.InsertionPoint(1) basePoint(2) = objItem.InsertionPoint(2)
Set insertedBlock = ThisDrawing.paperSpace.AttachExternalReference(PathName, "XREF_IMAGE", basePoint, 1, 1, 1, 0, False) Next objItem |