AutoColorMark.bas 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. Attribute VB_Name = "AutoColorMark"
  2. '// This is free and unencumbered software released into the public domain.
  3. '// For more information, please refer to https://github.com/hongwenjun
  4. '// Attribute VB_Name = "自动中线色阶条" AutoColorMark 2023.6.11
  5. '// 请先选择要印刷的物件群组,本插件完成设置页面大小,自动中线色阶条对准线功能
  6. Function Auto_ColorMark()
  7. If 0 = ActiveSelectionRange.Count Then Exit Function
  8. On Error GoTo ErrorHandler
  9. API.BeginOpt
  10. Dim doc As Document: Set doc = ActiveDocument
  11. ' 物件群组,设置页面大小
  12. set_page_size
  13. '// 获得页面中心点 x,y
  14. px = ActiveDocument.ActivePage.CenterX
  15. py = ActiveDocument.ActivePage.CenterY
  16. '// 导入色阶条中线对准线标记文件 ColorMark.cdr 解散群组
  17. doc.ActiveLayer.Import path & "GMS\ColorMark.cdr"
  18. ActiveDocument.ReferencePoint = cdrBottomMiddle
  19. ' ActiveDocument.Selection.SetPosition px, -100
  20. ActiveDocument.Selection.Ungroup
  21. Dim sh As Shape, shs As Shapes
  22. Set shs = ActiveSelection.Shapes
  23. '// 按 MarkName 名称查找放置中线对准线标记等
  24. For Each sh In shs
  25. ActiveDocument.ClearSelection
  26. sh.CreateSelection
  27. If "CenterLine" = sh.ObjectData("MarkName").value Then
  28. put_center_line sh
  29. ElseIf "TargetLine" = sh.ObjectData("MarkName").value Then
  30. put_target_line sh
  31. ElseIf "ColorStrip" = sh.ObjectData("MarkName").value Then
  32. ColorStrip = Val(GetSetting("LYVBA", "Settings", "ColorStrip", "1"))
  33. If Val(ColorStrip) = 1 Then
  34. put_ColorStrip sh ' 放置彩色色阶条
  35. Else
  36. sh.Delete ' 工厂定置不用色阶条
  37. End If
  38. ElseIf "ColorMark" = sh.ObjectData("MarkName").value Then
  39. ' CMYK四色标记放置咬口
  40. If (px > py) Then
  41. sh.SetPosition px + 25#, 0
  42. Else
  43. sh.Rotate 270#
  44. ActiveDocument.ReferencePoint = cdrBottomLeft
  45. sh.SetPosition 0, py - 42#
  46. End If
  47. sh.OrderToBack
  48. Else
  49. sh.Delete ' 没找到标记 ColorMark 删除
  50. End If
  51. Next sh
  52. ' 标准页面大小和添加页面框
  53. put_page_size
  54. put_page_line
  55. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  56. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  57. ActiveSelection.Group
  58. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  59. ErrorHandler:
  60. API.EndOpt
  61. End Function
  62. Private Function set_page_size()
  63. ' 实践应用: 选择物件群组,页面设置物件大小,物件页面居中
  64. ActiveDocument.Unit = cdrMillimeter
  65. Dim OrigSelection As ShapeRange, sh As Shape
  66. Set OrigSelection = ActiveSelectionRange
  67. Set sh = OrigSelection.Group
  68. ' MsgBox "选择物件尺寸: " & sh.SizeWidth & "x" & sh.SizeHeight
  69. ActivePage.SetSize Int(sh.SizeWidth + 0.9), Int(sh.SizeHeight + 0.9)
  70. #If VBA7 Then
  71. ActiveDocument.ClearSelection
  72. sh.AddToSelection
  73. ActiveSelection.AlignAndDistribute 3, 3, 2, 0, False, 2
  74. #Else
  75. sh.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter
  76. #End If
  77. End Function
  78. Private Function set_line_color(line As Shape)
  79. '// 设置线宽和注册色
  80. line.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  81. End Function
  82. Private Function put_page_line()
  83. ' 添加页面框线
  84. Dim s1 As Shape
  85. Set s1 = ActiveLayer.CreateRectangle2(0, 0, ActivePage.SizeWidth, ActivePage.SizeHeight)
  86. s1.Fill.ApplyNoFill: s1.OrderToBack
  87. s1.Outline.SetProperties 0.01, Color:=CreateCMYKColor(100, 0, 0, 0)
  88. End Function
  89. '''--------- CorelDRAW X4 和 高版本 对齐页面API不同 ------------------'''
  90. #If VBA7 Then
  91. Private Function put_center_line(sh As Shape)
  92. ' 在页面四边放置中线
  93. set_line_color sh
  94. sh.AlignAndDistribute 3, 1, 1, 0, False, 2
  95. sh.Duplicate 0, 0
  96. sh.Rotate 180
  97. sh.AlignAndDistribute 3, 2, 1, 0, False, 2
  98. sh.Duplicate 0, 0
  99. sh.Rotate 90
  100. sh.AlignAndDistribute 1, 3, 1, 0, False, 2
  101. sh.Duplicate 0, 0
  102. sh.Rotate 180
  103. sh.AlignAndDistribute 2, 3, 1, 0, False, 2
  104. End Function
  105. Private Function put_target_line(sh As Shape)
  106. ' 在页面四角放置套准标记线
  107. set_line_color sh
  108. sh.AlignAndDistribute 2, 1, 1, 0, False, 2
  109. sh.Duplicate 0, 0
  110. sh.Rotate 180
  111. sh.AlignAndDistribute 1, 2, 1, 0, False, 2
  112. sh.Duplicate 0, 0
  113. sh.Flip cdrFlipHorizontal ' 物件镜像
  114. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  115. sh.Duplicate 0, 0
  116. sh.Rotate 180
  117. sh.AlignAndDistribute 1, 1, 1, 0, False, 2
  118. End Function
  119. Private Function put_ColorStrip(sh As Shape)
  120. ' 在页面四边放置色阶条
  121. sh.OrderToBack
  122. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  123. sh.AlignAndDistribute 2, 1, 1, 0, False, 2
  124. sh.Duplicate 5, 0
  125. sh.AlignAndDistribute 1, 1, 1, 0, False, 2
  126. sh.Duplicate -25, 0
  127. sh.Rotate 90
  128. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  129. sh.Duplicate 0, 5
  130. sh.AlignAndDistribute 1, 2, 1, 0, False, 2
  131. sh.Move 0, 5
  132. Else
  133. sh.AlignAndDistribute 2, 1, 1, 0, False, 2
  134. sh.Duplicate 5, 0
  135. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  136. sh.Duplicate 5, 0
  137. sh.Rotate 270
  138. sh.AlignAndDistribute 1, 1, 1, 0, False, 2
  139. sh.Duplicate 0, -5
  140. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  141. sh.Move 0, 25
  142. End If
  143. End Function
  144. Private Function put_page_size()
  145. ' 添加文字 页面大小和文件名
  146. Dim st As Shape
  147. size = Trim(str(Int(ActivePage.SizeWidth))) + "x" + Trim(str(Int(ActivePage.SizeHeight))) + "mm"
  148. size = size & " " & ActiveDocument.FileName & " " & Date '
  149. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 7)
  150. End Function
  151. #Else
  152. '''--------- CorelDRAW X4 对齐页面API ------------------'''
  153. Private Function put_target_line(sh As Shape)
  154. ' 在页面四角放置套准标记线 Set sh = ActiveDocument.Selection
  155. set_line_color sh
  156. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  157. sh.Duplicate 0, 0
  158. sh.Rotate 180
  159. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  160. sh.Duplicate 0, 0
  161. sh.Flip cdrFlipHorizontal ' 物件镜像
  162. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  163. sh.Duplicate 0, 0
  164. sh.Rotate 180
  165. sh.AlignToPage cdrAlignRight + cdrAlignTop
  166. End Function
  167. Private Function put_center_line(sh As Shape)
  168. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  169. set_line_color sh
  170. sh.AlignToPage cdrAlignHCenter + cdrAlignTop
  171. sh.Duplicate 0, 0
  172. sh.Rotate 180
  173. sh.AlignToPage cdrAlignHCenter + cdrAlignBottom
  174. sh.Duplicate 0, 0
  175. sh.Rotate 90
  176. sh.AlignToPage cdrAlignVCenter + cdrAlignRight
  177. sh.Duplicate 0, 0
  178. sh.Rotate 180
  179. sh.AlignToPage cdrAlignVCenter + cdrAlignLeft
  180. End Function
  181. Private Function put_ColorStrip(sh As Shape)
  182. ' 在页面四边放置色阶条 Set sh = ActiveDocument.Selection
  183. sh.OrderToBack
  184. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  185. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  186. sh.Duplicate 5, 0
  187. sh.AlignToPage cdrAlignRight + cdrAlignTop
  188. sh.Duplicate -25, 0
  189. sh.Rotate 90
  190. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  191. sh.Duplicate 0, 5
  192. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  193. sh.Move 0, 5
  194. Else
  195. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  196. sh.Duplicate 5, 0
  197. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  198. sh.Duplicate 5, 0
  199. sh.Rotate 270
  200. sh.AlignToPage cdrAlignRight + cdrAlignTop
  201. sh.Duplicate 0, -5
  202. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  203. sh.Move 0, 25
  204. End If
  205. End Function
  206. Private Function put_page_size()
  207. ' 添加文字 页面大小
  208. Dim st As Shape
  209. size = Trim(str(Int(ActivePage.SizeWidth))) + "x" + Trim(str(Int(ActivePage.SizeHeight))) + "mm"
  210. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 7)
  211. st.AlignToPage cdrAlignRight + cdrAlignTop
  212. st.Move -3, -0.6
  213. End Function
  214. #End If
  215. ' 自动中线 For 黑白产品版
  216. Function Auto_ColorMark_K()
  217. If 0 = ActiveSelectionRange.Count Then Exit Function
  218. On Error GoTo ErrorHandler
  219. API.BeginOpt
  220. Dim doc As Document: Set doc = ActiveDocument
  221. ' 物件群组,设置页面大小
  222. set_page_size
  223. '// 获得页面中心点 x,y
  224. px = ActiveDocument.ActivePage.CenterX
  225. py = ActiveDocument.ActivePage.CenterY
  226. '// 导入色阶条中线对准线标记文件 ColorMark.cdr 解散群组
  227. doc.ActiveLayer.Import path & "GMS\ColorMark.cdr"
  228. ActiveDocument.ReferencePoint = cdrBottomMiddle
  229. ' ActiveDocument.Selection.SetPosition px, -100
  230. ActiveDocument.Selection.Ungroup
  231. Dim sh As Shape, shs As Shapes
  232. Set shs = ActiveSelection.Shapes
  233. '// 按 MarkName 名称查找放置中线对准线标记等
  234. For Each sh In shs
  235. ActiveDocument.ClearSelection
  236. sh.CreateSelection
  237. If "CenterLine" = sh.ObjectData("MarkName").value Then
  238. put_center_line sh
  239. ElseIf "TargetLine" = sh.ObjectData("MarkName").value Then
  240. put_target_line sh
  241. ElseIf "ColorStrip" = sh.ObjectData("MarkName").value Then
  242. sh.Delete ' 工厂定置不用色阶条
  243. ElseIf "ColorMark_K" = sh.ObjectData("MarkName").value Then
  244. ' 只放置单色黑
  245. If (px > py) Then
  246. sh.SetPosition px + 25#, 0
  247. Else
  248. sh.Rotate 270#
  249. ActiveDocument.ReferencePoint = cdrBottomLeft
  250. sh.SetPosition 0, py - 42#
  251. End If
  252. sh.OrderToBack
  253. Else
  254. sh.Delete ' 没找到标记 ColorMark 删除
  255. End If
  256. Next sh
  257. ' 标准页面大小和添加页面框
  258. put_page_size
  259. put_page_line
  260. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  261. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  262. ActiveSelection.Group
  263. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  264. ErrorHandler:
  265. API.EndOpt
  266. End Function