API.bas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. Attribute VB_Name = "API"
  2. Public Function GetSet(s As String)
  3. Bleed = Val(GetSetting("262235.xyz", "Settings", "Bleed", "2.0"))
  4. Line_len = Val(GetSetting("262235.xyz", "Settings", "Line_len", "3.0"))
  5. Outline_Width = Val(GetSetting("262235.xyz", "Settings", "Outline_Width", "0.2"))
  6. ' Debug.Print Bleed, Line_len, Outline_Width
  7. If s = "Bleed" Then
  8. GetSet = Bleed
  9. ElseIf s = "Line_len" Then
  10. GetSet = Line_len
  11. ElseIf s = "Outline_Width" Then
  12. GetSet = Outline_Width
  13. End If
  14. End Function
  15. Public Function Create_Tolerance()
  16. Dim text As String
  17. If GlobalUserData.Exists("Tolerance", 1) Then
  18. text = GlobalUserData("Tolerance", 1)
  19. End If
  20. text = InputBox("请输入容差值 0.1 --> 9.9", "容差值(mm)", text)
  21. If text = "" Then Exit Function
  22. GlobalUserData("Tolerance", 1) = text
  23. End Function
  24. Public Function Set_Space_Width() As Double
  25. Dim text As String
  26. If GlobalUserData.Exists("SpaceWidth", 1) Then
  27. text = GlobalUserData("SpaceWidth", 1)
  28. End If
  29. text = InputBox("请输入间隔宽度值 0 --> 99", "设置间隔宽度(mm)", text)
  30. If text = "" Then Exit Function
  31. GlobalUserData("SpaceWidth", 1) = text
  32. Set_Space_Width = Val(text)
  33. End Function
  34. '// 获得剪贴板文本字符
  35. Public Function GetClipBoardString() As String
  36. On Error Resume Next
  37. Dim MyData As New DataObject
  38. GetClipBoardString = ""
  39. MyData.GetFromClipboard
  40. GetClipBoardString = MyData.GetText
  41. Set MyData = Nothing
  42. End Function
  43. '// 文本字符复制到剪贴板
  44. Public Function WriteClipBoard(ByVal s As String)
  45. On Error Resume Next
  46. ' VBA_WIN10(vba7) 使用PutInClipboard乱码解决办法
  47. #If VBA7 Then
  48. With CreateObject("Forms.TextBox.1")
  49. .MultiLine = True
  50. .text = s
  51. .SelStart = 0
  52. .SelLength = .TextLength
  53. .Copy
  54. End With
  55. #Else
  56. Dim MyData As New DataObject
  57. MyData.SetText s
  58. MyData.PutInClipboard
  59. #End If
  60. End Function
  61. '// 获得数组元素个数
  62. Public Function arrlen(src As Variant) As Integer
  63. On Error Resume Next '空意味着 0 长度
  64. arrlen = (UBound(src) - LBound(src))
  65. End Function
  66. '// 对数组进行排序[单维]
  67. Public Function ArraySort(src As Variant) As Variant
  68. Dim out As Long, i As Long, tmp As Variant
  69. For out = LBound(src) To UBound(src) - 1
  70. For i = out + 1 To UBound(src)
  71. If src(out) > src(i) Then
  72. tmp = src(i): src(i) = src(out): src(out) = tmp
  73. End If
  74. Next i
  75. Next out
  76. ArraySort = src
  77. End Function
  78. '// 测试数组排序
  79. Private test_ArraySort()
  80. Dim arr As Variant, i As Integer
  81. arr = Array(5, 4, 3, 2, 1, 9, 999, 33)
  82. For i = 0 To arrlen(arr) - 1
  83. Debug.Print arr(i);
  84. Next i
  85. Debug.Print arrlen(arr)
  86. ArraySort arr
  87. For i = 0 To arrlen(arr) - 1
  88. Debug.Print arr(i);
  89. Next i
  90. End Sub
  91. Function FindAllShapes() As ShapeRange
  92. Dim s As Shape
  93. Dim srPowerClipped As New ShapeRange
  94. Dim sr As ShapeRange, srAll As New ShapeRange
  95. If ActiveSelection.Shapes.Count > 0 Then
  96. Set sr = ActiveSelection.Shapes.FindShapes()
  97. Else
  98. Set sr = ActivePage.Shapes.FindShapes()
  99. End If
  100. Do
  101. For Each s In sr.Shapes.FindShapes(Query:="[email protected]")
  102. srPowerClipped.AddRange s.PowerClip.Shapes.FindShapes()
  103. Next s
  104. srAll.AddRange sr
  105. sr.RemoveAll
  106. sr.AddRange srPowerClipped
  107. srPowerClipped.RemoveAll
  108. Loop Until sr.Count = 0
  109. Set FindAllShapes = srAll
  110. End Function
  111. ' ************* 函数模块 ************* '
  112. Function ExistsFile_UseFso(ByVal strPath As String) As Boolean
  113. Dim fso
  114. Set fso = CreateObject("Scripting.FileSystemObject")
  115. ExistsFile_UseFso = fso.FileExists(strPath)
  116. Set fso = Nothing
  117. End Function