1
1

MakeSizePlus.frm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} MakeSizePlus
  3. Caption = "Batch Dimension Plus"
  4. ClientHeight = 3690
  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 Frame1_Click()
  40. End Sub
  41. Private Sub UserForm_Initialize()
  42. With Me
  43. .StartUpPosition = 0
  44. .Left = Val(GetSetting(TOOLNAME, SECTION, "form_left", 900))
  45. .Top = Val(GetSetting(TOOLNAME, SECTION, "form_top", 200))
  46. .width = Val(GetSetting(TOOLNAME, SECTION, "form_width", 200))
  47. .Height = Val(GetSetting(TOOLNAME, SECTION, "form_Height", 105))
  48. End With
  49. LNG_CODE = Val(GetSetting("LYVBA", "Settings", "I18N_LNG", "1033"))
  50. Init_Translations Me, LNG_CODE
  51. Me.Caption = i18n("Batch Dimension Plus", LNG_CODE)
  52. ' 读取线设置
  53. Bleed.text = API.GetSet("Bleed")
  54. Line_len.text = API.GetSet("Line_len")
  55. Outline_Width.text = GetSetting("LYVBA", "Settings", "Outline_Width", "0.2")
  56. End Sub
  57. '// 关闭窗口时保存窗口位置
  58. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  59. saveFormPos True
  60. End Sub
  61. '// 保存窗口位置和加载窗口位置
  62. Sub saveFormPos(bDoSave As Boolean)
  63. If bDoSave Then 'save position
  64. SaveSetting TOOLNAME, SECTION, "form_left", Me.Left
  65. SaveSetting TOOLNAME, SECTION, "form_top", Me.Top
  66. SaveSetting TOOLNAME, SECTION, "form_width", Me.width
  67. SaveSetting TOOLNAME, SECTION, "form_Height", Me.Height
  68. End If
  69. End Sub
  70. Private Sub btn_ExpandForm_Click()
  71. With Me
  72. If .width = 200 Then
  73. .width = 260: .Height = 132
  74. ElseIf .Height = 132 Then
  75. .Height = 206
  76. Else
  77. .width = 200: .Height = 105
  78. End If
  79. End With
  80. End Sub
  81. '// Minimizes the window and retains dimensioning functionality '// 最小化窗口并保留标注尺寸功能
  82. Private Function MiniForm()
  83. Dim IStyle As Long
  84. Dim hwnd As Long
  85. hwnd = FindWindow("ThunderDFrame", MakeSizePlus.Caption)
  86. IStyle = GetWindowLong(hwnd, GWL_STYLE)
  87. IStyle = IStyle And Not WS_CAPTION
  88. SetWindowLong hwnd, GWL_STYLE, IStyle
  89. DrawMenuBar hwnd
  90. IStyle = GetWindowLong(hwnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME
  91. SetWindowLong hwnd, GWL_EXSTYLE, IStyle
  92. Dim ctl As Variant '// CorelDRAW 2020 定义成 Variant 才不会错误
  93. For Each ctl In MakeSizePlus.Controls
  94. ctl.Visible = False
  95. ctl.Top = 2
  96. Next ctl
  97. With Me
  98. .StartUpPosition = 0
  99. .BackColor = &H80000012
  100. .Left = Val(GetSetting("LYVBA", "Settings", "Left", "400")) + 318
  101. .Top = Val(GetSetting("LYVBA", "Settings", "Top", "55")) - 2
  102. .Height = 28
  103. .width = 98
  104. .MarkLines_Makesize.Visible = True
  105. .btn_Makesizes.Visible = True
  106. .Manual_Makesize.Visible = True
  107. .chkOpposite.Visible = True
  108. .X_EXIT.Visible = True
  109. .MarkLines_Makesize.Left = 1
  110. .btn_Makesizes.Left = 26
  111. .Manual_Makesize.Left = 50
  112. .chkOpposite.Left = 75: .chkOpposite.Top = 14
  113. .X_EXIT.Left = 85: .X_EXIT.Top = 0
  114. End With
  115. End Function
  116. Private Sub btn_MiniForm_Click()
  117. MiniForm
  118. End Sub
  119. Private Sub Settings_Click()
  120. If 0 < Val(Bleed.text) * Val(Line_len.text) < 100 Then
  121. SaveSetting "LYVBA", "Settings", "Bleed", Bleed.text
  122. SaveSetting "LYVBA", "Settings", "Line_len", Line_len.text
  123. SaveSetting "LYVBA", "Settings", "Outline_Width", Outline_Width.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
  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
  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
  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
  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
  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. Dim sr As ShapeRange
  322. Set sr = ActiveSelectionRange
  323. '// 右键
  324. If Button = 2 Then
  325. If chkOpposite.value = True Then
  326. CutLines.Dimension_MarkLines cdrAlignTop, True
  327. make_sizes_sep "upbx", Shift, True
  328. Else
  329. CutLines.Dimension_MarkLines cdrAlignLeft, True
  330. make_sizes_sep "lfbx", Shift, True
  331. End If
  332. '// 左键
  333. ElseIf Button = 1 Then
  334. If chkOpposite.value = True Then
  335. CutLines.Dimension_MarkLines cdrAlignLeft, False
  336. make_sizes_sep "lfbx", Shift, False
  337. Else
  338. CutLines.Dimension_MarkLines cdrAlignTop, False
  339. make_sizes_sep "upbx", Shift, False
  340. End If
  341. End If
  342. sr.CreateSelection
  343. End Sub
  344. '// 使用手工选节点建立尺寸标注,使用Ctrl分离尺寸标注
  345. Private Sub Manual_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  346. If Button = 2 Then
  347. '// 右键
  348. ElseIf Shift = fmCtrlMask Then
  349. Slanted_Makesize '// 手动标注倾斜尺寸
  350. Else
  351. ModulePlus.Untie_MarkLines '// 解绑尺寸,分离尺寸
  352. End If
  353. End Sub
  354. '// 手动标注倾斜尺寸
  355. Private Function Slanted_Makesize()
  356. On Error GoTo ErrorHandler
  357. API.BeginOpt
  358. Dim nr As NodeRange, cnt As Integer
  359. Dim sr As ShapeRange, sh As Shape
  360. Dim x1 As Double, y1 As Double
  361. Dim x2 As Double, y2 As Double
  362. Set sr = ActiveSelectionRange
  363. Set nr = ActiveShape.Curve.Selection
  364. If chkOpposite.value = False Then
  365. Slanted_Sort_Make sr '// 排序标注倾斜尺寸
  366. Exit Function
  367. End If
  368. If nr.Count < 2 Then Exit Function
  369. cnt = nr.Count
  370. While cnt > 1
  371. x1 = nr(cnt).PositionX
  372. y1 = nr(cnt).PositionY
  373. x2 = nr(cnt - 1).PositionX
  374. y2 = nr(cnt - 1).PositionY
  375. Set pts = CreateSnapPoint(x1, y1)
  376. Set pte = CreateSnapPoint(x2, y2)
  377. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  378. Dimension_SetProperty sh, PresetProperty.value
  379. cnt = cnt - 1
  380. Wend
  381. ErrorHandler:
  382. API.EndOpt
  383. End Function
  384. '// 排序标注倾斜尺寸
  385. Private Function Slanted_Sort_Make(shs As ShapeRange)
  386. On Error GoTo ErrorHandler
  387. Dim sr As New ShapeRange
  388. Dim s As Shape, sh As Shape
  389. Dim nr As NodeRange
  390. For Each sh In shs
  391. Set nr = sh.Curve.Selection
  392. For Each n In nr
  393. Set s = ActiveLayer.CreateEllipse2(n.PositionX, n.PositionY, 0.5, 0.5)
  394. sr.Add s
  395. Next n
  396. Next sh
  397. CutLines.RemoveDuplicates sr '// 简单删除重复算法
  398. Set sr = X4_Sort_ShapeRange(sr, stlx)
  399. For i = 1 To sr.Count - 1
  400. x1 = sr(i + 1).CenterX
  401. y1 = sr(i + 1).CenterY
  402. x2 = sr(i).CenterX
  403. y2 = sr(i).CenterY
  404. Set pts = CreateSnapPoint(x1, y1)
  405. Set pte = CreateSnapPoint(x2, y2)
  406. #If VBA7 Then
  407. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  408. #Else
  409. ' X4 There is a difference
  410. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, (x1 + x2) / 2, (y1 + y2) / 2, cdrDimensionStyleEngineering, Textsize:=18)
  411. #End If
  412. Dimension_SetProperty sh, PresetProperty.value
  413. Next i
  414. sr.Delete
  415. ErrorHandler:
  416. API.EndOpt
  417. End Function
  418. '// 尺寸标注设置属性
  419. Private Function Dimension_SetProperty(sh_dim As Shape, Optional ByVal Preset As Boolean = False)
  420. #If VBA7 Then
  421. If Preset And sh_dim.Type = cdrLinearDimensionShape Then
  422. With sh_dim.Style.GetProperty("dimension")
  423. .SetProperty "precision", 0 ' 小数位数
  424. .SetProperty "showUnits", 0 ' 是否显示单位 0/1
  425. .SetProperty "textPlacement", 0 ' 0、上方,1、下方,2、中间
  426. ' .SetProperty "dynamicText", 0 ' 是否可以编辑尺寸0/1
  427. ' .SetProperty "overhang", 500000 '
  428. End With
  429. End If
  430. sh_dim.Outline.width = API.GetSet("Outline_Width")
  431. #Else
  432. ' X4 There is a difference
  433. #End If
  434. End Function
  435. '// 尺寸标注左边
  436. Private Sub Makesize_Left_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  437. If Button = 2 Then
  438. CutLines.Dimension_MarkLines cdrAlignLeft, False
  439. make_sizes_sep "lfbx", Button, False
  440. ElseIf Shift = fmCtrlMask Then
  441. CutLines.Dimension_MarkLines cdrAlignLeft, False
  442. make_sizes_sep "lfbx", Shift, False
  443. Else
  444. '// Ctrl Key
  445. make_sizes_sep "lfb"
  446. End If
  447. End Sub
  448. '// 尺寸标注右边
  449. Private Sub Makesize_Right_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  450. If Button = 2 Then
  451. CutLines.Dimension_MarkLines cdrAlignLeft, True
  452. make_sizes_sep "lfbx", Button, True
  453. ElseIf Shift = fmCtrlMask Then
  454. CutLines.Dimension_MarkLines cdrAlignLeft, True
  455. make_sizes_sep "lfbx", Shift, True
  456. Else
  457. '// Ctrl Key
  458. make_sizes_sep "rib"
  459. End If
  460. End Sub
  461. '// 尺寸标注向上
  462. Private Sub Makesize_Up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  463. If Button = 2 Then
  464. CutLines.Dimension_MarkLines cdrAlignTop, False
  465. make_sizes_sep "upbx", Button, False
  466. ElseIf Shift = fmCtrlMask Then
  467. CutLines.Dimension_MarkLines cdrAlignTop, False
  468. make_sizes_sep "upbx", Shift, False
  469. Else
  470. '// Ctrl Key
  471. make_sizes_sep "upb"
  472. End If
  473. End Sub
  474. '// 尺寸标注向下
  475. Private Sub Makesize_Down_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  476. If Button = 2 Then
  477. CutLines.Dimension_MarkLines cdrAlignTop, True
  478. make_sizes_sep "upbx", Button, True
  479. ElseIf Shift = fmCtrlMask Then
  480. CutLines.Dimension_MarkLines cdrAlignTop, True
  481. make_sizes_sep "upbx", Shift, True
  482. Else
  483. '// Ctrl Key
  484. make_sizes_sep "dnb"
  485. End If
  486. End Sub
  487. Private Sub MakeRuler_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  488. On Error GoTo ErrorHandler
  489. API.BeginOpt
  490. Set sreg = Nothing
  491. If Button = 2 And Shift = 0 Then '// 鼠标右键 标注右边
  492. Ruler_Align cdrAlignRight
  493. ElseIf Button = 2 And Shift = 2 Then '// Ctrl+鼠标右键 标注左边
  494. Ruler_Align cdrAlignLeft
  495. ElseIf Shift = 0 Then '// 鼠标左键,标注在上边
  496. Ruler_Align cdrAlignTop
  497. ElseIf Shift = 2 Then '// Ctrl+鼠标左键,标注下边
  498. Ruler_Align cdrAlignBottom
  499. End If
  500. sreg.CreateSelection
  501. ErrorHandler:
  502. API.EndOpt
  503. End Sub
  504. Private Sub MakeRuler_Align_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  505. On Error GoTo ErrorHandler
  506. API.BeginOpt
  507. Set sreg = Nothing
  508. Dim ra As cdrAlignType
  509. ra = cdrAlignTop
  510. ' 定义方向上下左右
  511. Dim pos_x As Variant, pos_y As Variant
  512. pos_x = Array(27, 27, 12, 44)
  513. pos_y = Array(12, 44, 27, 27)
  514. If Abs(X - pos_x(0)) < 14 And Abs(Y - pos_y(0)) < 14 Then
  515. ra = cdrAlignTop
  516. ElseIf Abs(X - pos_x(1)) < 14 And Abs(Y - pos_y(1)) < 14 Then
  517. ra = cdrAlignBottom
  518. ElseIf Abs(X - pos_x(2)) < 14 And Abs(Y - pos_y(2)) < 14 Then
  519. ra = cdrAlignLeft
  520. ElseIf Abs(X - pos_x(3)) < 14 And Abs(Y - pos_y(3)) < 14 Then
  521. ra = cdrAlignRight
  522. End If
  523. Ruler_Align ra
  524. sreg.CreateSelection
  525. ErrorHandler:
  526. API.EndOpt
  527. End Sub
  528. Private Function Ruler_Align(ra As cdrAlignType)
  529. If ra = cdrAlignRight Then '// 标注右边
  530. CutLines.Dimension_MarkLines cdrAlignLeft, True
  531. Add_Ruler_Text_Y True
  532. ElseIf ra = cdrAlignLeft Then '// 标注左边
  533. CutLines.Dimension_MarkLines cdrAlignLeft, False
  534. Add_Ruler_Text_Y True
  535. ElseIf ra = cdrAlignTop Then '// 标注上边
  536. CutLines.Dimension_MarkLines cdrAlignTop, False
  537. Add_Ruler_Text True
  538. ElseIf ra = cdrAlignBottom Then '// 标注下边
  539. CutLines.Dimension_MarkLines cdrAlignTop, True
  540. Add_Ruler_Text True
  541. End If
  542. End Function
  543. '// 标尺线转换成距离数字
  544. Private Function Add_Ruler_Text(rm_lines As Boolean)
  545. On Error GoTo ErrorHandler
  546. API.BeginOpt
  547. Dim s As Shape, t As Shape, sr As ShapeRange
  548. Dim text As String
  549. Set sr = ActiveSelectionRange
  550. Set sr = X4_Sort_ShapeRange(sr, stlx)
  551. For Each s In sr
  552. X = s.CenterX: Y = s.CenterY
  553. text = str(Int(X - sr.FirstShape.CenterX + 0.5))
  554. Set t = ActiveLayer.CreateArtisticText(X, Y, text)
  555. t.CenterX = X: t.CenterY = Y
  556. sreg.Add t
  557. Next
  558. If rm_lines Then sr.Delete
  559. ErrorHandler:
  560. API.EndOpt
  561. End Function
  562. '// 标尺线转换成距离数字
  563. Private Function Add_Ruler_Text_Y(rm_lines As Boolean)
  564. On Error GoTo ErrorHandler
  565. API.BeginOpt
  566. Dim s As Shape, t As Shape, sr As ShapeRange
  567. Dim text As String
  568. Set sr = ActiveSelectionRange
  569. Set sr = X4_Sort_ShapeRange(sr, stty)
  570. For Each s In sr
  571. X = s.CenterX: Y = s.CenterY
  572. text = str(Int(Y - sr.FirstShape.CenterY + 0.5))
  573. Set t = ActiveLayer.CreateArtisticText(X, Y, text)
  574. t.Rotate 90
  575. t.CenterX = X: t.CenterY = Y
  576. sreg.Add t
  577. Next
  578. If rm_lines Then sr.Delete
  579. ErrorHandler:
  580. API.EndOpt
  581. End Function
  582. Private Sub X_EXIT_Click()
  583. Me.width = 200: Me.Height = 105
  584. Unload Me '// EXIT
  585. End Sub
  586. Private Sub I18N_LNG_Click()
  587. LNG_CODE = Val(GetSetting("LYVBA", "Settings", "I18N_LNG", "1033"))
  588. If LNG_CODE = 1033 Then
  589. LNG_CODE = 2052
  590. Else
  591. LNG_CODE = 1033
  592. End If
  593. SaveSetting "LYVBA", "Settings", "I18N_LNG", LNG_CODE
  594. MsgBox "中英文语言切换完成,请重启插件!", vbOKOnly, "兰雅VBA代码分享"
  595. End Sub
  596. Private Sub Bt_SplitSegment_Click()
  597. ModulePlus.SplitSegment
  598. End Sub
  599. Private Sub btn_square_hi_Click()
  600. ModulePlus.square_hw "Height"
  601. End Sub
  602. Private Sub btn_square_wi_Click()
  603. ModulePlus.square_hw "Width"
  604. End Sub
  605. '// 节点连接合并
  606. Private Sub btn_join_nodes_Click()
  607. ActiveSelection.CustomCommand "ConvertTo", "JoinCurves"
  608. Application.Refresh
  609. End Sub
  610. '// 节点优化减少
  611. Private Sub btn_nodes_reduce_Click()
  612. ModulePlus.Nodes_Reduce
  613. End Sub
  614. '// 选择标注线 选择文字 删除或者解绑标准线
  615. Private Sub SelectText_Click()
  616. ModulePlus.Dimension_Select_or_Delete 4
  617. End Sub
  618. Private Sub SelectLine_Click()
  619. ModulePlus.Dimension_Select_or_Delete 1
  620. End Sub
  621. Private Sub Delete_Dimension_Click()
  622. ModulePlus.Dimension_Select_or_Delete 2
  623. End Sub
  624. Private Sub bt_Untie_MarkLines_Click()
  625. ModulePlus.Untie_MarkLines
  626. End Sub