cut_lines.bas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Type Coordinate
  2. x As Double
  3. y As Double
  4. End Type
  5. Sub Cut_lines()
  6. '// 代码运行时关闭窗口刷新
  7. Application.Optimization = True
  8. ActiveDocument.BeginCommandGroup '一步撤消'
  9. ActiveDocument.Unit = cdrMillimeter
  10. Dim OrigSelection As ShapeRange
  11. Set OrigSelection = ActiveSelectionRange
  12. Dim s1 As Shape
  13. Dim dot As Coordinate
  14. Dim arr As Variant, border As Variant
  15. ' 当前选择物件的范围边界
  16. set_lx = OrigSelection.LeftX: set_rx = OrigSelection.RightX
  17. set_by = OrigSelection.BottomY: set_ty = OrigSelection.TopY
  18. set_cx = OrigSelection.CenterX: set_cy = OrigSelection.CenterY
  19. radius = 8: border = Array(set_lx, set_rx, set_by, set_ty, set_cx, set_cy, radius)
  20. For Each Target In OrigSelection
  21. Set s1 = Target
  22. lx = s1.LeftX: rx = s1.RightX
  23. by = s1.BottomY: ty = s1.TopY
  24. cx = s1.CenterX: cy = s1.CenterY
  25. '// 范围边界物件判断
  26. If Abs(set_lx - lx) < radius Or Abs(set_rx - rx) < radius Or Abs(set_by - by) _
  27. < radius Or Abs(set_ty - ty) < radius Then
  28. arr = Array(lx, by, rx, by, lx, ty, rx, ty) '// 物件左下-右下-左上-右上 四个顶点坐标数组
  29. For i = 0 To 3
  30. dot.x = arr(2 * i)
  31. dot.y = arr(2 * i + 1)
  32. '// 范围边界坐标点判断
  33. If Abs(set_lx - dot.x) < radius Or Abs(set_rx - dot.x) < radius _
  34. Or Abs(set_by - dot.y) < radius Or Abs(set_ty - dot.y) < radius Then
  35. draw_line dot, border '// 以坐标点和范围边界画裁切线
  36. End If
  37. Next i
  38. End If
  39. Next Target
  40. ActiveDocument.EndCommandGroup
  41. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  42. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  43. ActiveSelection.Group
  44. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  45. '// 代码操作结束恢复窗口刷新
  46. Application.Optimization = False
  47. ActiveWindow.Refresh
  48. Application.Refresh
  49. End Sub
  50. '范围边界 border = Array(set_lx, set_rx, set_by, set_ty, set_cx, set_cy, radius)
  51. Private Function draw_line(dot As Coordinate, border As Variant)
  52. Bleed = 2: line_len = 3: radius = border(6)
  53. Dim line As Shape
  54. If Abs(dot.y - border(3)) < radius Then
  55. Set line = ActiveLayer.CreateLineSegment(dot.x, dot.y + Bleed, dot.x, dot.y + (line_len + Bleed))
  56. set_line_color line
  57. ElseIf Abs(dot.y - border(2)) < radius Then
  58. Set line = ActiveLayer.CreateLineSegment(dot.x, dot.y - Bleed, dot.x, dot.y - (line_len + Bleed))
  59. set_line_color line
  60. End If
  61. If Abs(dot.x - border(1)) < radius Then
  62. Set line = ActiveLayer.CreateLineSegment(dot.x + Bleed, dot.y, dot.x + (line_len + Bleed), dot.y)
  63. set_line_color line
  64. ElseIf Abs(dot.x - border(0)) < radius Then
  65. Set line = ActiveLayer.CreateLineSegment(dot.x - Bleed, dot.y, dot.x - (line_len + Bleed), dot.y)
  66. set_line_color line
  67. End If
  68. End Function
  69. Private Function set_line_color(line As Shape)
  70. '// 设置线宽和注册色
  71. line.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  72. End Function