Woodman.bas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Woodman
  3. Caption = "批量标注尺寸节点"
  4. ClientHeight = 1980
  5. ClientLeft = 45
  6. ClientTop = 330
  7. ClientWidth = 3960
  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. Private Sub btn_square_hi_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  17. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  18. Set os = ActiveSelectionRange
  19. Set ss = os.Shapes
  20. uc = 0
  21. For Each s In ss
  22. s.SizeWidth = s.SizeHeight
  23. uc = uc + 1
  24. Next s
  25. Application.Optimization = False
  26. ActiveWindow.Refresh: Application.Refresh
  27. End Sub
  28. Private Sub btn_square_wi_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  29. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  30. Set os = ActiveSelectionRange
  31. Set ss = os.Shapes
  32. uc = 0
  33. For Each s In ss
  34. s.SizeHeight = s.SizeWidth
  35. uc = uc + 1
  36. Next s
  37. Application.Optimization = False
  38. ActiveWindow.Refresh: Application.Refresh
  39. End Sub
  40. Private Sub btn_makesizes_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  41. Dim os As ShapeRange
  42. Dim s As Shape
  43. Dim sr As ShapeRange
  44. Set doc = ActiveDocument
  45. 'rasm.Dimension.TextShape.Text.Story.size = CLng(fnt)
  46. 'rasm.Style.GetProperty("dimension").SetProperty "precision", 0
  47. 'rasm.Style.GetProperty("dimension").SetProperty "units", 3
  48. doc.BeginCommandGroup "delete sizes"
  49. Set sr = ActiveSelectionRange
  50. sr.RemoveAll
  51. If Shift = 4 Then
  52. On Error Resume Next
  53. Set os = ActiveSelectionRange
  54. For Each s In os.Shapes
  55. If s.Type = cdrLinearDimensionShape Then s.Delete
  56. Next s
  57. On Error GoTo 0
  58. ElseIf Shift = 1 Then
  59. Set os = ActiveSelectionRange
  60. For Each s In os.Shapes
  61. If s.Type = cdrLinearDimensionShape Then sr.Add s
  62. Next s
  63. sr.CreateSelection
  64. On Error GoTo 0
  65. ElseIf Shift = 2 Then
  66. On Error Resume Next
  67. Set os = ActiveSelectionRange
  68. For Each s In os.Shapes
  69. If s.Type = cdrLinearDimensionShape Then s.Delete
  70. Next s
  71. On Error GoTo 0
  72. Else
  73. make_sizes Shift
  74. End If
  75. doc.EndCommandGroup
  76. Application.Refresh
  77. End Sub
  78. Private Sub btn_sizes_up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  79. make_sizes_sep "up", Shift
  80. End Sub
  81. Private Sub btn_sizes_dn_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  82. make_sizes_sep "dn", Shift
  83. End Sub
  84. Private Sub btn_sizes_lf_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  85. make_sizes_sep "lf", Shift
  86. End Sub
  87. Private Sub btn_sizes_ri_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  88. make_sizes_sep "ri", Shift
  89. End Sub
  90. Private Sub btn_sizes_btw_up_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  91. make_sizes_sep "upb", Shift
  92. End Sub
  93. Private Sub btn_sizes_btw_dn_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  94. make_sizes_sep "dnb", Shift
  95. End Sub
  96. Private Sub btn_sizes_btw_lf_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  97. make_sizes_sep "lfb", Shift
  98. End Sub
  99. Private Sub btn_sizes_btw_ri_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  100. make_sizes_sep "rib", Shift
  101. End Sub
  102. Sub make_sizes_sep(dr, Optional shft = 0)
  103. Set doc = ActiveDocument
  104. Dim s As Shape
  105. Dim pts As New SnapPoint, pte As New SnapPoint
  106. Dim os As ShapeRange
  107. un = doc.Unit
  108. doc.Unit = cdrMillimeter
  109. doc.BeginCommandGroup "make sizes"
  110. Set os = ActiveSelectionRange
  111. Dim border As Variant
  112. Dim Line_len As Double
  113. Line_len = API.GetSet("Line_len")
  114. border = Array(cdrBottomRight, cdrBottomLeft, os.TopY + 10, os.TopY + 20 + Line_len, _
  115. cdrBottomRight, cdrTopRight, os.LeftX - 10, os.LeftX - 20 - Line_len)
  116. If chkOpposite.value Then border = Array(cdrTopRight, cdrTopLeft, os.BottomY - 10, os.BottomY - 20 - Line_len, _
  117. cdrBottomLeft, cdrTopLeft, os.RightX + 10, os.RightX + 20 + Line_len)
  118. If dr = "upbx" Or dr = "upb" Or dr = "dnb" Or dr = "up" Or dr = "dn" Then os.Sort "@shape1.left < @shape2.left"
  119. If dr = "lfbx" Or dr = "lfb" Or dr = "rib" Or dr = "lf" Or dr = "ri" Then os.Sort "@shape1.top > @shape2.top"
  120. If os.Count > 0 Then
  121. If os.Count > 1 And Len(dr) > 2 Then
  122. For i = 1 To os.Shapes.Count - 1
  123. Select Case dr
  124. Case "upbx":
  125. Set pts = os.Shapes(i).SnapPoints.BBox(border(0))
  126. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(1))
  127. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, 0, border(2), cdrDimensionStyleEngineering
  128. If shft > 0 And i = 1 Then
  129. Set pts = os.FirstShape.SnapPoints.BBox(border(0))
  130. Set pte = os.LastShape.SnapPoints.BBox(border(1))
  131. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, 0, border(3), cdrDimensionStyleEngineering
  132. End If
  133. Case "lfbx":
  134. Set pts = os.Shapes(i).SnapPoints.BBox(border(4))
  135. Set pte = os.Shapes(i + 1).SnapPoints.BBox(border(5))
  136. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, border(6), 0, cdrDimensionStyleEngineering
  137. If shft > 0 And i = 1 Then
  138. Set pts = os.FirstShape.SnapPoints.BBox(border(4))
  139. Set pte = os.LastShape.SnapPoints.BBox(border(5))
  140. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, border(7), 0, cdrDimensionStyleEngineering
  141. End If
  142. Case "upb":
  143. Set pts = os.Shapes(i).SnapPoints.BBox(cdrTopRight)
  144. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  145. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.TopY + os.SizeHeight / 10, cdrDimensionStyleEngineering
  146. Case "dnb":
  147. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  148. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrBottomLeft)
  149. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering
  150. Case "lfb":
  151. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomLeft)
  152. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopLeft)
  153. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering
  154. Case "rib":
  155. Set pts = os.Shapes(i).SnapPoints.BBox(cdrBottomRight)
  156. Set pte = os.Shapes(i + 1).SnapPoints.BBox(cdrTopRight)
  157. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering
  158. End Select
  159. 'ActiveDocument.ClearSelection
  160. Next i
  161. Else
  162. If shft > 0 Then
  163. Select Case dr
  164. Case "up":
  165. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  166. Set pte = os.LastShape.SnapPoints.BBox(cdrTopRight)
  167. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.TopY + os.SizeHeight / 10, cdrDimensionStyleEngineering
  168. Case "dn":
  169. Set pts = os.FirstShape.SnapPoints.BBox(cdrBottomLeft)
  170. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  171. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, os.LeftX + os.SizeWidth / 10, os.BottomY - os.SizeHeight / 10, cdrDimensionStyleEngineering
  172. Case "lf":
  173. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopLeft)
  174. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomLeft)
  175. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, os.LeftX - os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering
  176. Case "ri":
  177. Set pts = os.FirstShape.SnapPoints.BBox(cdrTopRight)
  178. Set pte = os.LastShape.SnapPoints.BBox(cdrBottomRight)
  179. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, os.RightX + os.SizeWidth / 10, os.BottomY + os.SizeHeight / 10, cdrDimensionStyleEngineering
  180. End Select
  181. Else
  182. For Each s In os.Shapes
  183. Select Case dr
  184. Case "up":
  185. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  186. Set pte = s.SnapPoints.BBox(cdrTopRight)
  187. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering
  188. Case "dn":
  189. Set pts = s.SnapPoints.BBox(cdrBottomLeft)
  190. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  191. ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.BottomY - s.SizeHeight / 10, cdrDimensionStyleEngineering
  192. Case "lf":
  193. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  194. Set pte = s.SnapPoints.BBox(cdrBottomLeft)
  195. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering
  196. Case "ri":
  197. Set pts = s.SnapPoints.BBox(cdrTopRight)
  198. Set pte = s.SnapPoints.BBox(cdrBottomRight)
  199. ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, pte, True, s.RightX + s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering
  200. End Select
  201. Next s
  202. End If
  203. End If
  204. End If
  205. os.CreateSelection
  206. doc.EndCommandGroup
  207. doc.Unit = un
  208. End Sub
  209. Sub make_sizes(Optional shft = 0)
  210. Set doc = ActiveDocument
  211. Dim s As Shape
  212. Dim pts As SnapPoint, pte As SnapPoint
  213. Dim os As ShapeRange
  214. un = doc.Unit
  215. doc.Unit = cdrMillimeter
  216. doc.BeginCommandGroup "make sizes"
  217. Set os = ActiveSelectionRange
  218. If os.Count > 0 Then
  219. For Each s In os.Shapes
  220. Set pts = s.SnapPoints.BBox(cdrTopLeft)
  221. Set pte = s.SnapPoints.BBox(cdrTopRight)
  222. Set ptle = s.SnapPoints.BBox(cdrBottomLeft)
  223. If shft <> 6 Then ActiveLayer.CreateLinearDimension cdrDimensionVertical, pts, ptle, True, s.LeftX - s.SizeWidth / 10, s.BottomY + s.SizeHeight / 10, cdrDimensionStyleEngineering
  224. If shft <> 3 Then ActiveLayer.CreateLinearDimension cdrDimensionHorizontal, pts, pte, True, s.LeftX + s.SizeWidth / 10, s.TopY + s.SizeHeight / 10, cdrDimensionStyleEngineering
  225. Next s
  226. End If
  227. doc.EndCommandGroup
  228. doc.Unit = un
  229. End Sub
  230. Public Function make_selection(Optional mode = "fcolor", Optional sel = True, Optional OSS As ShapeRange = Nothing, Optional colr = Nothing) As ShapeRange
  231. Dim s As Shape, lst As Shape
  232. Dim sr As ShapeRange
  233. 'Dim os As ShapeRange
  234. Set doc = ActiveDocument
  235. doc.Unit = cdrTenthMicron
  236. If OSS Is Nothing Then
  237. If toolspanel.num_list.value Or mode = "locked" Then
  238. Set os = ActivePage
  239. Else
  240. Set os = ActiveSelectionRange
  241. End If
  242. Else
  243. Set os = OSS
  244. End If
  245. Set sr = ActiveSelectionRange
  246. sr.RemoveAll
  247. If sel Then ActiveDocument.ClearSelection
  248. Set lst = os.Shapes.First
  249. For Each s In os.Shapes
  250. Select Case mode
  251. Case "ocolor": If s.Outline.Type <> cdrNoOutline And s.Shapes.Count = 0 And s.Outline.Color.HexValue = colr.HexValue Then sr.Add s
  252. Case "fcolor": If s.Fill.Type <> cdrNoFill And s.Shapes.Count = 0 And s.Fill.UniformColor.HexValue = colr.HexValue Then sr.Add s
  253. Case "nofil": If s.Fill.Type = cdrNoFill And s.Shapes.Count = 0 Then sr.Add s
  254. Case "fil": If s.Fill.Type <> cdrNoFill And s.Shapes.Count = 0 Then sr.Add s
  255. Case "abr": If s.Outline.Type <> cdrNoOutline And s.Shapes.Count = 0 Then sr.Add s
  256. Case "noabr": If s.Outline.Type = cdrNoOutline And s.Shapes.Count = 0 Then sr.Add s
  257. Case "open": If Not s.DisplayCurve Is Nothing Then If Not s.DisplayCurve.Closed Then sr.Add s
  258. Case "closed": If Not s.DisplayCurve Is Nothing Then If s.DisplayCurve.Closed Then sr.Add s
  259. Case "single": If s.Shapes.Count = 0 Then sr.Add s
  260. Case "dashed": If s.Outline.Style.DashCount > 0 Then sr.Add s
  261. Case "groups": If s.Shapes.Count > 0 And s.Effect Is Nothing Then sr.Add s
  262. Case "text": If s.Shapes.Count = 0 And s.Type = cdrTextShape Then sr.Add s
  263. Case "notext": If s.Shapes.Count = 0 And s.Type <> cdrTextShape Then sr.Add s
  264. Case "images": If s.Type = cdrBitmapShape Then sr.Add s
  265. Case "locked": If s.Locked Then sr.Add s
  266. Case "effects": If s.Effects.Count > 0 Or Not s.Effect Is Nothing Then sr.Add s
  267. Case "noeffects": If s.Effects.Count = 0 And s.Effect Is Nothing Then sr.Add s
  268. Case "bigger":
  269. arelst = lst.SizeHeight * lst.SizeWidth
  270. ares = s.SizeHeight * s.SizeWidth
  271. If ares >= arelst Then
  272. are = one_shape_area(lst)
  273. If one_shape_area(s) >= are Then sr.Add s
  274. End If
  275. Case "smaller":
  276. arelst = lst.SizeHeight * lst.SizeWidth
  277. ares = s.SizeHeight * s.SizeWidth
  278. If ares <= arelst Then
  279. are = one_shape_area(lst)
  280. If one_shape_area(s) <= are Then sr.Add s
  281. End If
  282. Case "last":
  283. If lst.Fill.Type = cdrNoFill Then
  284. 's.CreateSelection
  285. If s.Outline.Type <> cdrNoOutline Then If s.Outline.Color.HexValue = lst.Outline.Color.HexValue Then sr.Add s
  286. Else
  287. If s.Fill.UniformColor.HexValue = lst.Fill.UniformColor.HexValue Then sr.Add s
  288. End If
  289. End Select
  290. Next s
  291. If sr.Shapes.Count > 0 And sel Then sr.CreateSelection
  292. Set make_selection = sr
  293. Application.Refresh
  294. ActiveWindow.Activate
  295. End Function
  296. Public Function get_events(btn As String, Optional shft = 0, Optional click = 1)
  297. out = "ok"
  298. get_events = out
  299. End Function
  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. Private Sub MarkLines_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  326. If Button = 2 Then
  327. CutLines.Dimension_MarkLines cdrAlignLeft, chkOpposite.value
  328. make_sizes_sep "lfbx", Shift
  329. Else
  330. CutLines.Dimension_MarkLines cdrAlignTop, chkOpposite.value
  331. Label_Makesizes.Caption = "试试右键"
  332. make_sizes_sep "upbx", Shift
  333. End If
  334. End Sub
  335. Private Sub chkOpposite_Click()
  336. ' Debug.Print chkOpposite.value
  337. End Sub
  338. Private Sub manual_makesize_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  339. If Button = 2 Then
  340. '// 右键
  341. ElseIf Shift = fmCtrlMask Then
  342. Slanted_Makesize '// 手动标注倾斜尺寸
  343. Else
  344. Untie_MarkLines '// 解绑尺寸,分离尺寸
  345. End If
  346. End Sub
  347. '// 解绑尺寸,分离尺寸
  348. Private Function Untie_MarkLines()
  349. Dim os As ShapeRange, dss As New ShapeRange
  350. Set os = ActiveSelectionRange
  351. For Each s In os.Shapes
  352. If s.Type = cdrLinearDimensionShape Then
  353. dss.Add s
  354. End If
  355. Next s
  356. If dss.Count > 0 Then
  357. dss.BreakApartEx
  358. os.Shapes.FindShapes(Query:="@name ='DMKLine'").CreateSelection
  359. ActiveSelectionRange.Delete
  360. End If
  361. End Function
  362. '// 手动标注倾斜尺寸
  363. Private Function Slanted_Makesize()
  364. On Error GoTo ErrorHandler
  365. ActiveDocument.Unit = cdrMillimeter
  366. Dim nr As NodeRange, cnt As Integer
  367. Dim x1 As Double, y1 As Double
  368. Dim x2 As Double, y2 As Double
  369. Set nr = ActiveShape.Curve.Selection
  370. If nr.Count < 2 Then Exit Function
  371. cnt = nr.Count
  372. While cnt > 1
  373. x1 = nr(cnt).PositionX
  374. y1 = nr(cnt).PositionY
  375. x2 = nr(cnt - 1).PositionX
  376. y2 = nr(cnt - 1).PositionY
  377. Set pts = CreateSnapPoint(x1, y1)
  378. Set pte = CreateSnapPoint(x2, y2)
  379. ActiveLayer.CreateLinearDimension cdrDimensionSlanted, pts, pte, True, x1 - 5, y1 + 5, cdrDimensionStyleEngineering
  380. cnt = cnt - 1
  381. Wend
  382. ErrorHandler:
  383. End Function