裁切线.bas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Attribute VB_Name = "裁切线"
  2. ' Attribute VB_Name = "裁切线"
  3. Sub start()
  4. If 0 = ActiveSelectionRange.Count Then Exit Sub
  5. '// 代码运行时关闭窗口刷新
  6. Application.Optimization = True
  7. ActiveDocument.BeginCommandGroup '一步撤消'
  8. '// 设置当前文档 尺寸单位mm 出血和线长
  9. ActiveDocument.Unit = cdrMillimeter
  10. Bleed = 2
  11. line_len = 3
  12. Dim OrigSelection As ShapeRange
  13. Set OrigSelection = ActiveSelectionRange
  14. '// 定义当前选择物件 分别获得 左右下上中心坐标(x,y)和尺寸信息
  15. Dim s1 As Shape
  16. For Each Target In OrigSelection
  17. Set s1 = Target
  18. lx = s1.LeftX: rx = s1.RightX
  19. by = s1.BottomY: ty = s1.TopY
  20. cx = s1.CenterX: cy = s1.CenterY
  21. sw = s1.SizeWidth: sh = s1.SizeHeight
  22. '// 添加裁切线,分别左下-右下-左上-右上
  23. Dim s2, s3, s4, s5, s6, s7, s8, s9 As Shape
  24. Set s2 = ActiveLayer.CreateLineSegment(lx - Bleed, by, lx - (Bleed + line_len), by)
  25. Set s3 = ActiveLayer.CreateLineSegment(lx, by - Bleed, lx, by - (Bleed + line_len))
  26. Set s4 = ActiveLayer.CreateLineSegment(rx + Bleed, by, rx + (Bleed + line_len), by)
  27. Set s5 = ActiveLayer.CreateLineSegment(rx, by - Bleed, rx, by - (Bleed + line_len))
  28. Set s6 = ActiveLayer.CreateLineSegment(lx - Bleed, ty, lx - (Bleed + line_len), ty)
  29. Set s7 = ActiveLayer.CreateLineSegment(lx, ty + Bleed, lx, ty + (Bleed + line_len))
  30. Set s8 = ActiveLayer.CreateLineSegment(rx + Bleed, ty, rx + (Bleed + line_len), ty)
  31. Set s9 = ActiveLayer.CreateLineSegment(rx, ty + Bleed, rx, ty + (Bleed + line_len))
  32. '// 选中裁切线 群组 设置线宽和注册色
  33. ActiveDocument.AddToSelection s2, s3, s4, s5, s6, s7, s8, s9
  34. ActiveSelection.Group
  35. ActiveSelection.Outline.SetProperties 0.1
  36. ActiveSelection.Outline.SetProperties Color:=CreateRegistrationColor
  37. Next Target
  38. ActiveDocument.EndCommandGroup
  39. '// 代码操作结束恢复窗口刷新
  40. Application.Optimization = False
  41. ActiveWindow.Refresh
  42. Application.Refresh
  43. End Sub
  44. '// 单线条转裁切线 - 放置到页面四边
  45. Sub SelectLine_to_Cropline()
  46. If 0 = ActiveSelectionRange.Count Then Exit Sub
  47. '// 代码运行时关闭窗口刷新
  48. Application.Optimization = True
  49. ActiveDocument.Unit = cdrMillimeter
  50. ActiveDocument.BeginCommandGroup '一步撤消'
  51. '// 获得页面中心点 x,y
  52. px = ActiveDocument.Pages.First.CenterX
  53. py = ActiveDocument.Pages.First.CenterY
  54. Bleed = 2
  55. line_len = 3
  56. Dim s As Shape
  57. Dim line As Shape
  58. '// 遍历选择的线条
  59. For Each s In ActiveSelection.Shapes
  60. lx = s.LeftX
  61. rx = s.RightX
  62. by = s.BottomY
  63. ty = s.TopY
  64. cx = s.CenterX
  65. cy = s.CenterY
  66. sw = s.SizeWidth
  67. sh = s.SizeHeight
  68. '// 判断横线(高度小于宽度),在页面左边还是右边
  69. If sh <= sw Then
  70. s.Delete
  71. If cx < px Then
  72. Set line = ActiveLayer.CreateLineSegment(0, cy, 0 + line_len, cy)
  73. Else
  74. Set line = ActiveLayer.CreateLineSegment(px * 2, cy, px * 2 - line_len, cy)
  75. End If
  76. End If
  77. '// 判断竖线(高度大于宽度),在页面下边还是上边
  78. If sh > sw Then
  79. s.Delete
  80. If cy < py Then
  81. Set line = ActiveLayer.CreateLineSegment(cx, 0, cx, 0 + line_len)
  82. Else
  83. Set line = ActiveLayer.CreateLineSegment(cx, py * 2, cx, py * 2 - line_len)
  84. End If
  85. End If
  86. line.Outline.SetProperties 0.1
  87. line.Outline.SetProperties Color:=CreateRegistrationColor
  88. Next s
  89. ActiveDocument.EndCommandGroup
  90. '// 代码操作结束恢复窗口刷新
  91. Application.Optimization = False
  92. ActiveWindow.Refresh
  93. Application.Refresh
  94. End Sub