1
1

MakeSizePlus.frm 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} MakeSizePlus
  3. Caption = "Batch Dimensions Plus"
  4. ClientHeight = 3630
  5. ClientLeft = 45
  6. ClientTop = 330
  7. ClientWidth = 5115
  8. OleObjectBlob = "MakeSizePlus.frx":0000
  9. StartUpPosition = 1 'CenterOwner
  10. End
  11. Attribute VB_Name = "MakeSizePlus"
  12. Attribute VB_GlobalNameSpace = False
  13. Attribute VB_Creatable = False
  14. Attribute VB_PredeclaredId = True
  15. Attribute VB_Exposed = False
  16. '// This is free and unencumbered software released into the public domain.
  17. '// For more information, please refer to https://github.com/hongwenjun
  18. #If VBA7 Then
  19. Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
  20. Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  21. Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  22. Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  23. Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  24. #Else
  25. Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
  26. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  27. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  28. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  29. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  30. #End If
  31. Private Const GWL_STYLE As Long = (-16)
  32. Private Const GWL_EXSTYLE = (-20)
  33. Private Const WS_CAPTION As Long = &HC00000
  34. Private Const WS_EX_DLGMODALFRAME = &H1&
  35. '// 插件名称 VBA_UserForm
  36. Private Const TOOLNAME As String = "LYVBA"
  37. Private Const SECTION As String = "MakeSizePlus"
  38. Private sreg As New ShapeRange
  39. Private Sub UserForm_Initialize()
  40. With Me
  41. .StartUpPosition = 0
  42. .Left = Val(GetSetting(TOOLNAME, SECTION, "form_left", 900))
  43. .Top = Val(GetSetting(TOOLNAME, SECTION, "form_top", 200))
  44. .width = Val(GetSetting(TOOLNAME, SECTION, "form_width", 200))
  45. .Height = Val(GetSetting(TOOLNAME, SECTION, "form_Height", 105))
  46. End With
  47. LNG_CODE = API.GetLngCode
  48. Init_Translations Me, LNG_CODE
  49. Me.Caption = i18n("Batch Dimensions Plus", LNG_CODE)
  50. ' 读取线设置
  51. Bleed.text = API.GetSet("Bleed")
  52. Line_len.text = API.GetSet("Line_len")
  53. Outline_Width.text = GetSetting("LYVBA", "Settings", "Outline_Width", "0.2")
  54. Font_Size.text = GetSetting("LYVBA", "Settings", "Font_Size", "18")
  55. End Sub
  56. '// 关闭窗口时保存窗口位置
  57. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  58. saveFormPos True
  59. End Sub
  60. '// 保存窗口位置和加载窗口位置
  61. Sub saveFormPos(bDoSave As Boolean)
  62. If bDoSave Then 'save position
  63. SaveSetting TOOLNAME, SECTION, "form_left", Me.Left
  64. SaveSetting TOOLNAME, SECTION, "form_top", Me.Top
  65. SaveSetting TOOLNAME, SECTION, "form_width", Me.width
  66. SaveSetting TOOLNAME, SECTION, "form_Height", Me.Height
  67. End If
  68. End Sub
  69. Private Sub btn_ExpandForm_Click()
  70. With Me
  71. If .width = 200 Then
  72. .width = 260: .Height = 132
  73. ElseIf .Height = 132 Then
  74. .Height = 206
  75. Else
  76. .width = 200: .Height = 105
  77. End If
  78. End With
  79. End Sub
  80. '// Minimizes the window and retains dimensioning functionality '// 最小化窗口并保留标注尺寸功能
  81. Private Function MiniForm()
  82. Dim IStyle As Long
  83. Dim hwnd As Long
  84. hwnd = FindWindow("ThunderDFrame", MakeSizePlus.Caption)
  85. IStyle = GetWindowLong(hwnd, GWL_STYLE)
  86. IStyle = IStyle And Not WS_CAPTION
  87. SetWindowLong hwnd, GWL_STYLE, IStyle
  88. DrawMenuBar hwnd
  89. IStyle = GetWindowLong(hwnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME
  90. SetWindowLong hwnd, GWL_EXSTYLE, IStyle
  91. Dim ctl As Variant '// CorelDRAW 2020 定义成 Variant 才不会错误
  92. For Each ctl In MakeSizePlus.Controls
  93. ctl.Visible = False
  94. ctl.Top = 2
  95. Next ctl
  96. With Me
  97. .StartUpPosition = 0
  98. .BackColor = &H80000012
  99. .Left = Val(GetSetting("LYVBA", "Settings", "Left", "400")) + 318
  100. .Top = Val(GetSetting("LYVBA", "Settings", "Top", "55")) - 2
  101. .Height = 28
  102. .width = 98
  103. .MarkLines_Makesize.Visible = True
  104. .btn_Makesizes.Visible = True
  105. .Manual_Makesize.Visible = True
  106. .chkOpposite.Visible = True
  107. .X_EXIT.Visible = True
  108. .MarkLines_Makesize.Left = 1
  109. .btn_Makesizes.Left = 26
  110. .Manual_Makesize.Left = 50
  111. .chkOpposite.Left = 75: .chkOpposite.Top = 14
  112. .X_EXIT.Left = 85: .X_EXIT.Top = 0
  113. End With
  114. End Function
  115. Private Sub btn_MiniForm_Click()
  116. MiniForm
  117. End Sub
  118. Private Sub Settings_Click()
  119. If 0 < Val(Bleed.text) * Val(Line_len.text) < 100 Then
  120. SaveSetting "LYVBA", "Settings", "Bleed", Bleed.text
  121. SaveSetting "LYVBA", "Settings", "Line_len", Line_len.text
  122. SaveSetting "LYVBA", "Settings", "Outline_Width", Outline_Width.text
  123. SaveSetting "LYVBA", "Settings", "Font_Size", Font_Size.text
  124. Call API.Set_Space_Width '// 设置空间间隙
  125. End If
  126. End Sub
  127. Private Sub btn_Makesizes_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  128. On Error GoTo ErrorHandler
  129. API.BeginOpt
  130. Dim os As ShapeRange
  131. Dim s As Shape
  132. Dim sr As ShapeRange
  133. Set doc = ActiveDocument
  134. Set sr = ActiveSelectionRange
  135. sr.RemoveAll
  136. If Shift = 4 Then
  137. Set os = ActiveSelectionRange
  138. For Each s In os.Shapes
  139. If s.Type = cdrTextShape Then sr.Add s
  140. Next s
  141. sr.CreateSelection
  142. ElseIf Shift = 1 Then
  143. Set os = ActiveSelectionRange
  144. For Each s In os.Shapes
  145. If s.Type = cdrLinearDimensionShape Then sr.Add s
  146. Next s
  147. sr.CreateSelection
  148. ElseIf Shift = 2 Then
  149. Set os = ActiveSelectionRange
  150. For Each s In os.Shapes
  151. If s.Type = cdrLinearDimensionShape Then sr.Add s
  152. Next s
  153. sr.Delete
  154. If os.count > 0 Then
  155. os.Shapes.FindShapes(Query:="@name ='DMKLine'").CreateSelection
  156. ActiveSelectionRange.Delete
  157. End If
  158. Else
  159. make_sizes Shift
  160. End If
  161. ErrorHandler:
  162. API.EndOpt
  163. End Sub
  164. Sub make_sizes_sep(dr, Optional shft = 0, Optional ByVal mirror As Boolean = False)
  165. On Error GoTo ErrorHandler
  166. API.BeginOpt "Make Size"
  167. Set doc = ActiveDocument
  168. Dim s As Shape, sh As Shape
  169. Dim pts As New SnapPoint, pte As New SnapPoint
  170. Dim os As ShapeRange
  171. Set os = ActiveSelectionRange
  172. Dim border As Variant
  173. Dim Line_len As Double
  174. Line_len = API.Set_Space_Width(True) '// 读取间隔
  175. border = Array(cdrBottomRight, cdrBottomLeft, os.topY + Line_len, os.topY + 2 * Line_len, _
  176. cdrBottomRight, cdrTopRight, os.LeftX - Line_len, os.LeftX - 2 * Line_len)
  177. If mirror = True Then border = Array(cdrTopRight, cdrTopLeft, os.BottomY - Line_len, os.BottomY - 2 * Line_len, _
  178. cdrBottomLeft, cdrTopLeft, os.RightX + Line_len, os.RightX + 2 * Line_len)
  179. If dr = "upbx" Or dr = "upb" Or dr = "dnb" Or dr = "up" Or dr = "dn" Then Set os = X4_Sort_ShapeRange(os, stlx)
  180. If dr = "lfbx" Or dr = "lfb" Or dr = "rib" Or dr = "lf" Or dr = "ri" Then Set os = X4_Sort_ShapeRange(os, stty).ReverseRange
  181. If os.count > 0 Then
  182. If os.count > 1 And Len(dr) > 2 And os.Shapes.count > 1 Then
  183. For i = 1 To os.Shapes.count - 1
  184. Select Case dr
  185. Case "upbx"
  186. #If VBA7 Then
  187. Set pts = os.Shapes(i).SnapPoints.BBox(border(0))
  188. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(1))
  189. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(2), cdrDimensionStyleEngineering)
  190. If shft > 0 And i = 1 Then
  191. Dimension_SetProperty sh, PresetProperty.value, mirror
  192. Set pts = os.FirstShape.SnapPoints.BBox(border(0))
  193. Set pte = os.LastShape.SnapPoints.BBox(border(1))
  194. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(3), cdrDimensionStyleEngineering)
  195. End If
  196. Case "lfbx"
  197. Set pts = os.Shapes(i).SnapPoints.BBox(border(4))
  198. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(5))
  199. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(6), 0, cdrDimensionStyleEngineering)
  200. If shft > 0 And i = 1 Then
  201. Dimension_SetProperty sh, PresetProperty.value, mirror
  202. Set pts = os.FirstShape.SnapPoints.BBox(border(4))
  203. Set pte = os.LastShape.SnapPoints.BBox(border(5))
  204. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(7), 0, cdrDimensionStyleEngineering)
  205. End If
  206. #Else
  207. ' X4 There is a difference
  208. Set pts = CreateSnapPoint(os.Shapes(i).CenterX, os.Shapes(i).CenterY)
  209. Set pte = CreateSnapPoint(os.Shapes(i + 1).CenterX, os.Shapes(i + 1).CenterY)
  210. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(2), Textsize:=18)
  211. Case "lfbx"
  212. Set pts = CreateSnapPoint(os.Shapes(i).CenterX, os.Shapes(i).CenterY)
  213. Set pte = CreateSnapPoint(os.Shapes(i + 1).CenterX, os.Shapes(i + 1).CenterY)
  214. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(6), 0, Textsize:=18)
  215. #End If
  216. Case "upb"
  217. Set pts = os.Shapes(i).SnapPoints.BBox(cdrTopRight)
  218. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  219. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.topY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  220. Case "dnb"
  221. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  222. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrBottomLeft)
  223. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering)
  224. Case "lfb"
  225. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomLeft)
  226. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  227. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  228. Case "rib"
  229. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  230. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopRight)
  231. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  232. End Select
  233. '// 尺寸标注设置属性
  234. Dimension_SetProperty sh, PresetProperty.value, mirror
  235. 'ActiveDocument.ClearSelection
  236. Next i
  237. Else
  238. If shft > 0 Then
  239. Select Case dr
  240. Case "up"
  241. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  242. Set pte = os.LastShape.SnapPoints.BBox(cdrTopRight)
  243. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.topY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  244. Case "dn"
  245. Set pts = os.FirstShape.SnapPoints.BBox(cdrBottomLeft)
  246. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  247. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering)
  248. Case "lf"
  249. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  250. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomLeft)
  251. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  252. Case "ri"
  253. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopRight)
  254. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  255. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  256. End Select
  257. Dimension_SetProperty sh, PresetProperty.value, mirror
  258. Else
  259. For Each s In os.Shapes
  260. Select Case dr
  261. Case "up"
  262. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  263. Set pte = s.SnapPoints.BBox(cdrTopRight)
  264. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.topY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  265. Case "dn"
  266. Set pts = s.SnapPoints.BBox(cdrBottomLeft)
  267. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  268. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.BottomY - s.SizeHeight / 10, cdrDimensionStyleEngineering)
  269. Case "lf"
  270. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  271. Set pte = s.SnapPoints.BBox(cdrBottomLeft)
  272. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  273. Case "ri"
  274. Set pts = s.SnapPoints.BBox(cdrTopRight)
  275. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  276. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, s.RightX + s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  277. End Select
  278. Dimension_SetProperty sh, PresetProperty.value, mirror
  279. Next s
  280. End If
  281. End If
  282. End If
  283. os.CreateSelection
  284. ErrorHandler:
  285. API.EndOpt
  286. End Sub
  287. Sub make_sizes(Optional shft = 0)
  288. On Error GoTo ErrorHandler
  289. API.BeginOpt
  290. Dim s As Shape
  291. Dim pts As SnapPoint, pte As SnapPoint
  292. Dim os As ShapeRange
  293. Set os = ActiveSelectionRange
  294. If os.count > 0 Then
  295. For Each s In os.Shapes
  296. #If VBA7 Then
  297. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  298. Set pte = s.SnapPoints.BBox(cdrTopRight)
  299. Set ptle = s.SnapPoints.BBox(cdrBottomLeft)
  300. If shft <> 6 Then Dimension_SetProperty ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, ptle, True, _
  301. s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering), PresetProperty.value
  302. If shft <> 3 Then Dimension_SetProperty ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, _
  303. s.LeftX + s.SizeWidth / 10, s.topY + s.SizeHeight / 10, cdrDimensionStyleEngineering), PresetProperty.value
  304. #Else
  305. ' X4 There is a difference
  306. Set pts = s.SnapPoints(cdrTopLeft)
  307. Set pte = s.SnapPoints(cdrTopRight)
  308. Set ptle = s.SnapPoints(cdrBottomLeft)
  309. If shft <> 6 Then ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, ptle, True, _
  310. s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering, Textsize:=18
  311. If shft <> 3 Then ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, _
  312. s.LeftX + s.SizeWidth / 10, s.topY + s.SizeHeight / 10, cdrDimensionStyleEngineering, Textsize:=18
  313. #End If
  314. Next s
  315. End If
  316. ErrorHandler:
  317. API.EndOpt
  318. End Sub
  319. '// 使用标记线批量建立尺寸标注: 左键上标注,右键右标注
  320. Private Sub MarkLines_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  321. SRMInst 3, "sw"
  322. '// 右键
  323. If Button = 2 Then
  324. If chkOpposite.value = True Then
  325. CutLines.Dimension_MarkLines cdrAlignTop, True
  326. make_sizes_sep "upbx", Shift, True
  327. Else
  328. CutLines.Dimension_MarkLines cdrAlignLeft, True
  329. make_sizes_sep "lfbx", Shift, True
  330. End If
  331. '// 左键
  332. ElseIf Button = 1 Then
  333. If chkOpposite.value = True Then
  334. CutLines.Dimension_MarkLines cdrAlignLeft, False
  335. make_sizes_sep "lfbx", Shift, False
  336. Else
  337. CutLines.Dimension_MarkLines cdrAlignTop, False
  338. make_sizes_sep "upbx", Shift, False
  339. End If
  340. End If
  341. SRMInst 3, "lw"
  342. End Sub
  343. '// 自动酷炫风格标注
  344. Private Sub CoolStyle_Click()
  345. SRMInst 3, "sw"
  346. CutLines.Dimension_MarkLines cdrAlignTop, False
  347. make_sizes_sep "upbx", Shift, False
  348. SRMInst 3, "lw"
  349. CutLines.Dimension_MarkLines cdrAlignLeft, False
  350. make_sizes_sep "lfbx", Shift, False
  351. SRMInst 3, "lw"
  352. CutLines.Dimension_MarkLines cdrAlignTop, True
  353. make_sizes_sep "upbx", Shift, True
  354. SRMInst 3, "lw"
  355. CutLines.Dimension_MarkLines cdrAlignLeft, True
  356. make_sizes_sep "lfbx", Shift, True
  357. SRMInst 3, "lw"
  358. End Sub
  359. '// 快速标注尺寸样式
  360. Private Sub QuickStyle_Click()
  361. Dim os As ShapeRange
  362. Set os = ActiveSelectionRange
  363. SRMInst 3, "sw"
  364. CutLines.Dimension_MarkLines cdrAlignTop, True
  365. make_sizes_sep "upbx", 2, True
  366. SRMInst 4, "sw"
  367. SRMInst 3, "lw"
  368. CutLines.Dimension_MarkLines cdrAlignLeft, False
  369. make_sizes_sep "lfbx", Shift, False
  370. SRMInst 4, "lw"
  371. Dim sr As ShapeRange
  372. Set sr = ActiveSelectionRange
  373. sr.Sort "@shape1.left<@shape2.left"
  374. If sr.count > 5 And IsAllSameSize(os) Then
  375. n = sr.count
  376. sr.Remove n: sr.Remove (n - 1)
  377. sr.Remove 3: sr.Remove 2: sr.Remove 1
  378. sr.Delete
  379. End If
  380. SRMInst 3, "lw"
  381. End Sub
  382. '// 标注文字红色,分离标注
  383. Private Sub QuickRedText_Click()
  384. SRMInst 3, "sw"
  385. '// 选择文本,改成红色
  386. ModulePlus.Dimension_Select_or_Delete 4
  387. Dim sr As ShapeRange
  388. Set sr = ActiveSelectionRange
  389. sr.ApplyUniformFill CreateCMYKColor(0, 100, 100, 0)
  390. '// 解绑标注线
  391. SRMInst 3, "lw"
  392. ModulePlus.Untie_MarkLines
  393. SRMInst 3, "lw"
  394. End Sub
  395. '// 使用手工选节点建立尺寸标注,使用Ctrl分离尺寸标注
  396. Private Sub Manual_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  397. If Button = 2 Then
  398. '// 右键
  399. ElseIf Shift = fmCtrlMask Then
  400. Slanted_Makesize '// 手动标注倾斜尺寸
  401. Else
  402. ModulePlus.Untie_MarkLines '// 解绑尺寸,分离尺寸
  403. End If
  404. End Sub
  405. '// 手动标注倾斜尺寸
  406. Private Function Slanted_Makesize()
  407. On Error GoTo ErrorHandler
  408. API.BeginOpt
  409. Dim nr As NodeRange, cnt As Integer
  410. Dim sr As ShapeRange, sh As Shape
  411. Dim x1 As Double, y1 As Double
  412. Dim x2 As Double, y2 As Double
  413. Set sr = ActiveSelectionRange
  414. Set nr = ActiveShape.Curve.Selection
  415. If chkOpposite.value = False Then
  416. Slanted_Sort_Make sr '// 排序标注倾斜尺寸
  417. Exit Function
  418. End If
  419. If nr.count < 2 Then Exit Function
  420. cnt = nr.count
  421. While cnt > 1
  422. x1 = nr(cnt).PositionX
  423. y1 = nr(cnt).PositionY
  424. x2 = nr(cnt - 1).PositionX
  425. y2 = nr(cnt - 1).PositionY
  426. Set pts = CreateSnapPoint(x1, y1)
  427. Set pte = CreateSnapPoint(x2, y2)
  428. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  429. Dimension_SetProperty sh, PresetProperty.value, mirror
  430. cnt = cnt - 1
  431. Wend
  432. ErrorHandler:
  433. API.EndOpt
  434. End Function
  435. '// 排序标注倾斜尺寸
  436. Private Function Slanted_Sort_Make(shs As ShapeRange)
  437. On Error GoTo ErrorHandler
  438. Dim sr As New ShapeRange
  439. Dim s As Shape, sh As Shape
  440. Dim nr As NodeRange
  441. For Each sh In shs
  442. Set nr = sh.Curve.Selection
  443. For Each n In nr
  444. Set s = ActiveLayer.CreateEllipse2(n.PositionX, n.PositionY, 0.5, 0.5)
  445. sr.Add s
  446. Next n
  447. Next sh
  448. CutLines.RemoveDuplicates sr '// 简单删除重复算法
  449. Set sr = X4_Sort_ShapeRange(sr, stlx)
  450. For i = 1 To sr.count - 1
  451. x1 = sr(i + 1).CenterX
  452. y1 = sr(i + 1).CenterY
  453. x2 = sr(i).CenterX
  454. y2 = sr(i).CenterY
  455. Set pts = CreateSnapPoint(x1, y1)
  456. Set pte = CreateSnapPoint(x2, y2)
  457. #If VBA7 Then
  458. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  459. #Else
  460. ' X4 There is a difference
  461. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, (x1 + x2) / 2, (y1 + y2) / 2, cdrDimensionStyleEngineering, Textsize:=18)
  462. #End If
  463. Dimension_SetProperty sh, PresetProperty.value
  464. Next i
  465. sr.Delete
  466. ErrorHandler:
  467. API.EndOpt
  468. End Function
  469. '// 尺寸标注设置属性
  470. Private Function Dimension_SetProperty(sh_dim As Shape, Optional ByVal Preset As Boolean = False, Optional ByVal mirror As Boolean = False)
  471. #If VBA7 Then
  472. plt = 0: If periphery.value And mirror Then plt = 1
  473. If Preset And sh_dim.Type = cdrLinearDimensionShape Then
  474. With sh_dim.Style.GetProperty("dimension")
  475. .SetProperty "precision", 0 ' 小数位数
  476. .SetProperty "showUnits", 0 ' 是否显示单位 0/1
  477. .SetProperty "textPlacement", plt ' 0、上方,1、下方,2、中间
  478. ' .SetProperty "dynamicText", 0 ' 是否可以编辑尺寸0/1
  479. ' .SetProperty "overhang", 500000 '
  480. End With
  481. End If
  482. sh_dim.Outline.width = API.GetSet("Outline_Width")
  483. sh_dim.Dimension.TextShape.text.Story.size = Font_Size.value
  484. #Else
  485. ' X4 There is a difference
  486. #End If
  487. End Function
  488. '// 尺寸标注左边
  489. Private Sub Makesize_Left_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  490. SRMInst 3, "sw"
  491. If Button = 2 Then
  492. CutLines.Dimension_MarkLines cdrAlignLeft, False
  493. make_sizes_sep "lfbx", Button, False
  494. ElseIf Shift = fmCtrlMask Then
  495. CutLines.Dimension_MarkLines cdrAlignLeft, False
  496. make_sizes_sep "lfbx", Shift, False
  497. Else
  498. '// Ctrl Key
  499. make_sizes_sep "lfb"
  500. End If
  501. SRMInst 3, "lw"
  502. End Sub
  503. '// 尺寸标注右边
  504. Private Sub Makesize_Right_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  505. SRMInst 3, "sw"
  506. If Button = 2 Then
  507. CutLines.Dimension_MarkLines cdrAlignLeft, True
  508. make_sizes_sep "lfbx", Button, True
  509. ElseIf Shift = fmCtrlMask Then
  510. CutLines.Dimension_MarkLines cdrAlignLeft, True
  511. make_sizes_sep "lfbx", Shift, True
  512. Else
  513. '// Ctrl Key
  514. make_sizes_sep "rib"
  515. End If
  516. SRMInst 3, "lw"
  517. End Sub
  518. '// 尺寸标注向上
  519. Private Sub Makesize_Up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  520. SRMInst 3, "sw"
  521. If Button = 2 Then
  522. CutLines.Dimension_MarkLines cdrAlignTop, False
  523. make_sizes_sep "upbx", Button, False
  524. ElseIf Shift = fmCtrlMask Then
  525. CutLines.Dimension_MarkLines cdrAlignTop, False
  526. make_sizes_sep "upbx", Shift, False
  527. Else
  528. '// Ctrl Key
  529. make_sizes_sep "upb"
  530. End If
  531. SRMInst 3, "lw"
  532. End Sub
  533. '// 尺寸标注向下
  534. Private Sub Makesize_Down_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  535. SRMInst 3, "sw"
  536. If Button = 2 Then
  537. CutLines.Dimension_MarkLines cdrAlignTop, True
  538. make_sizes_sep "upbx", Button, True
  539. ElseIf Shift = fmCtrlMask Then
  540. CutLines.Dimension_MarkLines cdrAlignTop, True
  541. make_sizes_sep "upbx", Shift, True
  542. Else
  543. '// Ctrl Key
  544. make_sizes_sep "dnb"
  545. End If
  546. SRMInst 3, "lw"
  547. End Sub
  548. Private Sub MakeRuler_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  549. On Error GoTo ErrorHandler
  550. API.BeginOpt
  551. Set sreg = Nothing
  552. If Button = 2 And Shift = 0 Then '// 鼠标右键 标注右边
  553. Ruler_Align cdrAlignRight
  554. ElseIf Button = 2 And Shift = 2 Then '// Ctrl+鼠标右键 标注左边
  555. Ruler_Align cdrAlignLeft
  556. ElseIf Shift = 0 Then '// 鼠标左键,标注在上边
  557. Ruler_Align cdrAlignTop
  558. ElseIf Shift = 2 Then '// Ctrl+鼠标左键,标注下边
  559. Ruler_Align cdrAlignBottom
  560. End If
  561. sreg.CreateSelection
  562. ErrorHandler:
  563. API.EndOpt
  564. End Sub
  565. Private Sub MakeRuler_Align_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  566. On Error GoTo ErrorHandler
  567. API.BeginOpt
  568. Set sreg = Nothing
  569. Dim ra As cdrAlignType
  570. ra = cdrAlignTop
  571. ' 定义方向上下左右
  572. Dim pos_x As Variant, pos_y As Variant
  573. pos_x = Array(27, 27, 12, 44)
  574. pos_y = Array(12, 44, 27, 27)
  575. If Abs(X - pos_x(0)) < 14 And Abs(Y - pos_y(0)) < 14 Then
  576. ra = cdrAlignTop
  577. ElseIf Abs(X - pos_x(1)) < 14 And Abs(Y - pos_y(1)) < 14 Then
  578. ra = cdrAlignBottom
  579. ElseIf Abs(X - pos_x(2)) < 14 And Abs(Y - pos_y(2)) < 14 Then
  580. ra = cdrAlignLeft
  581. ElseIf Abs(X - pos_x(3)) < 14 And Abs(Y - pos_y(3)) < 14 Then
  582. ra = cdrAlignRight
  583. End If
  584. Ruler_Align ra
  585. sreg.CreateSelection
  586. ErrorHandler:
  587. API.EndOpt
  588. End Sub
  589. Private Function Ruler_Align(ra As cdrAlignType)
  590. If ra = cdrAlignRight Then '// 标注右边
  591. CutLines.Dimension_MarkLines cdrAlignLeft, True
  592. Add_Ruler_Text_Y True
  593. ElseIf ra = cdrAlignLeft Then '// 标注左边
  594. CutLines.Dimension_MarkLines cdrAlignLeft, False
  595. Add_Ruler_Text_Y True
  596. ElseIf ra = cdrAlignTop Then '// 标注上边
  597. CutLines.Dimension_MarkLines cdrAlignTop, False
  598. Add_Ruler_Text True
  599. ElseIf ra = cdrAlignBottom Then '// 标注下边
  600. CutLines.Dimension_MarkLines cdrAlignTop, True
  601. Add_Ruler_Text True
  602. End If
  603. End Function
  604. '// 标尺线转换成距离数字
  605. Private Function Add_Ruler_Text(rm_lines As Boolean)
  606. On Error GoTo ErrorHandler
  607. API.BeginOpt
  608. Dim s As Shape, t As Shape, sr As ShapeRange
  609. Dim text As String
  610. Set sr = ActiveSelectionRange
  611. Set sr = X4_Sort_ShapeRange(sr, stlx)
  612. For Each s In sr
  613. X = s.CenterX: Y = s.CenterY
  614. text = str(Int(X - sr.FirstShape.CenterX + 0.5))
  615. Set t = ActiveLayer.CreateArtisticText(X, Y, text, size:=Font_Size.value)
  616. t.CenterX = X: t.CenterY = Y
  617. sreg.Add t
  618. Next
  619. If rm_lines Then sr.Delete
  620. ErrorHandler:
  621. API.EndOpt
  622. End Function
  623. '// 标尺线转换成距离数字
  624. Private Function Add_Ruler_Text_Y(rm_lines As Boolean)
  625. On Error GoTo ErrorHandler
  626. API.BeginOpt
  627. Dim s As Shape, t As Shape, sr As ShapeRange
  628. Dim text As String
  629. Set sr = ActiveSelectionRange
  630. Set sr = X4_Sort_ShapeRange(sr, stty)
  631. For Each s In sr
  632. X = s.CenterX: Y = s.CenterY
  633. text = str(Int(Y - sr.FirstShape.CenterY + 0.5))
  634. Set t = ActiveLayer.CreateArtisticText(X, Y, text, size:=Font_Size.value)
  635. t.Rotate 90
  636. t.CenterX = X: t.CenterY = Y
  637. sreg.Add t
  638. Next
  639. If rm_lines Then sr.Delete
  640. ErrorHandler:
  641. API.EndOpt
  642. End Function
  643. Private Sub X_EXIT_Click()
  644. Me.width = 200: Me.Height = 105
  645. Unload Me '// EXIT
  646. End Sub
  647. Private Sub I18N_LNG_Click()
  648. LNG_CODE = API.GetLngCode
  649. If LNG_CODE = 1033 Then
  650. LNG_CODE = 2052
  651. Else
  652. LNG_CODE = 1033
  653. End If
  654. SaveSetting "LYVBA", "Settings", "I18N_LNG", LNG_CODE
  655. LNG_CODE = API.GetLngCode
  656. MsgBox i18n("Chinese And English Language Switching Is Completed, Please Restart The Plug-In.", LNG_CODE), vbOKOnly, i18n("Lanya Corelvba Plug-In", LNG_CODE)
  657. End Sub
  658. Private Sub Bt_SplitSegment_Click()
  659. ModulePlus.SplitSegment
  660. End Sub
  661. Private Sub btn_square_hi_Click()
  662. ModulePlus.square_hw "Height"
  663. End Sub
  664. Private Sub btn_square_wi_Click()
  665. ModulePlus.square_hw "Width"
  666. End Sub
  667. '// 节点连接合并
  668. Private Sub btn_join_nodes_Click()
  669. ActiveSelection.CustomCommand "ConvertTo", "JoinCurves"
  670. Application.Refresh
  671. End Sub
  672. '// 节点优化减少
  673. Private Sub btn_nodes_reduce_Click()
  674. ModulePlus.Nodes_Reduce
  675. End Sub
  676. '// 选择标注线 选择文字 删除或者解绑标准线
  677. Private Sub SelectText_Click()
  678. ModulePlus.Dimension_Select_or_Delete 4
  679. End Sub
  680. Private Sub SelectLine_Click()
  681. ModulePlus.Dimension_Select_or_Delete 1
  682. End Sub
  683. Private Sub Delete_Dimension_Click()
  684. ModulePlus.Dimension_Select_or_Delete 2
  685. End Sub
  686. Private Sub bt_Untie_MarkLines_Click()
  687. ModulePlus.Untie_MarkLines
  688. End Sub
  689. '// Select_Range 工具组合按钮
  690. Private Sub MADD_Click()
  691. SRMInst 1, "add"
  692. End Sub
  693. Private Sub MSUB_Click()
  694. SRMInst 1, "sub"
  695. End Sub
  696. Private Sub MRLW_Click()
  697. SRMInst 1, "lw"
  698. End Sub
  699. Private Sub MZERO_Click()
  700. SRMInst 1, "zero"
  701. MsgBox "Selection Range is Removed!"
  702. End Sub
  703. '''//// CorelDRAW 与 Adobe_Illustrator 剪贴板转换 ////'''
  704. Private Sub Adobe_Illustrator_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  705. Dim value As Integer
  706. If Button = 2 Then
  707. savePDFtoClip.AICopyToCdr
  708. Exit Sub
  709. End If
  710. If Button Then
  711. savePDFtoClip.CdrCopyToAI
  712. MsgBox "CorelDRAW 与 Adobe_Illustrator 剪贴板转换" & vbNewLine & "鼠标左键复制,鼠标右键粘贴"
  713. End If
  714. End Sub
  715. '// 修复圆角缺角到直角
  716. Private Sub btn_corners_off_Click()
  717. Tools.corner_off
  718. End Sub