Tools.bas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. Attribute VB_Name = "Tools"
  2. Public Function 分分合合()
  3. 拼版裁切线.arrange
  4. CQL查找相同.CQLline_CM100
  5. 拼版裁切线.Cut_lines
  6. Dim s As Shape
  7. Set s = ActivePage.SelectShapesFromRectangle(ActivePage.LeftX, ActivePage.TopY, ActivePage.RightX, ActivePage.BottomY, True)
  8. 自动中线色阶条.Auto_ColorMark
  9. End Function
  10. Public Function 傻瓜火车排列()
  11. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  12. Dim ssr As ShapeRange, s As Shape
  13. Dim cnt As Integer
  14. Set ssr = ActiveSelectionRange
  15. cnt = 1
  16. #If VBA7 Then
  17. ' ssr.sort " @shape1.top>@shape2.top"
  18. ssr.Sort " @shape1.left<@shape2.left"
  19. #Else
  20. ' X4 不支持 ShapeRange.sort
  21. #End If
  22. ActiveDocument.ReferencePoint = cdrBottomLeft
  23. For Each s In ssr
  24. If cnt > 1 Then s.SetPosition ssr(cnt - 1).RightX, ssr(cnt - 1).BottomY
  25. cnt = cnt + 1
  26. Next s
  27. ActiveDocument.EndCommandGroup
  28. Application.Optimization = False
  29. ActiveWindow.Refresh: Application.Refresh
  30. End Function
  31. Public Function 傻瓜阶梯排列()
  32. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  33. Dim ssr As ShapeRange, s As Shape
  34. Dim cnt As Integer
  35. Set ssr = ActiveSelectionRange
  36. cnt = 1
  37. #If VBA7 Then
  38. ssr.Sort " @shape1.top>@shape2.top"
  39. ' ssr.sort " @shape1.left<@shape2.left"
  40. #Else
  41. ' X4 不支持 ShapeRange.sort
  42. #End If
  43. ActiveDocument.ReferencePoint = cdrTopLeft
  44. For Each s In ssr
  45. If cnt > 1 Then s.SetPosition ssr(cnt - 1).LeftX, ssr(cnt - 1).BottomY
  46. cnt = cnt + 1
  47. Next s
  48. ActiveDocument.EndCommandGroup
  49. Application.Optimization = False
  50. ActiveWindow.Refresh: Application.Refresh
  51. End Function
  52. '// 文本转曲线
  53. Public Function TextShape_ConvertToCurves()
  54. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  55. Dim s As Shape, cnt As Long
  56. For Each s In API.FindAllShapes.Shapes.FindShapes(, cdrTextShape)
  57. s.ConvertToCurves
  58. cnt = cnt + 1
  59. Next s
  60. MsgBox "转曲物件统计: " & cnt, , "文本转曲线"
  61. ActiveDocument.EndCommandGroup
  62. Application.Optimization = False
  63. ActiveWindow.Refresh: Application.Refresh
  64. End Function
  65. Public Function copy_shape()
  66. Dim OrigSelection As ShapeRange
  67. Set OrigSelection = ActiveSelectionRange
  68. OrigSelection.Copy
  69. End Function
  70. Public Function Rotate_Shapes(n As Double)
  71. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  72. ActiveDocument.Unit = cdrMillimeter
  73. Dim sh As Shape, shs As Shapes
  74. Set shs = ActiveSelection.Shapes
  75. Dim s As String, size As String
  76. For Each sh In shs
  77. sh.Rotate n
  78. Next sh
  79. ActiveDocument.EndCommandGroup
  80. Application.Optimization = False
  81. ActiveWindow.Refresh: Application.Refresh
  82. End Function
  83. Public Function get_shape_size(ByRef sx As Double, ByRef sy As Double)
  84. ActiveDocument.Unit = cdrMillimeter
  85. Dim sh As ShapeRange
  86. Set sh = ActiveSelectionRange
  87. sx = sh.SizeWidth
  88. sy = sh.SizeHeight
  89. sx = Int(sx * 100 + 0.5) / 100
  90. sy = Int(sy * 100 + 0.5) / 100
  91. End Function
  92. Public Function Set_Shapes_size(ByRef sx As Double, ByRef sy As Double)
  93. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  94. ActiveDocument.Unit = cdrMillimeter
  95. ActiveDocument.ReferencePoint = cdrCenter
  96. Dim sh As Shape, shs As Shapes
  97. Set shs = ActiveSelection.Shapes
  98. Dim s As String, size As String
  99. For Each sh In shs
  100. sh.SizeWidth = sx
  101. sh.SizeHeight = sy
  102. Next sh
  103. ActiveDocument.EndCommandGroup
  104. Application.Optimization = False
  105. ActiveWindow.Refresh: Application.Refresh
  106. End Function
  107. Public Function 尺寸取整()
  108. If 0 = ActiveSelectionRange.Count Then Exit Function
  109. ActiveDocument.Unit = cdrMillimeter
  110. Dim sh As Shape, shs As Shapes
  111. Set shs = ActiveSelection.Shapes
  112. Dim s As String, size As String
  113. For Each sh In shs
  114. size = Int(sh.SizeWidth + 0.5) & "x" & Int(sh.SizeHeight + 0.5) & "mm"
  115. sh.SetSize Int(sh.SizeWidth + 0.5), Int(sh.SizeHeight + 0.5)
  116. s = s & size & vbNewLine
  117. Next sh
  118. MsgBox "物件尺寸信息到剪贴板" & vbNewLine & s
  119. API.WriteClipBoard s
  120. End Function
  121. Public Function 居中页面()
  122. If 0 = ActiveSelectionRange.Count Then Exit Function
  123. ' 实践应用: 选择物件群组,页面设置物件大小,物件页面居中
  124. ActiveDocument.Unit = cdrMillimeter
  125. Dim OrigSelection As ShapeRange, sh As Shape
  126. Set OrigSelection = ActiveSelectionRange
  127. Set sh = OrigSelection.Group
  128. ActivePage.SetSize Int(sh.SizeWidth + 0.9), Int(sh.SizeHeight + 0.9)
  129. #If VBA7 Then
  130. ActiveDocument.ClearSelection
  131. sh.AddToSelection
  132. ActiveSelection.AlignAndDistribute 3, 3, 2, 0, False, 2
  133. #Else
  134. sh.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter
  135. #End If
  136. End Function
  137. Public Function Python脚本整理尺寸()
  138. mypy = Path & "GMS\262235.xyz\整理尺寸.py"
  139. cmd_line = "pythonw " & Chr(34) & mypy & Chr(34)
  140. Shell cmd_line
  141. End Function
  142. Public Function Python提取条码数字()
  143. mypy = Path & "GMS\262235.xyz\提取条码数字.py"
  144. cmd_line = "pythonw " & Chr(34) & mypy & Chr(34)
  145. Shell cmd_line
  146. End Function
  147. Public Function Python二维码QRCode()
  148. mypy = Path & "GMS\262235.xyz\二维码QRCode.py"
  149. cmd_line = "pythonw " & Chr(34) & mypy & Chr(34)
  150. Shell cmd_line
  151. End Function
  152. Public Function QRCode_replace()
  153. On Error GoTo ErrorHandler
  154. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  155. Dim image_path As String
  156. image_path = API.GetClipBoardString
  157. ActiveDocument.ReferencePoint = cdrCenter
  158. Dim sh As Shape, shs As Shapes, cs As Shape
  159. Dim x As Double, y As Double
  160. Set shs = ActiveSelection.Shapes
  161. cnt = 0
  162. For Each sh In shs
  163. If cnt = 0 Then
  164. ActiveDocument.ClearSelection
  165. ActiveLayer.Import image_path
  166. Set sc = ActiveSelection
  167. cnt = 1
  168. Else
  169. sc.Duplicate 0, 0
  170. End If
  171. sh.GetPosition x, y
  172. sc.SetPosition x, y
  173. sh.GetSize x, y
  174. sc.SetSize x, y
  175. sh.Delete
  176. Next sh
  177. '// 代码操作结束恢复窗口刷新
  178. ActiveDocument.EndCommandGroup
  179. Application.Optimization = False
  180. ActiveWindow.Refresh: Application.Refresh
  181. Exit Function
  182. ErrorHandler:
  183. Application.Optimization = False
  184. On Error Resume Next
  185. End Function
  186. Public Function QRCode_to_Vector()
  187. On Error GoTo ErrorHandler
  188. Set sr = ActiveSelectionRange
  189. With sr(1).Bitmap.Trace(cdrTraceHighQualityImage)
  190. .TraceType = cdrTraceHighQualityImage
  191. .Smoothing = 50 '数值小则平滑,数值大则细节多
  192. .RemoveBackground = False
  193. .DeleteOriginalObject = True
  194. .Finish
  195. End With
  196. Exit Function
  197. ErrorHandler:
  198. On Error Resume Next
  199. End Function