Tools.bas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Attribute VB_Name = "Tools"
  2. Public Sub 填入居中文字(str)
  3. Dim s As Shape
  4. Set s = ActiveSelection
  5. X = s.CenterX
  6. Y = s.CenterY
  7. Set s = ActiveLayer.CreateArtisticText(0, 0, str)
  8. s.CenterX = X
  9. s.CenterY = Y
  10. End Sub
  11. Public Sub 尺寸标注()
  12. ActiveDocument.Unit = cdrMillimeter
  13. Set s = ActiveSelection
  14. X = s.CenterX: Y = s.TopY
  15. sw = s.SizeWidth: sh = s.SizeHeight
  16. Text = Int(sw) & "x" & Int(sh) & "mm"
  17. Set s = ActiveLayer.CreateArtisticText(0, 0, Text)
  18. s.CenterX = X: s.BottomY = Y + 5
  19. End Sub
  20. Public Sub 批量居中文字(str)
  21. Dim s As Shape, sr As ShapeRange
  22. Set sr = ActiveSelectionRange
  23. For Each s In sr.Shapes
  24. X = s.CenterX: Y = s.CenterY
  25. Set s = ActiveLayer.CreateArtisticText(0, 0, str)
  26. s.CenterX = X: s.CenterY = Y
  27. Next
  28. End Sub
  29. Public Sub 批量标注()
  30. ActiveDocument.Unit = cdrMillimeter
  31. Set sr = ActiveSelectionRange
  32. For Each s In sr.Shapes
  33. X = s.CenterX: Y = s.TopY
  34. sw = s.SizeWidth: sh = s.SizeHeight
  35. Text = Int(sw + 0.5) & "x" & Int(sh + 0.5) & "mm"
  36. Set s = ActiveLayer.CreateArtisticText(0, 0, Text)
  37. s.CenterX = X: s.BottomY = Y + 5
  38. Next
  39. End Sub
  40. Public Sub 智能群组()
  41. Set s1 = ActiveSelectionRange.CustomCommand("Boundary", "CreateBoundary")
  42. Set brk1 = s1.BreakApartEx
  43. For Each s In brk1
  44. Set sh = ActivePage.SelectShapesFromRectangle(s.LeftX, s.TopY, s.RightX, s.BottomY, True)
  45. sh.Shapes.All.Group
  46. s.Delete
  47. Next
  48. End Sub
  49. Private Function 对角线角度(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double
  50. pi = 4 * VBA.Atn(1) ' 计算圆周率'
  51. 对角线角度 = VBA.Atn((y2 - y1) / (x2 - x1)) / pi * 180
  52. End Function
  53. Public Sub 角度转平()
  54. ActiveDocument.ReferencePoint = cdrCenter
  55. Dim sr As ShapeRange '定义物件范围
  56. Set sr = ActiveSelectionRange
  57. Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
  58. Dim Shift As Long
  59. Dim b As Boolean
  60. b = ActiveDocument.GetUserArea(x1, y1, x2, y2, Shift, 10, False, 306)
  61. If Not b Then
  62. a = 对角线角度(x1, y1, x2, y2)
  63. sr.Rotate -a
  64. End If
  65. End Sub