MakeSizePlus.frm 25 KB

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