拼版裁切线.bas 6.6 KB

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