乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 17|回复: 0

2145386484-未知句柄

[复制链接]

120

主题

326

帖子

7

银币

中流砥柱

Rank: 25

铜币
806
发表于 2008-7-24 12:25:00 | 显示全部楼层 |阅读模式
在找尺寸线的起点和终点坐标时,经常会出现如下情况。
2145386484--未知句柄
在有这段描述
'Not a valid handle. 未知句柄
This could be an older block that doesn't  follow the pattern of BlockBegin's handle starting at 1 above the block handle. Continue the loop until you find it. BlockEnd should still be 1 above BlockBegin.
这是老版本生成的块,不能随父节点在块开始点1之上找到块关联句柄。只有不断循环才能找到它,块的结束部分仍然在块开始的1上。
原程序如下:
  1. Public Sub BlockEntsByLayer()
  2. Dim oBlk As AcadBlock
  3. Dim oBlk1 As AcadBlock
  4. Dim oBlkRef As AcadBlockReference
  5. Dim oBlkRef1 As AcadBlockReference
  6. Dim oEnt As AcadEntity
  7. Dim oEnt1 As AcadEntity
  8. Dim ss As AcadSelectionSet
  9. Dim SeqEnd As AcadEntity
  10. Dim blkent As AcadObject
  11. Dim EntArray As Variant
  12. Dim HasSEQE As BooleanSet ss = GetSS_BlockFilter
  13. For Each oBlkRef In ss
  14. Set oBlk = ThisDrawing.Blocks(oBlkRef.Name)
  15. If Not oBlk.IsXRef Then
  16. 'process BlockBegin and BlockEnd
  17. HasSEQE = GetSeqEnd(oBlk, EntArray)
  18. If HasSEQE = True Then
  19. Set oEnt = EntArray(0)
  20. oEnt.Layer = "0"
  21. Set oEnt = EntArray(1)
  22. oEnt.Layer = "0"
  23. End If
  24. For Each oEnt In oBlk
  25. Set blkent = oBlk
  26. 'process sub ents
  27. If TypeOf oEnt Is AcadBlockReference Then
  28. Set oBlkRef1 = oEnt
  29. Set oBlk1 = ThisDrawing.Blocks(oBlkRef1.Name)
  30. For Each oEnt1 In oBlk1
  31. With oEnt1
  32. If Not ThisDrawing.Layers(.Layer).Lock Then
  33. .Layer = "0"
  34. .Color = acByLayer
  35. End If
  36. End With
  37. Next oEnt1
  38. Else
  39. With oEnt
  40. If Not ThisDrawing.Layers(.Layer).Lock Then
  41. .Layer = "0"
  42. .Color = acByLayer
  43. End If
  44. End With
  45. End If
  46. Next oEnt
  47. End If
  48. Next oBlkRef
  49. ThisDrawing.Regen acAllViewports
  50. End SubPublic Sub AddSelectionSet(ss As AcadSelectionSet, SetName As String)
  51. ' This routine does the error trapping neccessary for when you want to create a
  52. ' selectin set. It takes the set and the proposed name and either adds it to the selectionsets
  53. ' collection or sets it.
  54. On Error Resume Next
  55. Set ss = ThisDrawing.SelectionSets.Add(SetName)
  56. If Err.Number  0 Then
  57. Set ss = ThisDrawing.SelectionSets.Item(SetName)
  58. End If
  59. End Sub
  60. Public Function GetSS_BlockFilter() As AcadSelectionSet
  61. 'creates an ss of Blocks only
  62. Dim s1 As AcadSelectionSet
  63. Dim objEnts(0) As AcadEntity
  64. Dim oEnt As AcadEntity
  65. Dim lispCode As VLAX
  66. Dim i As IntegerDim intFtyp(0) As Integer ' setup for the filter
  67. Dim varFval(0) As Variant
  68. Dim varFilter1, varFilter2 As Variant
  69. intFtyp(0) = 0: varFval(0) = "INSERT" ' get only blocks
  70. varFilter1 = intFtyp: varFilter2 = varFval'check for PickFirst selection set
  71. Set s1 = ThisDrawing.PickfirstSelectionSet
  72. If s1.Count > 0 Then
  73. Set lispCode = Toolbox.CreateVLAXClass
  74. 'create a working ss in lisp environment
  75. lispCode.EvalLispExpression "(setq ss (ssadd))"
  76. For Each oEnt In s1
  77. 'transfer only blocks to the lisp ss
  78. 'here's where the filtering is done
  79. If TypeOf oEnt Is AcadBlockReference Then
  80. lispCode.EvalLispExpression "(ssadd " & _
  81. "(handent " & Chr(34) & _
  82. oEnt.Handle & Chr(34) & ")" & _
  83. "ss" & _
  84. ")"
  85. End If
  86. Next oEnt
  87. 'clear orig pfss of ents, may contain other than text
  88. s1.Clear
  89. 'set the pfss to the now filtered lisp ss
  90. lispCode.EvalLispExpression "(sssetfirst nil ss)"
  91. lispCode.EvalLispExpression "(setq ss nil)"
  92. 'transfer to a named ss and then deselect the pfss
  93. AddSelectionSet s1, "ssBlockFilter"
  94. Set s1 = ThisDrawing.PickfirstSelectionSet
  95. lispCode.EvalLispExpression "(sssetfirst nil)"
  96. Set lispCode = Nothing
  97. Else
  98. AddSelectionSet s1, "ssBlockFilter" ' create or get the set
  99. s1.Clear ' clear the set
  100. s1.SelectOnScreen varFilter1, varFilter2 ' do it
  101. End If
  102. Set GetSS_BlockFilter = s1End Function
  103. Public Function GetSeqEnd(objBlock As AcadBlock, EntArray As Variant) As Boolean
  104. On Error GoTo Err_Control
  105. 'Returns True if BlockBegin or BlockEnd entities are found
  106. 'and returns them in the supplied array, a 2d array of AcadEnity.
  107. Dim objSeqEnd As AcadEntity
  108. Dim arySeqEnd(1) As AcadEntity
  109. Dim strIHex As String
  110. Dim strHandle As String
  111. Dim strLeftHex As String
  112. Dim strOwner As StringstrHandle = objBlock.Handle
  113. strLeftHex = Left(strHandle, Len(strHandle) - 2)
  114. strIHex = "&H" & Right(objBlock.Handle, 2)
  115. Do
  116. ContLoop:
  117. strIHex = strIHex + 1
  118. Set objSeqEnd = _
  119. ThisDrawing.HandleToObject(strLeftHex & Hex(strIHex))
  120. strOwner = objSeqEnd.OwnerID
  121. If objSeqEnd.ObjectName = "AcDbBlockBegin" Then
  122. Set arySeqEnd(0) = objSeqEnd
  123. GetSeqEnd = True
  124. End If
  125. If objSeqEnd.ObjectName = "AcDbBlockEnd" Then
  126. Set arySeqEnd(1) = objSeqEnd
  127. GetSeqEnd = True
  128. Exit Do
  129. End If
  130. 'Keep the loop from exceeding the reference members
  131. Loop Until strOwner  objBlock.ObjectID
  132. If GetSeqEnd = True Then EntArray = arySeqEndExit_Here:
  133. Exit Function
  134. Err_Control:
  135. Select Case Err.Number
  136. Case -2145386484
  137. 'Not a valid handle.
  138. 'This could be an older block that doesn't
  139. 'follow the pattern of BlockBegin's handle
  140. 'starting at 1 above the block handle.
  141. 'Continue the loop until you find it.
  142. 'BlockEnd should still be 1 above BlockBegin.
  143. Resume ContLoop
  144. Case Else
  145. MsgBox Err.Number & ", " & Err.Description, , "GetSeqEnd"
  146. Resume Exit_Here
  147. End Select
  148. End Function
[/url]
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-4 06:39 , Processed in 1.155736 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表