SelectLine_to_Cropline.bas 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. '// 单线条转裁切线 - 放置到页面四边
  2. Sub SelectLine_to_Cropline()
  3. '// 代码运行时关闭窗口刷新
  4. Application.Optimization = True
  5. ActiveDocument.Unit = cdrMillimeter
  6. '// 获得页面中心点 x,y
  7. px = ActiveDocument.Pages.First.CenterX
  8. py = ActiveDocument.Pages.First.CenterY
  9. Bleed = 2
  10. line_len = 3
  11. Dim s As Shape
  12. Dim line As Shape
  13. '// 遍历选择的线条
  14. For Each s In ActiveSelection.Shapes
  15. lx = s.LeftX
  16. rx = s.RightX
  17. by = s.BottomY
  18. ty = s.TopY
  19. cx = s.CenterX
  20. cy = s.CenterY
  21. sw = s.SizeWidth
  22. sh = s.SizeHeight
  23. '// 判断横线(高度小于宽度),在页面左边还是右边
  24. If sh < sw Then
  25. s.Delete
  26. If cx < px Then
  27. Set line = ActiveLayer.CreateLineSegment(0, cy, 0 + line_len, cy)
  28. Else
  29. Set line = ActiveLayer.CreateLineSegment(px * 2, cy, px * 2 - line_len, cy)
  30. End If
  31. End If
  32. '// 判断竖线(高度大于宽度),在页面下边还是上边
  33. If sh > sw Then
  34. s.Delete
  35. If cy < py Then
  36. Set line = ActiveLayer.CreateLineSegment(cx, 0, cx, 0 + line_len)
  37. Else
  38. Set line = ActiveLayer.CreateLineSegment(cx, py * 2, cx, py * 2 - line_len)
  39. End If
  40. End If
  41. line.Outline.SetProperties 0.1
  42. line.Outline.SetProperties Color:=CreateRegistrationColor
  43. Next s
  44. '// 代码操作结束恢复窗口刷新
  45. Application.Optimization = False
  46. ActiveWindow.Refresh
  47. Application.Refresh
  48. End Sub