自动中线色阶条.bas 10.0 KB

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