裁切线.bas 3.8 KB

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