自动中线色阶条.bas 10 KB

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