剪贴板尺寸建立矩形.bas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Attribute VB_Name = "剪贴板尺寸建立矩形"
  2. '// Attribute VB_Name = "剪贴板尺寸建立矩形"
  3. Type Coordinate
  4. x As Double
  5. y As Double
  6. End Type
  7. Public O_O As Coordinate
  8. Sub start()
  9. '// 坐标原点
  10. O_O.x = 0: O_O.y = 0
  11. Dim ost As ShapeRange
  12. Set ost = ActiveSelectionRange
  13. O_O.x = ost.LeftX
  14. O_O.y = ost.BottomY - 50 '选择物件 下移动 50mm
  15. '// 建立矩形 Width x Height 单位 mm
  16. Dim Str, arr, n
  17. Str = API.GetClipBoardString
  18. ' 替换 mm x * 换行 TAB 为空格
  19. Str = VBA.replace(Str, "m", " ")
  20. Str = VBA.replace(Str, "x", " ")
  21. Str = VBA.replace(Str, "X", " ")
  22. Str = VBA.replace(Str, "*", " ")
  23. Str = VBA.replace(Str, vbNewLine, " ")
  24. Do While InStr(Str, " ") '多个空格换成一个空格
  25. Str = VBA.replace(Str, " ", " ")
  26. Loop
  27. arr = Split(Str)
  28. ActiveDocument.BeginCommandGroup '一步撤消'
  29. Dim x As Double
  30. Dim y As Double
  31. For n = LBound(arr) To UBound(arr) - 1 Step 2
  32. ' MsgBox arr(n)
  33. x = Val(arr(n))
  34. y = Val(arr(n + 1))
  35. If x > 0 And y > 0 Then
  36. Rectangle x, y
  37. O_O.x = O_O.x + x + 30
  38. End If
  39. Next
  40. ActiveDocument.EndCommandGroup
  41. End Sub
  42. '// 建立矩形 Width x Height 单位 mm
  43. Private Function Rectangle(Width As Double, Height As Double)
  44. ActiveDocument.Unit = cdrMillimeter
  45. Dim size As Shape
  46. Dim d As Document
  47. Dim s1 As Shape
  48. '// 建立矩形 Width x Height 单位 mm
  49. Set s1 = ActiveLayer.CreateRectangle(O_O.x, O_O.y, O_O.x + Width, O_O.y - Height)
  50. '// 填充颜色无,轮廓颜色 K100,线条粗细0.3mm
  51. s1.Fill.ApplyNoFill
  52. s1.Outline.SetProperties 0.3, OutlineStyles(0), CreateCMYKColor(0, 100, 0, 0), ArrowHeads(0), ArrowHeads(0), cdrFalse, cdrFalse, cdrOutlineButtLineCaps, cdrOutlineMiterLineJoin, 0#, 100, MiterLimit:=5#
  53. sw = s1.SizeWidth
  54. sh = s1.SizeHeight
  55. text = Trim(Str(sw)) + "x" + Trim(Str(sh)) + "mm"
  56. Set d = ActiveDocument
  57. Set size = d.ActiveLayer.CreateArtisticText(O_O.x + sw / 2 - 25, O_O.y + 10, text, Font:="Tahoma") '// O_O.y + 10 标注尺寸上移 10mm
  58. size.Fill.UniformColor.CMYKAssign 0, 100, 100, 0
  59. End Function
  60. ' 测试矩形变形
  61. Private Function setRectangle(Width As Double, Height As Double)
  62. Dim s1 As Shape
  63. Set s1 = ActiveSelection
  64. ActiveDocument.Unit = cdrMillimeter
  65. '// 物件中心基准, 先把宽度设定为
  66. ActiveDocument.ReferencePoint = cdrCenter
  67. s1.SetSize Height, Height
  68. '// 物件旋转 30度,轮廓线1mm ,轮廓颜色 M100Y100
  69. s1.Rotate 30#
  70. s1.Outline.SetProperties 1#
  71. s1.Outline.SetProperties Color:=CreateCMYKColor(0, 100, 100, 0)
  72. End Function
  73. '// 获得选择物件大小信息
  74. Sub get_all_size()
  75. ActiveDocument.Unit = cdrMillimeter
  76. Set fs = CreateObject("Scripting.FileSystemObject")
  77. Set f = fs.CreateTextFile("R:\size.txt", True)
  78. Dim sh As Shape, shs As Shapes
  79. Set shs = ActiveSelection.Shapes
  80. Dim s As String
  81. For Each sh In shs
  82. size = Trim(Str(Int(sh.SizeWidth + 0.5))) + "x" + Trim(Str(Int(sh.SizeHeight + 0.5))) + "mm"
  83. f.WriteLine (size)
  84. s = s + size + vbNewLine
  85. Next sh
  86. f.Close
  87. MsgBox "输出物件尺寸信息到文件" & "R:\size.txt" & vbNewLine & s
  88. API.WriteClipBoard s
  89. End Sub