cut_lines.bas 3.2 KB

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