明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1397|回复: 0

2145386484-未知句柄

[复制链接]
发表于 2008-7-24 12:25:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-7-24 12:33:44 编辑

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

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

本版积分规则

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

GMT+8, 2024-11-26 06:40 , Processed in 0.140787 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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