Auto_ColorMark.bas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 + 25#, 0
  33. Else
  34. sh.Rotate 270#
  35. ActiveDocument.ReferencePoint = cdrBottomLeft
  36. sh.SetPosition 0, py - 48#
  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. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  46. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  47. ActiveSelection.Group
  48. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  49. '// 代码操作结束恢复窗口刷新
  50. ActiveDocument.EndCommandGroup
  51. Application.Optimization = False
  52. ActiveWindow.Refresh: Application.Refresh
  53. Exit Sub
  54. ErrorHandler:
  55. MsgBox "请先选择要印刷的物件群组,本插件完成设置页面大小,自动中线色阶条对准线功能!"
  56. Application.Optimization = False
  57. On Error Resume Next
  58. End Sub
  59. Private Sub set_page_size()
  60. ' 实践应用: 选择物件群组,页面设置物件大小,物件页面居中
  61. ActiveDocument.Unit = cdrMillimeter
  62. Dim OrigSelection As ShapeRange, sh As Shape
  63. Set OrigSelection = ActiveSelectionRange
  64. Set sh = OrigSelection.Group
  65. ' MsgBox "选择物件尺寸: " & sh.SizeWidth & "x" & sh.SizeHeight
  66. ActivePage.SetSize Int(sh.SizeWidth + 0.9), Int(sh.SizeHeight + 0.9)
  67. sh.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter
  68. End Sub
  69. Private Function set_line_color(line As Shape)
  70. '// 设置线宽和注册色
  71. line.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  72. End Function
  73. Private Function put_target_line(sh As Shape)
  74. ' 在页面四角放置套准标记线 Set sh = ActiveDocument.Selection
  75. set_line_color sh
  76. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  77. sh.Duplicate 0, 0
  78. sh.Rotate 180
  79. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  80. sh.Duplicate 0, 0
  81. sh.Flip cdrFlipHorizontal ' 物件镜像
  82. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  83. sh.Duplicate 0, 0
  84. sh.Rotate 180
  85. sh.AlignToPage cdrAlignRight + cdrAlignTop
  86. End Function
  87. Private Function put_center_line(sh As Shape)
  88. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  89. set_line_color sh
  90. sh.AlignToPage cdrAlignHCenter + cdrAlignTop
  91. sh.Duplicate 0, 0
  92. sh.Rotate 180
  93. sh.AlignToPage cdrAlignHCenter + cdrAlignBottom
  94. sh.Duplicate 0, 0
  95. sh.Rotate 90
  96. sh.AlignToPage cdrAlignVCenter + cdrAlignRight
  97. sh.Duplicate 0, 0
  98. sh.Rotate 180
  99. sh.AlignToPage cdrAlignVCenter + cdrAlignLeft
  100. End Function
  101. Private Function put_ColorStrip(sh As Shape)
  102. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  103. sh.OrderToBack
  104. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  105. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  106. sh.Duplicate 5, 0
  107. sh.AlignToPage cdrAlignRight + cdrAlignTop
  108. sh.Duplicate -25, 0
  109. sh.Rotate 90
  110. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  111. sh.Duplicate 0, 5
  112. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  113. sh.Move 0, 5
  114. Else
  115. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  116. sh.Duplicate 5, 0
  117. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  118. sh.Duplicate 5, 0
  119. sh.Rotate 270
  120. sh.AlignToPage cdrAlignRight + cdrAlignTop
  121. sh.Duplicate 0, -5
  122. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  123. sh.Move 0, 25
  124. End If
  125. End Function
  126. Private Function put_page_line()
  127. ' 添加页面框线
  128. Dim s1 As Shape
  129. Set s1 = ActiveLayer.CreateRectangle2(0, 0, ActivePage.SizeWidth, ActivePage.SizeHeight)
  130. s1.Fill.ApplyNoFill: s1.OrderToBack
  131. s1.Outline.SetProperties 0.04, Color:=CreateCMYKColor(0, 100, 0, 0)
  132. End Function
  133. Private Function put_page_size()
  134. ' 添加文字 页面大小
  135. Dim st As Shape
  136. size = Trim(Str(Int(ActivePage.SizeWidth))) + "x" + Trim(Str(Int(ActivePage.SizeHeight))) + "mm"
  137. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 8)
  138. st.AlignToPage cdrAlignRight + cdrAlignTop
  139. st.Move -3, -0.2
  140. End Function