拼版裁切线.bas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. Attribute VB_Name = "拼版裁切线"
  2. Type Coordinate
  3. x As Double
  4. y As Double
  5. End Type
  6. Sub Cut_lines()
  7. If 0 = ActiveSelectionRange.Count Then Exit Sub
  8. '// 代码运行时关闭窗口刷新
  9. Application.Optimization = True
  10. ActiveDocument.BeginCommandGroup '一步撤消'
  11. ActiveDocument.Unit = cdrMillimeter
  12. Dim OrigSelection As ShapeRange
  13. Set OrigSelection = ActiveSelectionRange
  14. Dim s1 As Shape, sbd As Shape
  15. Dim dot As Coordinate
  16. Dim arr As Variant, border As Variant
  17. ' 当前选择物件的范围边界
  18. set_lx = OrigSelection.LeftX: set_rx = OrigSelection.RightX
  19. set_by = OrigSelection.BottomY: set_ty = OrigSelection.TopY
  20. set_cx = OrigSelection.CenterX: set_cy = OrigSelection.CenterY
  21. radius = 8: border = Array(set_lx, set_rx, set_by, set_ty, set_cx, set_cy, radius)
  22. ' 创建边界矩形,用来添加角线
  23. Set sbd = ActiveLayer.CreateRectangle(set_lx, set_by, set_rx, set_ty)
  24. OrigSelection.Add sbd
  25. For Each Target In OrigSelection
  26. Set s1 = Target
  27. lx = s1.LeftX: rx = s1.RightX
  28. by = s1.BottomY: ty = s1.TopY
  29. cx = s1.CenterX: cy = s1.CenterY
  30. '// 范围边界物件判断
  31. If Abs(set_lx - lx) < radius Or Abs(set_rx - rx) < radius Or Abs(set_by - by) _
  32. < radius Or Abs(set_ty - ty) < radius Then
  33. arr = Array(lx, by, rx, by, lx, ty, rx, ty) '// 物件左下-右下-左上-右上 四个顶点坐标数组
  34. For i = 0 To 3
  35. dot.x = arr(2 * i)
  36. dot.y = arr(2 * i + 1)
  37. '// 范围边界坐标点判断
  38. If Abs(set_lx - dot.x) < radius Or Abs(set_rx - dot.x) < radius _
  39. Or Abs(set_by - dot.y) < radius Or Abs(set_ty - dot.y) < radius Then
  40. draw_line dot, border '// 以坐标点和范围边界画裁切线
  41. End If
  42. Next i
  43. End If
  44. Next Target
  45. sbd.Delete '删除边界矩形
  46. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  47. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  48. ActiveSelection.Group
  49. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  50. ActiveDocument.EndCommandGroup
  51. '// 代码操作结束恢复窗口刷新
  52. Application.Optimization = False
  53. ActiveWindow.Refresh
  54. Application.Refresh
  55. End Sub
  56. '范围边界 border = Array(set_lx, set_rx, set_by, set_ty, set_cx, set_cy, radius)
  57. Private Function draw_line(dot As Coordinate, border As Variant)
  58. Bleed = 2: line_len = 3: radius = border(6)
  59. Dim line As Shape
  60. If Abs(dot.y - border(3)) < radius Then
  61. Set line = ActiveLayer.CreateLineSegment(dot.x, border(3) + Bleed, dot.x, border(3) + (line_len + Bleed))
  62. set_line_color line
  63. ElseIf Abs(dot.y - border(2)) < radius Then
  64. Set line = ActiveLayer.CreateLineSegment(dot.x, border(2) - Bleed, dot.x, border(2) - (line_len + Bleed))
  65. set_line_color line
  66. End If
  67. If Abs(dot.x - border(1)) < radius Then
  68. Set line = ActiveLayer.CreateLineSegment(border(1) + Bleed, dot.y, border(1) + (line_len + Bleed), dot.y)
  69. set_line_color line
  70. ElseIf Abs(dot.x - border(0)) < radius Then
  71. Set line = ActiveLayer.CreateLineSegment(border(0) - Bleed, dot.y, border(0) - (line_len + Bleed), dot.y)
  72. set_line_color line
  73. End If
  74. End Function
  75. '// 旧版本
  76. Private Function draw_line_按点基准(dot As Coordinate, border As Variant)
  77. Bleed = 2: line_len = 3: radius = border(6)
  78. Dim line As Shape
  79. If Abs(dot.y - border(3)) < radius Then
  80. Set line = ActiveLayer.CreateLineSegment(dot.x, dot.y + Bleed, dot.x, dot.y + (line_len + Bleed))
  81. set_line_color line
  82. ElseIf Abs(dot.y - border(2)) < radius Then
  83. Set line = ActiveLayer.CreateLineSegment(dot.x, dot.y - Bleed, dot.x, dot.y - (line_len + Bleed))
  84. set_line_color line
  85. End If
  86. If Abs(dot.x - border(1)) < radius Then
  87. Set line = ActiveLayer.CreateLineSegment(dot.x + Bleed, dot.y, dot.x + (line_len + Bleed), dot.y)
  88. set_line_color line
  89. ElseIf Abs(dot.x - border(0)) < radius Then
  90. Set line = ActiveLayer.CreateLineSegment(dot.x - Bleed, dot.y, dot.x - (line_len + Bleed), dot.y)
  91. set_line_color line
  92. End If
  93. End Function
  94. Private Function set_line_color(line As Shape)
  95. '// 设置线宽和注册色
  96. line.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  97. End Function
  98. '// CorelDRAW 物件排列拼版简单代码
  99. Sub arrange()
  100. On Error GoTo ErrorHandler
  101. ActiveDocument.Unit = cdrMillimeter
  102. row = 3 ' 拼版 3 x 4
  103. List = 4
  104. sp = 0 '间隔 0mm
  105. Dim Str, arr, n
  106. Str = API.GetClipBoardString
  107. ' 替换 mm x * 换行 TAB 为空格
  108. Str = VBA.replace(Str, "mm", " ")
  109. Str = VBA.replace(Str, "x", " ")
  110. Str = VBA.replace(Str, "*", " ")
  111. Str = VBA.replace(Str, Chr(13), " ")
  112. Str = VBA.replace(Str, Chr(9), " ")
  113. Do While InStr(Str, " ") '多个空格换成一个空格
  114. Str = VBA.replace(Str, " ", " ")
  115. Loop
  116. arr = Split(Str)
  117. Dim s1 As Shape
  118. Dim x As Double, y As Double
  119. If 0 = ActiveSelectionRange.Count Then
  120. x = Val(arr(0)): y = Val(arr(1))
  121. row = Int(ActiveDocument.Pages.First.SizeWidth / x)
  122. List = Int(ActiveDocument.Pages.First.SizeHeight / y)
  123. If UBound(arr) > 2 Then
  124. row = Val(arr(2)): List = Val(arr(3))
  125. If row * List > 800 Then
  126. GoTo ErrorHandler
  127. ElseIf UBound(arr) > 3 Then
  128. sp = Val(arr(4)) '间隔
  129. End If
  130. End If
  131. '// 建立矩形 Width x Height 单位 mm
  132. Set s1 = ActiveLayer.CreateRectangle(0, 0, x, y)
  133. '// 填充颜色无,轮廓颜色 K100,线条粗细0.3mm
  134. s1.Fill.ApplyNoFill
  135. s1.Outline.SetProperties 0.3, OutlineStyles(0), CreateCMYKColor(0, 100, 0, 0), ArrowHeads(0), _
  136. ArrowHeads(0), cdrFalse, cdrFalse, cdrOutlineButtLineCaps, cdrOutlineMiterLineJoin, 0#, 100, MiterLimit:=5#
  137. '// 如果当前选择物件,按当前物件拼版
  138. ElseIf 1 = ActiveSelectionRange.Count Then
  139. Set s1 = ActiveSelection
  140. x = s1.SizeWidth: y = s1.SizeHeight
  141. row = Int(ActiveDocument.Pages.First.SizeWidth / x)
  142. List = Int(ActiveDocument.Pages.First.SizeHeight / y)
  143. End If
  144. sw = x: sh = y
  145. '// StepAndRepeat 方法在范围内创建多个形状副本
  146. Dim dup1 As ShapeRange
  147. Set dup1 = s1.StepAndRepeat(row - 1, sw + sp, 0#)
  148. Dim dup2 As ShapeRange
  149. Set dup2 = ActiveDocument.CreateShapeRangeFromArray _
  150. (dup1, s1).StepAndRepeat(List - 1, 0#, (sh + sp))
  151. Exit Sub
  152. ErrorHandler:
  153. MsgBox "记事本输入数字,示例: 50x50 4x3 ,复制到剪贴板再运行工具!"
  154. On Error Resume Next
  155. End Sub