AutoColorMark.bas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. Sub Auto_ColorMark()
  7. If 0 = ActiveSelectionRange.Count Then Exit Sub
  8. On Error GoTo ErrorHandler
  9. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  10. Dim doc As Document: Set doc = ActiveDocument: doc.Unit = cdrMillimeter
  11. ' 物件群组,设置页面大小
  12. Call 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("262235.xyz", "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. '// 代码操作结束恢复窗口刷新
  60. ActiveDocument.EndCommandGroup
  61. Application.Optimization = False
  62. ActiveWindow.Refresh: Application.Refresh
  63. Exit Sub
  64. ErrorHandler:
  65. MsgBox "请先选择要印刷的物件群组,本插件完成设置页面大小,自动中线色阶条对准线功能!"
  66. Application.Optimization = False
  67. On Error Resume Next
  68. End Sub
  69. Private Sub set_page_size()
  70. ' 实践应用: 选择物件群组,页面设置物件大小,物件页面居中
  71. ActiveDocument.Unit = cdrMillimeter
  72. Dim OrigSelection As ShapeRange, sh As Shape
  73. Set OrigSelection = ActiveSelectionRange
  74. Set sh = OrigSelection.group
  75. ' MsgBox "选择物件尺寸: " & sh.SizeWidth & "x" & sh.SizeHeight
  76. ActivePage.SetSize Int(sh.SizeWidth + 0.9), Int(sh.SizeHeight + 0.9)
  77. #If VBA7 Then
  78. ActiveDocument.ClearSelection
  79. sh.AddToSelection
  80. ActiveSelection.AlignAndDistribute 3, 3, 2, 0, False, 2
  81. #Else
  82. sh.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter
  83. #End If
  84. End Sub
  85. Private Function set_line_color(line As Shape)
  86. '// 设置线宽和注册色
  87. line.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  88. End Function
  89. Private Function put_page_line()
  90. ' 添加页面框线
  91. Dim s1 As Shape
  92. Set s1 = ActiveLayer.CreateRectangle2(0, 0, ActivePage.SizeWidth, ActivePage.SizeHeight)
  93. s1.Fill.ApplyNoFill: s1.OrderToBack
  94. s1.Outline.SetProperties 0.01, Color:=CreateCMYKColor(100, 0, 0, 0)
  95. End Function
  96. '''--------- CorelDRAW X4 和 高版本 对齐页面API不同 ------------------'''
  97. #If VBA7 Then
  98. Private Function put_center_line(sh As Shape)
  99. ' 在页面四边放置中线
  100. set_line_color sh
  101. sh.AlignAndDistribute 3, 1, 1, 0, False, 2
  102. sh.Duplicate 0, 0
  103. sh.Rotate 180
  104. sh.AlignAndDistribute 3, 2, 1, 0, False, 2
  105. sh.Duplicate 0, 0
  106. sh.Rotate 90
  107. sh.AlignAndDistribute 1, 3, 1, 0, False, 2
  108. sh.Duplicate 0, 0
  109. sh.Rotate 180
  110. sh.AlignAndDistribute 2, 3, 1, 0, False, 2
  111. End Function
  112. Private Function put_target_line(sh As Shape)
  113. ' 在页面四角放置套准标记线
  114. set_line_color sh
  115. sh.AlignAndDistribute 2, 1, 1, 0, False, 2
  116. sh.Duplicate 0, 0
  117. sh.Rotate 180
  118. sh.AlignAndDistribute 1, 2, 1, 0, False, 2
  119. sh.Duplicate 0, 0
  120. sh.Flip cdrFlipHorizontal ' 物件镜像
  121. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  122. sh.Duplicate 0, 0
  123. sh.Rotate 180
  124. sh.AlignAndDistribute 1, 1, 1, 0, False, 2
  125. End Function
  126. Private Function put_ColorStrip(sh As Shape)
  127. ' 在页面四边放置色阶条
  128. sh.OrderToBack
  129. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  130. sh.AlignAndDistribute 2, 1, 1, 0, False, 2
  131. sh.Duplicate 5, 0
  132. sh.AlignAndDistribute 1, 1, 1, 0, False, 2
  133. sh.Duplicate -25, 0
  134. sh.Rotate 90
  135. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  136. sh.Duplicate 0, 5
  137. sh.AlignAndDistribute 1, 2, 1, 0, False, 2
  138. sh.Move 0, 5
  139. Else
  140. sh.AlignAndDistribute 2, 1, 1, 0, False, 2
  141. sh.Duplicate 5, 0
  142. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  143. sh.Duplicate 5, 0
  144. sh.Rotate 270
  145. sh.AlignAndDistribute 1, 1, 1, 0, False, 2
  146. sh.Duplicate 0, -5
  147. sh.AlignAndDistribute 2, 2, 1, 0, False, 2
  148. sh.Move 0, 25
  149. End If
  150. End Function
  151. Private Function put_page_size()
  152. ' 添加文字 页面大小和文件名
  153. Dim st As Shape
  154. size = Trim(Str(Int(ActivePage.SizeWidth))) + "x" + Trim(Str(Int(ActivePage.SizeHeight))) + "mm"
  155. size = size & " " & ActiveDocument.FileName & " " & Date ' & vbNewLine & "Https://262235.xyz 需要您的支持!"
  156. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 7)
  157. End Function
  158. #Else
  159. '''--------- CorelDRAW X4 对齐页面API ------------------'''
  160. Private Function put_target_line(sh As Shape)
  161. ' 在页面四角放置套准标记线 Set sh = ActiveDocument.Selection
  162. set_line_color sh
  163. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  164. sh.Duplicate 0, 0
  165. sh.Rotate 180
  166. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  167. sh.Duplicate 0, 0
  168. sh.Flip cdrFlipHorizontal ' 物件镜像
  169. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  170. sh.Duplicate 0, 0
  171. sh.Rotate 180
  172. sh.AlignToPage cdrAlignRight + cdrAlignTop
  173. End Function
  174. Private Function put_center_line(sh As Shape)
  175. ' 在页面四边放置中线 Set sh = ActiveDocument.Selection
  176. set_line_color sh
  177. sh.AlignToPage cdrAlignHCenter + cdrAlignTop
  178. sh.Duplicate 0, 0
  179. sh.Rotate 180
  180. sh.AlignToPage cdrAlignHCenter + cdrAlignBottom
  181. sh.Duplicate 0, 0
  182. sh.Rotate 90
  183. sh.AlignToPage cdrAlignVCenter + cdrAlignRight
  184. sh.Duplicate 0, 0
  185. sh.Rotate 180
  186. sh.AlignToPage cdrAlignVCenter + cdrAlignLeft
  187. End Function
  188. Private Function put_ColorStrip(sh As Shape)
  189. ' 在页面四边放置色阶条 Set sh = ActiveDocument.Selection
  190. sh.OrderToBack
  191. If ActivePage.SizeWidth >= ActivePage.SizeHeight Then
  192. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  193. sh.Duplicate 5, 0
  194. sh.AlignToPage cdrAlignRight + cdrAlignTop
  195. sh.Duplicate -25, 0
  196. sh.Rotate 90
  197. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  198. sh.Duplicate 0, 5
  199. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  200. sh.Move 0, 5
  201. Else
  202. sh.AlignToPage cdrAlignLeft + cdrAlignTop
  203. sh.Duplicate 5, 0
  204. sh.AlignToPage cdrAlignLeft + cdrAlignBottom
  205. sh.Duplicate 5, 0
  206. sh.Rotate 270
  207. sh.AlignToPage cdrAlignRight + cdrAlignTop
  208. sh.Duplicate 0, -5
  209. sh.AlignToPage cdrAlignRight + cdrAlignBottom
  210. sh.Move 0, 25
  211. End If
  212. End Function
  213. Private Function put_page_size()
  214. ' 添加文字 页面大小
  215. Dim st As Shape
  216. size = Trim(Str(Int(ActivePage.SizeWidth))) + "x" + Trim(Str(Int(ActivePage.SizeHeight))) + "mm"
  217. Set st = ActiveLayer.CreateArtisticText(0, 0, size, , , "Arial", 7)
  218. st.AlignToPage cdrAlignRight + cdrAlignTop
  219. st.Move -3, -0.6
  220. End Function
  221. #End If
  222. ' 自动中线 For 黑白产品版
  223. Sub Auto_ColorMark_K()
  224. If 0 = ActiveSelectionRange.Count Then Exit Sub
  225. On Error GoTo ErrorHandler
  226. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  227. Dim doc As Document: Set doc = ActiveDocument: doc.Unit = cdrMillimeter
  228. ' 物件群组,设置页面大小
  229. Call set_page_size
  230. '// 获得页面中心点 x,y
  231. px = ActiveDocument.ActivePage.CenterX
  232. py = ActiveDocument.ActivePage.CenterY
  233. '// 导入色阶条中线对准线标记文件 ColorMark.cdr 解散群组
  234. doc.ActiveLayer.Import Path & "GMS\ColorMark.cdr"
  235. ActiveDocument.ReferencePoint = cdrBottomMiddle
  236. ' ActiveDocument.Selection.SetPosition px, -100
  237. ActiveDocument.Selection.Ungroup
  238. Dim sh As Shape, shs As Shapes
  239. Set shs = ActiveSelection.Shapes
  240. '// 按 MarkName 名称查找放置中线对准线标记等
  241. For Each sh In shs
  242. ActiveDocument.ClearSelection
  243. sh.CreateSelection
  244. If "CenterLine" = sh.ObjectData("MarkName").value Then
  245. put_center_line sh
  246. ElseIf "TargetLine" = sh.ObjectData("MarkName").value Then
  247. put_target_line sh
  248. ElseIf "ColorStrip" = sh.ObjectData("MarkName").value Then
  249. sh.Delete ' 工厂定置不用色阶条
  250. ElseIf "ColorMark_K" = sh.ObjectData("MarkName").value Then
  251. ' 只放置单色黑
  252. If (px > py) Then
  253. sh.SetPosition px + 25#, 0
  254. Else
  255. sh.Rotate 270#
  256. ActiveDocument.ReferencePoint = cdrBottomLeft
  257. sh.SetPosition 0, py - 42#
  258. End If
  259. sh.OrderToBack
  260. Else
  261. sh.Delete ' 没找到标记 ColorMark 删除
  262. End If
  263. Next sh
  264. ' 标准页面大小和添加页面框
  265. put_page_size
  266. put_page_line
  267. '// 使用CQL 颜色标志查找,然后群组统一设置线宽和注册色
  268. ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
  269. ActiveSelection.group
  270. ActiveSelection.Outline.SetProperties 0.1, Color:=CreateRegistrationColor
  271. '// 代码操作结束恢复窗口刷新
  272. ActiveDocument.EndCommandGroup
  273. Application.Optimization = False
  274. ActiveWindow.Refresh: Application.Refresh
  275. Exit Sub
  276. ErrorHandler:
  277. MsgBox "请先选择要印刷的物件群组,本插件完成设置页面大小,自动中线色阶条对准线功能!"
  278. Application.Optimization = False
  279. On Error Resume Next
  280. End Sub