Auto_ColorMark.bas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. '// 请先选择要印刷的物件群组,本插件完成设置页面大小,自动中线色阶条对准线功能
  2. Sub Auto_ColorMark()
  3. On Error GoTo ErrorHandler
  4. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  5. Dim doc As Document: Set doc = ActiveDocument: doc.Unit = cdrMillimeter
  6. ' 物件群组,设置页面大小
  7. Call set_page_size
  8. '// 获得页面中心点 x,y
  9. px = ActiveDocument.ActivePage.CenterX
  10. py = ActiveDocument.ActivePage.CenterY
  11. '// 导入色阶条中线对准线标记文件 ColorMark.cdr 解散群组
  12. doc.ActiveLayer.Import Path & "GMS\ColorMark.cdr"
  13. ActiveDocument.ReferencePoint = cdrBottomMiddle
  14. ActiveDocument.Selection.SetPosition px, -100
  15. ActiveDocument.Selection.Ungroup
  16. Dim sh As Shape, shs As Shapes
  17. Set shs = ActiveSelection.Shapes
  18. '// 按 MarkName 名称查找放置中线对准线标记等
  19. For Each sh In shs
  20. ActiveDocument.ClearSelection
  21. sh.CreateSelection
  22. If "CenterLine" = sh.ObjectData("MarkName").Value Then
  23. put_center_line sh
  24. ElseIf "TargetLine" = sh.ObjectData("MarkName").Value Then
  25. put_target_line sh
  26. ElseIf "ColorStrip" = sh.ObjectData("MarkName").Value Then
  27. put_ColorStrip sh ' 放置彩色色阶条
  28. ' sh.Delete ' 工厂定置不用色阶条
  29. ElseIf "ColorMark" = sh.ObjectData("MarkName").Value Then
  30. ' CMYK四色标记放置咬口
  31. If (px > py) Then
  32. sh.SetPosition px + 30#, 0
  33. Else
  34. sh.Rotate 270#
  35. ActiveDocument.ReferencePoint = cdrBottomLeft
  36. sh.SetPosition 0, py - 52#
  37. End If
  38. Else
  39. sh.Delete ' 没找到标记 ColorMark 删除
  40. End If
  41. Next sh
  42. ' 标准页面大小和添加页面框
  43. put_page_size
  44. put_page_line
  45. '// 代码操作结束恢复窗口刷新
  46. ActiveDocument.EndCommandGroup
  47. Application.Optimization = False
  48. ActiveWindow.Refresh: Application.Refresh
  49. Exit Sub
  50. ErrorHandler:
  51. MsgBox "请先选择要印刷的物件群组,本插件完成设置页面大小,自动中线色阶条对准线功能!"
  52. Application.Optimization = False
  53. On Error Resume Next
  54. End Sub
  55. Private Sub set_page_size()
  56. ' 实践应用: 选择物件群组,页面设置物件大小,物件页面居中
  57. ActiveDocument.Unit = cdrMillimeter
  58. Dim OrigSelection As ShapeRange, sh As Shape
  59. Set OrigSelection = ActiveSelectionRange
  60. Set sh = OrigSelection.Group
  61. ' MsgBox "选择物件尺寸: " & sh.SizeWidth & "x" & sh.SizeHeight
  62. ActivePage.SetSize Int(sh.SizeWidth + 0.9), Int(sh.SizeHeight + 0.9)
  63. sh.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter
  64. End Sub
  65. Private Function put_target_line(sh As Shape)
  66. ' 在页面四角放置套准标记线 Set sh = ActiveDocument.Selection
  67. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  68. sh.Duplicate 0, 0
  69. sh.Rotate 180
  70. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  71. sh.Duplicate 0, 0
  72. sh.Flip cdrFlipHorizontal ' 物件镜像
  73. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  74. sh.Duplicate 0, 0
  75. sh.Rotate 180
  76. sh.AlignToPage cdrAlignRight + cdrAlignTop
  77. End Function
  78. Private Function put_center_line(sh As Shape)
  79. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  80. sh.AlignToPage cdrAlignHCenter + cdrAlignTop
  81. sh.Duplicate 0, 0
  82. sh.Rotate 180
  83. sh.AlignToPage cdrAlignHCenter + cdrAlignBottom
  84. sh.Duplicate 0, 0
  85. sh.Rotate 90
  86. sh.AlignToPage cdrAlignVCenter + cdrAlignRight
  87. sh.Duplicate 0, 0
  88. sh.Rotate 180
  89. sh.AlignToPage cdrAlignVCenter + cdrAlignLeft
  90. End Function
  91. Private Function put_ColorStrip(sh As Shape)
  92. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  93. sh.OrderToBack
  94. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  95. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  96. sh.Duplicate 10, 0
  97. sh.AlignToPage cdrAlignRight + cdrAlignTop
  98. sh.Duplicate -25, 0
  99. sh.Rotate 90
  100. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  101. sh.Duplicate 0, 10
  102. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  103. sh.Move 0, 10
  104. Else
  105. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  106. sh.Duplicate 10, 0
  107. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  108. sh.Duplicate 10, 0
  109. sh.Rotate 270
  110. sh.AlignToPage cdrAlignRight + cdrAlignTop
  111. sh.Duplicate 0, -10
  112. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  113. sh.Move 0, 25
  114. End If
  115. End Function
  116. Private Function put_page_line()
  117. ' 添加页面框线
  118. Dim s1 As Shape
  119. Set s1 = ActiveLayer.CreateRectangle2(0, 0, ActivePage.SizeWidth, ActivePage.SizeHeight)
  120. s1.Fill.ApplyNoFill: s1.OrderToBack
  121. s1.Outline.SetProperties 0.04, Color:=CreateCMYKColor(0, 100, 0, 0)
  122. End Function
  123. Private Function put_page_size()
  124. ' 添加文字 页面大小
  125. Dim st As Shape
  126. size = Trim(Str(Int(ActivePage.SizeWidth))) + "x" + Trim(Str(Int(ActivePage.SizeHeight))) + "mm"
  127. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 8)
  128. st.AlignToPage cdrAlignRight + cdrAlignTop
  129. st.Move -3, -0.2
  130. End Function