ChatGPT.bas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. Attribute VB_Name = "ChatGPT"
  2. Private Type Coordinate
  3. x As Double
  4. Y As Double
  5. End Type
  6. Sub Z序排列()
  7. ActiveDocument.Unit = cdrMillimeter
  8. Dim dot As Coordinate
  9. Dim s As Shape, ssr As ShapeRange
  10. Dim cnt As Long: cnt = 1
  11. Set ssr = ActiveSelectionRange
  12. ssr.Sort " @shape1.Top * 100 - @shape1.Left > @shape2.Top * 100 - @shape2.Left"
  13. For Each s In ssr
  14. dot.x = s.CenterX: dot.Y = s.CenterY
  15. s.OrderToFront
  16. puts dot.x, dot.Y, cnt: cnt = cnt + 1
  17. Next s
  18. End Sub
  19. Sub U序排列()
  20. ActiveDocument.Unit = cdrMillimeter
  21. Set xdict = CreateObject("Scripting.dictionary")
  22. Set ydict = CreateObject("Scripting.dictionary")
  23. Dim dot As Coordinate
  24. Dim s As Shape, ssr As ShapeRange
  25. Dim cnt As Long: cnt = 1
  26. Set ssr = ActiveSelectionRange
  27. ssr.Sort " @shape1.Top * 100 - @shape1.Left > @shape2.Top * 100 - @shape2.Left"
  28. For Each s In ssr
  29. dot.x = s.CenterX: dot.Y = s.CenterY
  30. If xdict.Exists(Int(dot.x)) = False Then xdict.Add Int(dot.x), dot.x
  31. If ydict.Exists(Int(dot.Y)) = False Then ydict.Add Int(dot.Y), dot.Y
  32. Next s
  33. inverter = 1 ' 交流频率控制
  34. xc = xdict.Count: yc = ydict.Count
  35. For cnt = 0 To ydict.Count - 1
  36. If inverter Mod 2 = 0 Then
  37. ssr.Sort " @shape1.Left > @shape2.Left", cnt * xc + 1, cnt * xc + xc
  38. Else
  39. ssr.Sort " @shape1.Left < @shape2.Left", cnt * xc + 1, cnt * xc + xc
  40. End If
  41. inverter = inverter + 1
  42. Next cnt
  43. cnt = 1
  44. For Each s In ssr
  45. dot.x = s.CenterX: dot.Y = s.CenterY
  46. s.OrderToFront
  47. puts dot.x, dot.Y, cnt: cnt = cnt + 1
  48. Next s
  49. End Sub
  50. Sub 计算行列() ' 字典使用计算行列
  51. ActiveDocument.Unit = cdrMillimeter
  52. Set xdict = CreateObject("Scripting.dictionary")
  53. Set ydict = CreateObject("Scripting.dictionary")
  54. Dim dot As Coordinate, Offset As Coordinate
  55. Dim s As Shape, ssr As ShapeRange
  56. Set ssr = ActiveSelectionRange
  57. ' 当前选择物件的范围边界
  58. set_lx = ssr.LeftX: set_rx = ssr.RightX
  59. set_by = ssr.BottomY: set_ty = ssr.TopY
  60. ssr(1).GetSize Offset.x, Offset.Y
  61. ' 当前选择物件 ShapeRange 初步排序
  62. ssr.Sort " @shape1.Top * 100 - @shape1.Left > @shape2.Top * 100 - @shape2.Left"
  63. For Each s In ssr
  64. dot.x = s.CenterX: dot.Y = s.CenterY
  65. If xdict.Exists(Int(dot.x)) = False Then xdict.Add Int(dot.x), dot.x
  66. If ydict.Exists(Int(dot.Y)) = False Then ydict.Add Int(dot.Y), dot.Y
  67. Next s
  68. ' MsgBox "字典使用计算行列:" & xdict.Count & ydict.Count
  69. Dim cnt As Long: cnt = 1
  70. ' 遍历字典,输出
  71. Dim key As Variant
  72. For Each key In xdict.keys
  73. dot.x = xdict(key)
  74. puts dot.x, set_by - Offset.Y / 2, cnt
  75. cnt = cnt + 1
  76. Next key
  77. cnt = 1
  78. For Each key In ydict.keys
  79. dot.Y = ydict(key)
  80. puts set_lx - Offset.x / 2, dot.Y, cnt
  81. cnt = cnt + 1
  82. Next key
  83. End Sub
  84. Private Sub puts(x, Y, n)
  85. Dim st As String
  86. st = str(n)
  87. Set s = ActiveLayer.CreateArtisticText(0, 0, st)
  88. s.CenterX = x: s.CenterY = Y
  89. End Sub
  90. '// 对数组进行排序[单维]
  91. Public Function ArraySort(src As Variant) As Variant
  92. Dim out As Long, i As Long, tmp As Variant
  93. For out = LBound(src) To UBound(src) - 1
  94. For i = out + 1 To UBound(src)
  95. If src(out) > src(i) Then
  96. tmp = src(i): src(i) = src(out): src(out) = tmp
  97. End If
  98. Next i
  99. Next out
  100. ArraySort = src
  101. End Function
  102. Sub ShowMessage()
  103. MsgBox "Hello, World!"
  104. End Sub
  105. Sub DictionaryExample()
  106. ' 创建一个空的Dictionary
  107. Dim myDict As Object
  108. Set myDict = CreateObject("Scripting.Dictionary")
  109. ' 向Dictionary中添加键值对
  110. myDict.Add "orange", 4
  111. myDict.Add "banana", 2
  112. myDict.Add "apple", 3
  113. ' 访问键值对
  114. Debug.Print "The value of 'apple' is " & myDict("apple")
  115. ' 遍历Dictionary中的所有键值对
  116. Dim key As Variant
  117. For Each key In myDict.keys
  118. Debug.Print key & " : " & myDict(key)
  119. Next key
  120. ' 检查某个键是否存在
  121. If myDict.Exists("orange") Then
  122. Debug.Print "The key 'orange' exists"
  123. End If
  124. ' 删除某个键值对
  125. myDict.Remove "banana"
  126. ' 清空Dictionary
  127. myDict.RemoveAll
  128. End Sub
  129. Sub tongji使用字典统计()
  130. Dim s As Shape
  131. Dim sr As ShapeRange
  132. Set sr = ActiveSelection.Shapes.FindShapes(Query:="@name='wk-y标记'")
  133. Dim stn As String, str As String
  134. Set d = CreateObject("Scripting.dictionary")
  135. For Each s In sr
  136. If s.Type = cdrTextShape Then
  137. If s.text.Type = cdrArtistic Then
  138. stn = s.text.Story.text
  139. If d.Exists(stn) = True Then
  140. d.Item(stn) = d.Item(stn) + 1
  141. Else
  142. d.Add stn, 1
  143. End If: End If: End If
  144. Next s
  145. str = " 规 格" & vbTab & vbTab & vbTab & "数量" & vbNewLine
  146. a = d.keys: b = d.items
  147. For i = 0 To d.Count - 1
  148. str = str & a(i) & vbTab & vbTab & b(i) & "条" & vbNewLine
  149. Next
  150. ' 遍历Dictionary中的所有键值对
  151. Dim key As Variant
  152. For Each key In d.keys
  153. Debug.Print key & " : " & d(key)
  154. Next key
  155. Debug.Print str
  156. End Sub
  157. Sub 正式U序排列()
  158. Application.Optimization = True
  159. ActiveDocument.BeginCommandGroup '一步撤消'
  160. ActiveDocument.Unit = cdrMillimeter
  161. Set xdict = CreateObject("Scripting.dictionary")
  162. Set ydict = CreateObject("Scripting.dictionary")
  163. Dim dot As Coordinate
  164. Dim s As Shape, ssr As ShapeRange
  165. Dim cnt As Long: cnt = 1
  166. Set ssr = ActiveSelectionRange
  167. ssr.Sort " @shape1.Top * 100 - @shape1.Left > @shape2.Top * 100 - @shape2.Left"
  168. For Each s In ssr
  169. dot.x = s.CenterX: dot.Y = s.CenterY
  170. If xdict.Exists(Int(dot.x)) = False Then xdict.Add Int(dot.x), dot.x
  171. If ydict.Exists(Int(dot.Y)) = False Then ydict.Add Int(dot.Y), dot.Y
  172. Next s
  173. inverter = 1 ' 交流频率控制
  174. xc = xdict.Count: yc = ydict.Count
  175. For cnt = 0 To ydict.Count - 1
  176. If inverter Mod 2 = 0 Then
  177. ssr.Sort " @shape1.Left > @shape2.Left", cnt * xc + 1, cnt * xc + xc
  178. Else
  179. ssr.Sort " @shape1.Left < @shape2.Left", cnt * xc + 1, cnt * xc + xc
  180. End If
  181. inverter = inverter + 1
  182. Next cnt
  183. cnt = 1
  184. For Each s In ssr
  185. dot.x = s.CenterX: dot.Y = s.CenterY
  186. s.OrderToFront
  187. puts dot.x, dot.Y, cnt: cnt = cnt + 1
  188. Next s
  189. ActiveDocument.EndCommandGroup
  190. '// 代码操作结束恢复窗口刷新
  191. Application.Optimization = False
  192. ActiveWindow.Refresh
  193. Application.Refresh
  194. End Sub