AutoColorMark.bas 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. st.AlignAndDistribute 1, 1, 1, 0, False, 2
  151. st.Move -3, -0.6
  152. st.ConvertToCurves
  153. End Function
  154. #Else
  155. '''--------- CorelDRAW X4 对齐页面API ------------------'''
  156. Private Function put_target_line(sh As Shape)
  157. ' 在页面四角放置套准标记线 Set sh = ActiveDocument.Selection
  158. set_line_color sh
  159. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  160. sh.Duplicate 0, 0
  161. sh.Rotate 180
  162. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  163. sh.Duplicate 0, 0
  164. sh.Flip cdrFlipHorizontal ' 物件镜像
  165. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  166. sh.Duplicate 0, 0
  167. sh.Rotate 180
  168. sh.AlignToPage cdrAlignRight + cdrAlignTop
  169. End Function
  170. Private Function put_center_line(sh As Shape)
  171. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  172. set_line_color sh
  173. sh.AlignToPage cdrAlignHCenter + cdrAlignTop
  174. sh.Duplicate 0, 0
  175. sh.Rotate 180
  176. sh.AlignToPage cdrAlignHCenter + cdrAlignBottom
  177. sh.Duplicate 0, 0
  178. sh.Rotate 90
  179. sh.AlignToPage cdrAlignVCenter + cdrAlignRight
  180. sh.Duplicate 0, 0
  181. sh.Rotate 180
  182. sh.AlignToPage cdrAlignVCenter + cdrAlignLeft
  183. End Function
  184. Private Function put_ColorStrip(sh As Shape)
  185. ' 在页面四边放置色阶条 Set sh = ActiveDocument.Selection
  186. sh.OrderToBack
  187. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  188. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  189. sh.Duplicate 5, 0
  190. sh.AlignToPage cdrAlignRight + cdrAlignTop
  191. sh.Duplicate -25, 0
  192. sh.Rotate 90
  193. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  194. sh.Duplicate 0, 5
  195. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  196. sh.Move 0, 5
  197. Else
  198. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  199. sh.Duplicate 5, 0
  200. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  201. sh.Duplicate 5, 0
  202. sh.Rotate 270
  203. sh.AlignToPage cdrAlignRight + cdrAlignTop
  204. sh.Duplicate 0, -5
  205. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  206. sh.Move 0, 25
  207. End If
  208. End Function
  209. Private Function put_page_size()
  210. ' 添加文字 页面大小
  211. Dim st As Shape
  212. size = Trim(str(Int(ActivePage.SizeWidth))) + "x" + Trim(str(Int(ActivePage.SizeHeight))) + "mm"
  213. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 7)
  214. st.AlignToPage cdrAlignRight + cdrAlignTop
  215. st.Move -3, -0.6
  216. st.ConvertToCurves
  217. End Function
  218. #End If
  219. ' 自动中线 For 黑白产品版
  220. Function Auto_ColorMark_K()
  221. If 0 = ActiveSelectionRange.count Then Exit Function
  222. On Error GoTo ErrorHandler
  223. API.BeginOpt
  224. Dim doc As Document: Set doc = ActiveDocument
  225. ' 物件群组,设置页面大小
  226. set_page_size
  227. '// 获得页面中心点 x,y
  228. px = ActiveDocument.ActivePage.CenterX
  229. py = ActiveDocument.ActivePage.CenterY
  230. '// 导入色阶条中线对准线标记文件 ColorMark.cdr 解散群组
  231. doc.ActiveLayer.Import path & "GMS\ColorMark.cdr"
  232. ActiveDocument.ReferencePoint = cdrBottomMiddle
  233. ' ActiveDocument.Selection.SetPosition px, -100
  234. ActiveDocument.Selection.Ungroup
  235. Dim sh As Shape, shs As Shapes
  236. Set shs = ActiveSelection.Shapes
  237. '// 按 MarkName 名称查找放置中线对准线标记等
  238. For Each sh In shs
  239. ActiveDocument.ClearSelection
  240. sh.CreateSelection
  241. If "CenterLine" = sh.ObjectData("MarkName").value Then
  242. put_center_line sh
  243. ElseIf "TargetLine" = sh.ObjectData("MarkName").value Then
  244. put_target_line sh
  245. ElseIf "ColorStrip" = sh.ObjectData("MarkName").value Then
  246. sh.Delete ' 工厂定置不用色阶条
  247. ElseIf "ColorMark_K" = sh.ObjectData("MarkName").value Then
  248. ' 只放置单色黑
  249. If (px > py) Then
  250. sh.SetPosition px + 25#, 0
  251. Else
  252. sh.Rotate 270#
  253. ActiveDocument.ReferencePoint = cdrBottomLeft
  254. sh.SetPosition 0, py - 42#
  255. End If
  256. sh.OrderToBack
  257. Else
  258. sh.Delete ' 没找到标记 ColorMark 删除
  259. End If
  260. Next sh
  261. ' 标准页面大小和添加页面框
  262. put_page_size
  263. put_page_line
  264. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  265. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  266. ActiveSelection.Group
  267. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  268. ErrorHandler:
  269. API.EndOpt
  270. End Function