Woodman.bas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Woodman
  3. Caption = "Batch Dimension Nodes"
  4. ClientHeight = 2220
  5. ClientLeft = 45
  6. ClientTop = 330
  7. ClientWidth = 3945
  8. OleObjectBlob = "Woodman.frx":0000
  9. StartUpPosition = 1 '所有者中心
  10. End
  11. Attribute VB_Name = "Woodman"
  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", Woodman.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 Control '// CorelDRAW 2020 需要注释,才不会错误
  47. For Each ctl In Woodman.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 btn_square_hi_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  74. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  75. Set os = ActiveSelectionRange
  76. Set ss = os.Shapes
  77. uc = 0
  78. For Each s In ss
  79. s.SizeWidth = s.SizeHeight
  80. uc = uc + 1
  81. Next s
  82. Application.Optimization = False
  83. ActiveWindow.Refresh: Application.Refresh
  84. End Sub
  85. Private Sub btn_square_wi_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  86. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  87. Set os = ActiveSelectionRange
  88. Set ss = os.Shapes
  89. uc = 0
  90. For Each s In ss
  91. s.SizeHeight = s.SizeWidth
  92. uc = uc + 1
  93. Next s
  94. Application.Optimization = False
  95. ActiveWindow.Refresh: Application.Refresh
  96. End Sub
  97. Private Sub btn_Makesizes_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  98. Dim os As ShapeRange
  99. Dim s As Shape
  100. Dim sr As ShapeRange
  101. Set doc = ActiveDocument
  102. 'rasm.Dimension.TextShape.Text.Story.size = CLng(fnt)
  103. 'rasm.Style.GetProperty("dimension").SetProperty "precision", 0
  104. 'rasm.Style.GetProperty("dimension").SetProperty "units", 3
  105. doc.BeginCommandGroup "delete sizes"
  106. Set sr = ActiveSelectionRange
  107. sr.RemoveAll
  108. If Shift = 4 Then
  109. On Error Resume Next
  110. Set os = ActiveSelectionRange
  111. For Each s In os.Shapes
  112. If s.Type = cdrLinearDimensionShape Then s.Delete
  113. Next s
  114. On Error GoTo 0
  115. ElseIf Shift = 1 Then
  116. Set os = ActiveSelectionRange
  117. For Each s In os.Shapes
  118. If s.Type = cdrLinearDimensionShape Then sr.Add s
  119. Next s
  120. sr.CreateSelection
  121. On Error GoTo 0
  122. ElseIf Shift = 2 Then
  123. On Error Resume Next
  124. Set os = ActiveSelectionRange
  125. For Each s In os.Shapes
  126. If s.Type = cdrLinearDimensionShape Then s.Delete
  127. Next s
  128. If os.Count > 0 Then
  129. os.Shapes.FindShapes(Query:="@name ='DMKLine'").CreateSelection
  130. ActiveSelectionRange.Delete
  131. End If
  132. On Error GoTo 0
  133. Else
  134. make_sizes Shift
  135. End If
  136. doc.EndCommandGroup
  137. Application.Refresh
  138. End Sub
  139. Private Sub btn_sizes_up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  140. make_sizes_sep "up", Shift
  141. End Sub
  142. Private Sub btn_sizes_dn_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  143. make_sizes_sep "dn", Shift
  144. End Sub
  145. Private Sub btn_sizes_lf_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  146. make_sizes_sep "lf", Shift
  147. End Sub
  148. Private Sub btn_sizes_ri_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  149. make_sizes_sep "ri", Shift
  150. End Sub
  151. Private Sub btn_sizes_btw_up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  152. make_sizes_sep "upb", Shift
  153. End Sub
  154. Private Sub btn_sizes_btw_dn_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  155. make_sizes_sep "dnb", Shift
  156. End Sub
  157. Private Sub btn_sizes_btw_lf_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  158. make_sizes_sep "lfb", Shift
  159. End Sub
  160. Private Sub btn_sizes_btw_ri_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  161. make_sizes_sep "rib", Shift
  162. End Sub
  163. Sub make_sizes_sep(dr, Optional shft = 0, Optional ByVal mirror As Boolean = False)
  164. On Error GoTo ErrorHandler
  165. API.BeginOpt "Make Size"
  166. Set doc = ActiveDocument
  167. Dim s As Shape, sh As Shape
  168. Dim pts As New SnapPoint, pte As New SnapPoint
  169. Dim os As ShapeRange
  170. Set os = ActiveSelectionRange
  171. Dim border As Variant
  172. Dim Line_len As Double
  173. If shft > 1 Then
  174. Line_len = API.Set_Space_Width '// 设置文字空间间隙
  175. Else
  176. Line_len = API.Set_Space_Width(True) '// 只读文字空间间隙
  177. End If
  178. border = Array(cdrBottomRight, cdrBottomLeft, os.TopY + Line_len, os.TopY + 2 * Line_len, _
  179. cdrBottomRight, cdrTopRight, os.LeftX - Line_len, os.LeftX - 2 * Line_len)
  180. If mirror = True Then border = Array(cdrTopRight, cdrTopLeft, os.BottomY - Line_len, os.BottomY - 2 * Line_len, _
  181. cdrBottomLeft, cdrTopLeft, os.RightX + Line_len, os.RightX + 2 * Line_len)
  182. If dr = "upbx" Or dr = "upb" Or dr = "dnb" Or dr = "up" Or dr = "dn" Then os.Sort "@shape1.left < @shape2.left"
  183. If dr = "lfbx" Or dr = "lfb" Or dr = "rib" Or dr = "lf" Or dr = "ri" Then os.Sort "@shape1.top > @shape2.top"
  184. If os.Count > 0 Then
  185. If os.Count > 1 And Len(dr) > 2 And os.Shapes.Count > 1 Then
  186. For i = 1 To os.Shapes.Count - 1
  187. Select Case dr
  188. Case "upbx":
  189. Set pts = os.Shapes(i).SnapPoints.BBox(border(0))
  190. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(1))
  191. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(2), cdrDimensionStyleEngineering)
  192. If shft > 0 And i = 1 Then
  193. Dimension_SetProperty sh, PresetProperty.value
  194. Set pts = os.FirstShape.SnapPoints.BBox(border(0))
  195. Set pte = os.LastShape.SnapPoints.BBox(border(1))
  196. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, 0, border(3), cdrDimensionStyleEngineering)
  197. End If
  198. Case "lfbx":
  199. Set pts = os.Shapes(i).SnapPoints.BBox(border(4))
  200. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(5))
  201. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(6), 0, cdrDimensionStyleEngineering)
  202. If shft > 0 And i = 1 Then
  203. Dimension_SetProperty sh, PresetProperty.value
  204. Set pts = os.FirstShape.SnapPoints.BBox(border(4))
  205. Set pte = os.LastShape.SnapPoints.BBox(border(5))
  206. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, border(7), 0, cdrDimensionStyleEngineering)
  207. End If
  208. Case "upb":
  209. Set pts = os.Shapes(i).SnapPoints.BBox(cdrTopRight)
  210. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  211. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.TopY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  212. Case "dnb":
  213. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  214. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrBottomLeft)
  215. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering)
  216. Case "lfb":
  217. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomLeft)
  218. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  219. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  220. Case "rib":
  221. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  222. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopRight)
  223. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  224. End Select
  225. '// 尺寸标注设置属性
  226. Dimension_SetProperty sh, PresetProperty.value
  227. 'ActiveDocument.ClearSelection
  228. Next i
  229. Else
  230. If shft > 0 Then
  231. Select Case dr
  232. Case "up":
  233. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  234. Set pte = os.LastShape.SnapPoints.BBox(cdrTopRight)
  235. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.TopY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  236. Case "dn":
  237. Set pts = os.FirstShape.SnapPoints.BBox(cdrBottomLeft)
  238. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  239. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering)
  240. Case "lf":
  241. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  242. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomLeft)
  243. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  244. Case "ri":
  245. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopRight)
  246. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  247. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering)
  248. End Select
  249. Dimension_SetProperty sh, PresetProperty.value
  250. Else
  251. For Each s In os.Shapes
  252. Select Case dr
  253. Case "up":
  254. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  255. Set pte = s.SnapPoints.BBox(cdrTopRight)
  256. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  257. Case "dn":
  258. Set pts = s.SnapPoints.BBox(cdrBottomLeft)
  259. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  260. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.BottomY - s.SizeHeight / 10, cdrDimensionStyleEngineering)
  261. Case "lf":
  262. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  263. Set pte = s.SnapPoints.BBox(cdrBottomLeft)
  264. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  265. Case "ri":
  266. Set pts = s.SnapPoints.BBox(cdrTopRight)
  267. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  268. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, pte, True, s.RightX + s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering)
  269. End Select
  270. Dimension_SetProperty sh, PresetProperty.value
  271. Next s
  272. End If
  273. End If
  274. End If
  275. os.CreateSelection
  276. ErrorHandler:
  277. API.EndOpt
  278. End Sub
  279. Sub make_sizes(Optional shft = 0)
  280. On Error GoTo ErrorHandler
  281. API.BeginOpt
  282. Dim s As Shape
  283. Dim pts As SnapPoint, pte As SnapPoint
  284. Dim os As ShapeRange
  285. Set os = ActiveSelectionRange
  286. If os.Count > 0 Then
  287. For Each s In os.Shapes
  288. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  289. Set pte = s.SnapPoints.BBox(cdrTopRight)
  290. Set ptle = s.SnapPoints.BBox(cdrBottomLeft)
  291. If shft <> 6 Then Dimension_SetProperty ActiveLayer.CreateLinearDimension(cdrDimensionVertical, pts, ptle, True, _
  292. s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering), PresetProperty.value
  293. If shft <> 3 Then Dimension_SetProperty ActiveLayer.CreateLinearDimension(cdrDimensionHorizontal, pts, pte, True, _
  294. s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering), PresetProperty.value
  295. Next s
  296. End If
  297. ErrorHandler:
  298. API.EndOpt
  299. End Sub
  300. Private Sub btn_join_nodes_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  301. ActiveSelection.CustomCommand "ConvertTo", "JoinCurves"
  302. Application.Refresh
  303. End Sub
  304. Private Sub btn_nodes_reduce_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  305. On Error GoTo ErrorHandler
  306. Set doc = ActiveDocument
  307. Dim s As Shape
  308. ps = Array(1)
  309. doc.Unit = cdrTenthMicron
  310. Set os = ActivePage.Shapes
  311. If os.Count > 0 Then
  312. doc.BeginCommandGroup "reduce nodes"
  313. For Each s In os
  314. s.ConvertToCurves
  315. If Not s.DisplayCurve Is Nothing Then
  316. s.Curve.AutoReduceNodes 50
  317. End If
  318. Next s
  319. doc.EndCommandGroup
  320. End If
  321. Application.Refresh
  322. ErrorHandler:
  323. MsgBox "s.Curve.AutoReduceNodes 只有高版本才支持本API"
  324. End Sub
  325. '// 使用标记线批量建立尺寸标注: 左键上标注,右键右标注
  326. Private Sub MarkLines_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  327. Dim sr As ShapeRange
  328. Set sr = ActiveSelectionRange
  329. '// 右键
  330. If Button = 2 Then
  331. If chkOpposite.value = True Then
  332. CutLines.Dimension_MarkLines cdrAlignTop, True
  333. make_sizes_sep "upbx", Shift, True
  334. Else
  335. CutLines.Dimension_MarkLines cdrAlignLeft, True
  336. make_sizes_sep "lfbx", Shift, True
  337. End If
  338. '// 左键
  339. ElseIf Button = 1 Then
  340. If chkOpposite.value = True Then
  341. CutLines.Dimension_MarkLines cdrAlignLeft, False
  342. make_sizes_sep "lfbx", Shift, False
  343. Else
  344. CutLines.Dimension_MarkLines cdrAlignTop, False
  345. make_sizes_sep "upbx", Shift, False
  346. End If
  347. End If
  348. sr.CreateSelection
  349. End Sub
  350. '// 使用手工选节点建立尺寸标注,使用Ctrl分离尺寸标注
  351. Private Sub Manual_Makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
  352. If Button = 2 Then
  353. '// 右键
  354. ElseIf Shift = fmCtrlMask Then
  355. Slanted_Makesize '// 手动标注倾斜尺寸
  356. Else
  357. Untie_MarkLines '// 解绑尺寸,分离尺寸
  358. End If
  359. End Sub
  360. '// 解绑尺寸,分离尺寸
  361. Private Function Untie_MarkLines()
  362. Dim os As ShapeRange, dss As New ShapeRange
  363. Set os = ActiveSelectionRange
  364. For Each s In os.Shapes
  365. If s.Type = cdrLinearDimensionShape Then
  366. dss.Add s
  367. End If
  368. Next s
  369. If dss.Count > 0 Then
  370. dss.BreakApartEx
  371. os.Shapes.FindShapes(Query:="@name ='DMKLine'").CreateSelection
  372. ActiveSelectionRange.Delete
  373. End If
  374. End Function
  375. '// 手动标注倾斜尺寸
  376. Private Function Slanted_Makesize()
  377. On Error GoTo ErrorHandler
  378. API.BeginOpt
  379. Dim nr As NodeRange, cnt As Integer
  380. Dim sr As ShapeRange, sh As Shape
  381. Dim x1 As Double, y1 As Double
  382. Dim x2 As Double, y2 As Double
  383. Set sr = ActiveSelectionRange
  384. Set nr = ActiveShape.Curve.Selection
  385. If chkOpposite.value = False Then
  386. Slanted_Sort_Make sr '// 排序标注倾斜尺寸
  387. Exit Function
  388. End If
  389. If nr.Count < 2 Then Exit Function
  390. cnt = nr.Count
  391. While cnt > 1
  392. x1 = nr(cnt).PositionX
  393. y1 = nr(cnt).PositionY
  394. x2 = nr(cnt - 1).PositionX
  395. y2 = nr(cnt - 1).PositionY
  396. Set pts = CreateSnapPoint(x1, y1)
  397. Set pte = CreateSnapPoint(x2, y2)
  398. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  399. Dimension_SetProperty sh, PresetProperty.value
  400. cnt = cnt - 1
  401. Wend
  402. ErrorHandler:
  403. API.EndOpt
  404. End Function
  405. '// 排序标注倾斜尺寸
  406. Private Function Slanted_Sort_Make(shs As ShapeRange)
  407. On Error GoTo ErrorHandler
  408. Dim sr As New ShapeRange
  409. Dim s As Shape, sh As Shape
  410. Dim nr As NodeRange
  411. For Each sh In shs
  412. Set nr = sh.Curve.Selection
  413. For Each n In nr
  414. Set s = ActiveLayer.CreateEllipse2(n.PositionX, n.PositionY, 0.5, 0.5)
  415. sr.Add s
  416. Next n
  417. Next sh
  418. CutLines.RemoveDuplicates sr '// 简单删除重复算法
  419. sr.Sort "@shape1.left < @shape2.left"
  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. Set sh = ActiveLayer.CreateLinearDimension(cdrDimensionSlanted, pts, pte, True, x1 - 20, y1 + 20, cdrDimensionStyleEngineering)
  428. Dimension_SetProperty sh, PresetProperty.value
  429. Next i
  430. sr.Delete
  431. ErrorHandler:
  432. API.EndOpt
  433. End Function
  434. '// 尺寸标注设置属性
  435. Private Function Dimension_SetProperty(sh_dim As Shape, Optional ByVal Preset As Boolean = False)
  436. If Preset And sh_dim.Type = cdrLinearDimensionShape Then
  437. With sh_dim.Style.GetProperty("dimension")
  438. .SetProperty "precision", 0 ' 小数位数
  439. .SetProperty "showUnits", 0 ' 是否显示单位 0/1
  440. .SetProperty "textPlacement", 0 ' 0、上方,1、下方,2、中间
  441. ' .SetProperty "dynamicText", 0 ' 是否可以编辑尺寸0/1
  442. ' .SetProperty "overhang", 500000 '
  443. End With
  444. End If
  445. End Function
  446. Private Sub X_EXIT_Click()
  447. Unload Me '// EXIT
  448. End Sub