MakeSizePlus.bas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} MakeSizePlus
  3. Caption = "Batch Dimension Nodes"
  4. ClientHeight = 1680
  5. ClientLeft = 45
  6. ClientTop = 330
  7. ClientWidth = 3900
  8. OleObjectBlob = "MakeSizePlus.frx":0000
  9. StartUpPosition = 1 '所有者中心
  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. '// Minimizes the window and retains dimensioning functionality '// 最小化窗口并保留标注尺寸功能
  36. Private Function MiniForm()
  37. Dim IStyle As Long
  38. Dim hwnd As Long
  39. hwnd = FindWindow("ThunderDFrame", MakeSizePlus.Caption)
  40. IStyle = GetWindowLong(hwnd, GWL_STYLE)
  41. IStyle = IStyle And Not WS_CAPTION
  42. SetWindowLong hwnd, GWL_STYLE, IStyle
  43. DrawMenuBar hwnd
  44. IStyle = GetWindowLong(hwnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME
  45. SetWindowLong hwnd, GWL_EXSTYLE, IStyle
  46. Dim ctl As Variant '// CorelDRAW 2020 定义成 Variant 才不会错误
  47. For Each ctl In MakeSizePlus.Controls
  48. ctl.Visible = False
  49. ctl.Top = 2
  50. Next ctl
  51. With Me
  52. .StartUpPosition = 0
  53. .BackColor = &H80000012
  54. .Left = Val(GetSetting("LYVBA", "Settings", "Left", "400")) + 318
  55. .Top = Val(GetSetting("LYVBA", "Settings", "Top", "55")) - 2
  56. .Height = 28
  57. .width = 98
  58. .MarkLines_Makesize.Visible = True
  59. .btn_Makesizes.Visible = True
  60. .Manual_Makesize.Visible = True
  61. .chkOpposite.Visible = True
  62. .X_EXIT.Visible = True
  63. .MarkLines_Makesize.Left = 1
  64. .btn_Makesizes.Left = 26
  65. .Manual_Makesize.Left = 50
  66. .chkOpposite.Left = 75: .chkOpposite.Top = 14
  67. .X_EXIT.Left = 85: .X_EXIT.Top = 0
  68. End With
  69. End Function
  70. Private Sub btn_MiniForm_Click()
  71. MiniForm
  72. End Sub
  73. Private Sub UserForm_Initialize()
  74. LNG_CODE = Val(GetSetting("LYVBA", "Settings", "I18N_LNG", "1033"))
  75. Init_Translations Me, LNG_CODE
  76. Me.Caption = i18n("Batch Dimension Nodes", LNG_CODE)
  77. End Sub
  78. Private Sub btn_square_hi_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  79. API.BeginOpt
  80. Set os = ActiveSelectionRange
  81. Set ss = os.Shapes
  82. For Each s In ss
  83. s.SizeWidth = s.SizeHeight
  84. Next s
  85. API.EndOpt
  86. End Sub
  87. Private Sub btn_square_wi_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  88. API.BeginOpt
  89. Set os = ActiveSelectionRange
  90. Set ss = os.Shapes
  91. For Each s In ss
  92. s.SizeHeight = s.SizeWidth
  93. Next s
  94. API.EndOpt
  95. End Sub
  96. Private Sub btn_Makesizes_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  97. On Error GoTo ErrorHandler
  98. API.BeginOpt
  99. Dim os As ShapeRange
  100. Dim s As Shape
  101. Dim sr As ShapeRange
  102. Set doc = ActiveDocument
  103. Set sr = ActiveSelectionRange
  104. sr.RemoveAll
  105. If Shift = 4 Then
  106. Set os = ActiveSelectionRange
  107. For Each s In os.Shapes
  108. If s.Type = cdrTextShape Then sr.Add s
  109. Next s
  110. sr.CreateSelection
  111. ElseIf Shift = 1 Then
  112. Set os = ActiveSelectionRange
  113. For Each s In os.Shapes
  114. If s.Type = cdrLinearDimensionShape Then sr.Add s
  115. Next s
  116. sr.CreateSelection
  117. ElseIf Shift = 2 Then
  118. Set os = ActiveSelectionRange
  119. For Each s In os.Shapes
  120. If s.Type = cdrLinearDimensionShape Then sr.Add s
  121. Next s
  122. sr.Delete
  123. If os.Count > 0 Then
  124. os.Shapes.FindShapes(Query:="@name ='DMKLine'").CreateSelection
  125. ActiveSelectionRange.Delete
  126. End If
  127. Else
  128. make_sizes Shift
  129. End If
  130. ErrorHandler:
  131. API.EndOpt
  132. End Sub
  133. Sub make_sizes_sep(dr, Optional shft = 0, Optional ByVal mirror As Boolean = False)
  134. On Error GoTo ErrorHandler
  135. API.BeginOpt "Make Size"
  136. Set doc = ActiveDocument
  137. Dim s As Shape, sh As Shape
  138. Dim pts As New SnapPoint, pte As New SnapPoint
  139. Dim os As ShapeRange
  140. Set os = ActiveSelectionRange
  141. Dim border As Variant
  142. Dim Line_len As Double
  143. If shft > 1 Then
  144. Line_len = API.Set_Space_Width '// 设置文字空间间隙
  145. Else
  146. Line_len = API.Set_Space_Width(True) '// 只读文字空间间隙
  147. End If
  148. border = Array(cdrBottomRight, cdrBottomLeft, os.TopY + Line_len, os.TopY + 2 * Line_len, _
  149. cdrBottomRight, cdrTopRight, os.LeftX - Line_len, os.LeftX - 2 * Line_len)
  150. If mirror = True Then border = Array(cdrTopRight, cdrTopLeft, os.BottomY - Line_len, os.BottomY - 2 * Line_len, _
  151. cdrBottomLeft, cdrTopLeft, os.RightX + Line_len, os.RightX + 2 * Line_len)
  152. #If VBA7 Then
  153. If dr = "upbx" Or dr = "upb" Or dr = "dnb" Or dr = "up" Or dr = "dn" Then os.Sort "@shape1.left < @shape2.left"
  154. If dr = "lfbx" Or dr = "lfb" Or dr = "rib" Or dr = "lf" Or dr = "ri" Then os.Sort "@shape1.top > @shape2.top"
  155. #Else
  156. If dr = "upbx" Or dr = "upb" Or dr = "dnb" Or dr = "up" Or dr = "dn" Then Set os = X4_Sort_ShapeRange(os, stlx)
  157. If dr = "lfbx" Or dr = "lfb" Or dr = "rib" Or dr = "lf" Or dr = "ri" Then Set os = X4_Sort_ShapeRange(os, stty).ReverseRange
  158. #End If
  159. If os.Count > 0 Then
  160. If os.Count > 1 And Len(dr) > 2 And os.Shapes.Count > 1 Then
  161. For i = 1 To os.Shapes.Count - 1
  162. Select Case dr
  163. Case "upbx"
  164. #If VBA7 Then
  165. Set pts = os.Shapes(i).SnapPoints.BBox(border(0))
  166. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(1))
  167. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(2), cdrDimensionStyleEngineering)
  168. If shft > 0 And i = 1 Then
  169. Dimension_SetProperty sh, PresetProperty.value
  170. Set pts = os.FirstShape.SnapPoints.BBox(border(0))
  171. Set pte = os.LastShape.SnapPoints.BBox(border(1))
  172. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(3), cdrDimensionStyleEngineering)
  173. End If
  174. Case "lfbx"
  175. Set pts = os.Shapes(i).SnapPoints.BBox(border(4))
  176. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(5))
  177. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(6), 0, cdrDimensionStyleEngineering)
  178. If shft > 0 And i = 1 Then
  179. Dimension_SetProperty sh, PresetProperty.value
  180. Set pts = os.FirstShape.SnapPoints.BBox(border(4))
  181. Set pte = os.LastShape.SnapPoints.BBox(border(5))
  182. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(7), 0, cdrDimensionStyleEngineering)
  183. End If
  184. #Else
  185. ' X4 There is a difference
  186. Set pts = CreateSnapPoint(os.Shapes(i).CenterX, os.Shapes(i).CenterY)
  187. Set pte = CreateSnapPoint(os.Shapes(i + 1).CenterX, os.Shapes(i + 1).CenterY)
  188. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(2), Textsize:=18)
  189. Case "lfbx"
  190. Set pts = CreateSnapPoint(os.Shapes(i).CenterX, os.Shapes(i).CenterY)
  191. Set pte = CreateSnapPoint(os.Shapes(i + 1).CenterX, os.Shapes(i + 1).CenterY)
  192. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(6), 0, Textsize:=18)
  193. #End If
  194. Case "upb"
  195. Set pts = os.Shapes(i).SnapPoints.BBox(cdrTopRight)
  196. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  197. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.TopY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  198. Case "dnb"
  199. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  200. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrBottomLeft)
  201. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering)
  202. Case "lfb"
  203. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomLeft)
  204. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  205. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  206. Case "rib"
  207. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  208. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopRight)
  209. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  210. End Select
  211. '// 尺寸标注设置属性
  212. Dimension_SetProperty sh, PresetProperty.value
  213. 'ActiveDocument.ClearSelection
  214. Next i
  215. Else
  216. If shft > 0 Then
  217. Select Case dr
  218. Case "up"
  219. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  220. Set pte = os.LastShape.SnapPoints.BBox(cdrTopRight)
  221. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.TopY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  222. Case "dn"
  223. Set pts = os.FirstShape.SnapPoints.BBox(cdrBottomLeft)
  224. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  225. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering)
  226. Case "lf"
  227. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  228. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomLeft)
  229. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  230. Case "ri"
  231. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopRight)
  232. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  233. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  234. End Select
  235. Dimension_SetProperty sh, PresetProperty.value
  236. Else
  237. For Each s In os.Shapes
  238. Select Case dr
  239. Case "up"
  240. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  241. Set pte = s.SnapPoints.BBox(cdrTopRight)
  242. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  243. Case "dn"
  244. Set pts = s.SnapPoints.BBox(cdrBottomLeft)
  245. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  246. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.BottomY - s.SizeHeight / 10, cdrDimensionStyleEngineering)
  247. Case "lf"
  248. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  249. Set pte = s.SnapPoints.BBox(cdrBottomLeft)
  250. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  251. Case "ri"
  252. Set pts = s.SnapPoints.BBox(cdrTopRight)
  253. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  254. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, s.RightX + s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  255. End Select
  256. Dimension_SetProperty sh, PresetProperty.value
  257. Next s
  258. End If
  259. End If
  260. End If
  261. os.CreateSelection
  262. ErrorHandler:
  263. API.EndOpt
  264. End Sub
  265. Sub make_sizes(Optional shft = 0)
  266. On Error GoTo ErrorHandler
  267. API.BeginOpt
  268. Dim s As Shape
  269. Dim pts As SnapPoint, pte As SnapPoint
  270. Dim os As ShapeRange
  271. Set os = ActiveSelectionRange
  272. If os.Count > 0 Then
  273. For Each s In os.Shapes
  274. #If VBA7 Then
  275. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  276. Set pte = s.SnapPoints.BBox(cdrTopRight)
  277. Set ptle = s.SnapPoints.BBox(cdrBottomLeft)
  278. If shft <> 6 Then Dimension_SetProperty ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, ptle, True, _
  279. s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering), PresetProperty.value
  280. If shft <> 3 Then Dimension_SetProperty ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, _
  281. s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering), PresetProperty.value
  282. #Else
  283. ' X4 There is a difference
  284. Set pts = s.SnapPoints(cdrTopLeft)
  285. Set pte = s.SnapPoints(cdrTopRight)
  286. Set ptle = s.SnapPoints(cdrBottomLeft)
  287. If shft <> 6 Then ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, ptle, True, _
  288. s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering, Textsize:=18
  289. If shft <> 3 Then ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, _
  290. s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering, Textsize:=18
  291. #End If
  292. Next s
  293. End If
  294. ErrorHandler:
  295. API.EndOpt
  296. End Sub
  297. '// 节点连接合并
  298. Private Sub btn_join_nodes_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  299. ActiveSelection.CustomCommand "ConvertTo", "JoinCurves"
  300. Application.Refresh
  301. End Sub
  302. '// 节点优化减少
  303. Private Sub btn_nodes_reduce_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  304. On Error GoTo ErrorHandler: API.BeginOpt
  305. Set doc = ActiveDocument
  306. Dim s As Shape
  307. ps = Array(1)
  308. doc.Unit = cdrTenthMicron
  309. Set os = ActivePage.Shapes
  310. If os.Count > 0 Then
  311. For Each s In os
  312. s.ConvertToCurves
  313. If Not s.DisplayCurve Is Nothing Then
  314. s.Curve.AutoReduceNodes 50
  315. End If
  316. Next s
  317. End If
  318. ErrorHandler:
  319. API.EndOpt
  320. End Sub
  321. '// 使用标记线批量建立尺寸标注: 左键上标注,右键右标注
  322. Private Sub MarkLines_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  323. Dim sr As ShapeRange
  324. Set sr = ActiveSelectionRange
  325. '// 右键
  326. If Button = 2 Then
  327. If chkOpposite.value = True Then
  328. CutLines.Dimension_MarkLines cdrAlignTop, True
  329. make_sizes_sep "upbx", Shift, True
  330. Else
  331. CutLines.Dimension_MarkLines cdrAlignLeft, True
  332. make_sizes_sep "lfbx", Shift, True
  333. End If
  334. '// 左键
  335. ElseIf Button = 1 Then
  336. If chkOpposite.value = True Then
  337. CutLines.Dimension_MarkLines cdrAlignLeft, False
  338. make_sizes_sep "lfbx", Shift, False
  339. Else
  340. CutLines.Dimension_MarkLines cdrAlignTop, False
  341. make_sizes_sep "upbx", Shift, False
  342. End If
  343. End If
  344. sr.CreateSelection
  345. End Sub
  346. '// 使用手工选节点建立尺寸标注,使用Ctrl分离尺寸标注
  347. Private Sub Manual_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  348. If Button = 2 Then
  349. '// 右键
  350. ElseIf Shift = fmCtrlMask Then
  351. Slanted_Makesize '// 手动标注倾斜尺寸
  352. Else
  353. Untie_MarkLines '// 解绑尺寸,分离尺寸
  354. End If
  355. End Sub
  356. '// 解绑尺寸,分离尺寸
  357. Private Function Untie_MarkLines()
  358. Dim os As ShapeRange, dss As New ShapeRange
  359. Set os = ActiveSelectionRange
  360. For Each s In os.Shapes
  361. If s.Type = cdrLinearDimensionShape Then
  362. dss.Add s
  363. End If
  364. Next s
  365. If dss.Count > 0 Then
  366. dss.BreakApartEx
  367. os.Shapes.FindShapes(Query:="@name ='DMKLine'").CreateSelection
  368. ActiveSelectionRange.Delete
  369. End If
  370. End Function
  371. '// 手动标注倾斜尺寸
  372. Private Function Slanted_Makesize()
  373. On Error GoTo ErrorHandler
  374. API.BeginOpt
  375. Dim nr As NodeRange, cnt As Integer
  376. Dim sr As ShapeRange, sh As Shape
  377. Dim x1 As Double, y1 As Double
  378. Dim x2 As Double, y2 As Double
  379. Set sr = ActiveSelectionRange
  380. Set nr = ActiveShape.Curve.Selection
  381. If chkOpposite.value = False Then
  382. Slanted_Sort_Make sr '// 排序标注倾斜尺寸
  383. Exit Function
  384. End If
  385. If nr.Count < 2 Then Exit Function
  386. cnt = nr.Count
  387. While cnt > 1
  388. x1 = nr(cnt).PositionX
  389. y1 = nr(cnt).PositionY
  390. x2 = nr(cnt - 1).PositionX
  391. y2 = nr(cnt - 1).PositionY
  392. Set pts = CreateSnapPoint(x1, y1)
  393. Set pte = CreateSnapPoint(x2, y2)
  394. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  395. Dimension_SetProperty sh, PresetProperty.value
  396. cnt = cnt - 1
  397. Wend
  398. ErrorHandler:
  399. API.EndOpt
  400. End Function
  401. '// 排序标注倾斜尺寸
  402. Private Function Slanted_Sort_Make(shs As ShapeRange)
  403. On Error GoTo ErrorHandler
  404. Dim sr As New ShapeRange
  405. Dim s As Shape, sh As Shape
  406. Dim nr As NodeRange
  407. For Each sh In shs
  408. Set nr = sh.Curve.Selection
  409. For Each n In nr
  410. Set s = ActiveLayer.CreateEllipse2(n.PositionX, n.PositionY, 0.5, 0.5)
  411. sr.Add s
  412. Next n
  413. Next sh
  414. CutLines.RemoveDuplicates sr '// 简单删除重复算法
  415. #If VBA7 Then
  416. sr.Sort "@shape1.left < @shape2.left"
  417. #Else
  418. Set sr = X4_Sort_ShapeRange(sr, stlx)
  419. #End If
  420. For i = 1 To sr.Count - 1
  421. x1 = sr(i + 1).CenterX
  422. y1 = sr(i + 1).CenterY
  423. x2 = sr(i).CenterX
  424. y2 = sr(i).CenterY
  425. Set pts = CreateSnapPoint(x1, y1)
  426. Set pte = CreateSnapPoint(x2, y2)
  427. #If VBA7 Then
  428. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  429. #Else
  430. ' X4 There is a difference
  431. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, (x1 + x2) / 2, (y1 + y2) / 2, cdrDimensionStyleEngineering, Textsize:=18)
  432. #End If
  433. Dimension_SetProperty sh, PresetProperty.value
  434. Next i
  435. sr.Delete
  436. ErrorHandler:
  437. API.EndOpt
  438. End Function
  439. '// 尺寸标注设置属性
  440. Private Function Dimension_SetProperty(sh_dim As Shape, Optional ByVal Preset As Boolean = False)
  441. #If VBA7 Then
  442. If Preset And sh_dim.Type = cdrLinearDimensionShape Then
  443. With sh_dim.Style.GetProperty("dimension")
  444. .SetProperty "precision", 0 ' 小数位数
  445. .SetProperty "showUnits", 0 ' 是否显示单位 0/1
  446. .SetProperty "textPlacement", 0 ' 0、上方,1、下方,2、中间
  447. ' .SetProperty "dynamicText", 0 ' 是否可以编辑尺寸0/1
  448. ' .SetProperty "overhang", 500000 '
  449. End With
  450. End If
  451. #Else
  452. ' X4 There is a difference
  453. #End If
  454. End Function
  455. '// 尺寸标注左边
  456. Private Sub Makesize_Left_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  457. If Button = 2 Then
  458. CutLines.Dimension_MarkLines cdrAlignLeft, False
  459. make_sizes_sep "lfbx", Button, False
  460. ElseIf Shift = fmCtrlMask Then
  461. CutLines.Dimension_MarkLines cdrAlignLeft, False
  462. make_sizes_sep "lfbx", Shift, False
  463. Else
  464. '// Ctrl Key
  465. make_sizes_sep "lfb"
  466. End If
  467. End Sub
  468. '// 尺寸标注右边
  469. Private Sub Makesize_Right_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  470. If Button = 2 Then
  471. CutLines.Dimension_MarkLines cdrAlignLeft, True
  472. make_sizes_sep "lfbx", Button, True
  473. ElseIf Shift = fmCtrlMask Then
  474. CutLines.Dimension_MarkLines cdrAlignLeft, True
  475. make_sizes_sep "lfbx", Shift, True
  476. Else
  477. '// Ctrl Key
  478. make_sizes_sep "rib"
  479. End If
  480. End Sub
  481. '// 尺寸标注向上
  482. Private Sub Makesize_Up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  483. If Button = 2 Then
  484. CutLines.Dimension_MarkLines cdrAlignTop, False
  485. make_sizes_sep "upbx", Button, False
  486. ElseIf Shift = fmCtrlMask Then
  487. CutLines.Dimension_MarkLines cdrAlignTop, False
  488. make_sizes_sep "upbx", Shift, False
  489. Else
  490. '// Ctrl Key
  491. make_sizes_sep "upb"
  492. End If
  493. End Sub
  494. '// 尺寸标注向下
  495. Private Sub Makesize_Down_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  496. If Button = 2 Then
  497. CutLines.Dimension_MarkLines cdrAlignTop, True
  498. make_sizes_sep "upbx", Button, True
  499. ElseIf Shift = fmCtrlMask Then
  500. CutLines.Dimension_MarkLines cdrAlignTop, True
  501. make_sizes_sep "upbx", Shift, True
  502. Else
  503. '// Ctrl Key
  504. make_sizes_sep "dnb"
  505. End If
  506. End Sub
  507. Private Sub MakeRuler_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  508. If Button = 2 Then
  509. CutLines.Dimension_MarkLines cdrAlignLeft, False
  510. Add_Ruler_Text_Y True
  511. Else
  512. '// 建立标尺线
  513. CutLines.Dimension_MarkLines cdrAlignTop, False
  514. '// 标尺线转换成距离数字
  515. Add_Ruler_Text True
  516. End If
  517. End Sub
  518. '// 标尺线转换成距离数字
  519. Private Function Add_Ruler_Text(rm_lines As Boolean)
  520. API.BeginOpt
  521. Dim s As Shape, t As Shape, sr As ShapeRange
  522. Dim text As String
  523. Set sr = ActiveSelectionRange
  524. sr.Sort "@shape1.left < @shape2.left"
  525. For Each s In sr
  526. x = s.CenterX: Y = s.CenterY
  527. text = str(Int(x - sr.FirstShape.CenterX + 0.5))
  528. Set t = ActiveLayer.CreateArtisticText(x, Y, text)
  529. t.CenterX = x: t.CenterY = Y
  530. Next
  531. If rm_lines Then sr.Delete
  532. API.EndOpt
  533. End Function
  534. '// 标尺线转换成距离数字
  535. Private Function Add_Ruler_Text_Y(rm_lines As Boolean)
  536. API.BeginOpt
  537. Dim s As Shape, t As Shape, sr As ShapeRange
  538. Dim text As String
  539. Set sr = ActiveSelectionRange
  540. sr.Sort "@shape1.top < @shape2.top"
  541. For Each s In sr
  542. x = s.CenterX: Y = s.CenterY
  543. text = str(Int(Y - sr.FirstShape.CenterY + 0.5))
  544. Set t = ActiveLayer.CreateArtisticText(x, Y, text)
  545. t.CenterX = x: t.CenterY = Y
  546. Next
  547. If rm_lines Then sr.Delete
  548. API.EndOpt
  549. End Function
  550. Private Sub X_EXIT_Click()
  551. Unload Me '// EXIT
  552. End Sub