智能群组和查找.bas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Attribute VB_Name = "智能群组和查找"
  2. Sub 剪贴板物件替换()
  3. Replace_UI.Show 0
  4. End Sub
  5. Public Sub 智能群组()
  6. If 0 = ActiveSelectionRange.Count Then Exit Sub
  7. On Error GoTo ErrorHandler
  8. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  9. ActiveDocument.ReferencePoint = cdrBottomLeft
  10. ActiveDocument.Unit = cdrMillimeter
  11. Dim OrigSelection As ShapeRange, sr As New ShapeRange
  12. Dim s1 As Shape, sh As Shape, s As Shape
  13. Dim x As Double, y As Double, w As Double, h As Double
  14. Dim eff1 As Effect
  15. Set OrigSelection = ActiveSelectionRange
  16. '// 遍历物件画矩形
  17. For Each sh In OrigSelection
  18. sh.GetBoundingBox x, y, w, h
  19. If w * h > 4 Then
  20. Set s = ActiveLayer.CreateRectangle2(x, y, w, h)
  21. sr.Add s
  22. '// 轴线 创建轮廓处理
  23. ElseIf w * h < 0.3 Then
  24. ' Debug.Print w * h
  25. Set eff1 = sh.CreateContour(cdrContourOutside, 0.5, 1, cdrDirectFountainFillBlend, CreateRGBColor(26, 22, 35), CreateRGBColor(26, 22, 35), CreateRGBColor(26, 22, 35), 0, 0, cdrContourSquareCap, cdrContourCornerMiteredOffsetBevel, 15#)
  26. eff1.Separate
  27. End If
  28. Next sh
  29. '// 查找轴线轮廓
  30. ActivePage.Shapes.FindShapes(Query:="@Outline.Color=RGB(26, 22, 35)").CreateSelection
  31. ActivePage.Shapes.FindShapes(Query:="@fill.Color=RGB(26, 22, 35)").AddToSelection
  32. For Each sh In ActiveSelection.Shapes
  33. sr.Add sh
  34. Next sh
  35. '// 新矩形寻找边界,散开,删除刚才画的新矩形
  36. Set s1 = sr.CustomCommand("Boundary", "CreateBoundary")
  37. Set brk1 = s1.BreakApartEx
  38. sr.Delete
  39. '// 矩形边界智能群组,删除矩形
  40. For Each s In brk1
  41. Set sh = ActivePage.SelectShapesFromRectangle(s.LeftX, s.TopY, s.RightX, s.BottomY, False)
  42. sh.Shapes.All.Group
  43. s.Delete
  44. Next
  45. ActiveDocument.EndCommandGroup
  46. Application.Optimization = False
  47. ActiveWindow.Refresh: Application.Refresh
  48. Exit Sub
  49. ErrorHandler:
  50. Application.Optimization = False
  51. MsgBox "请先选择一些物件来确定群组范围!"
  52. On Error Resume Next
  53. End Sub
  54. Function 智能群组_V1()
  55. On Error GoTo ErrorHandler
  56. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  57. ActiveDocument.Unit = cdrMillimeter
  58. Dim OrigSelection As ShapeRange, brk1 As ShapeRange
  59. Set OrigSelection = ActiveSelectionRange
  60. Dim s1 As Shape, sh As Shape, s As Shape
  61. Set s1 = OrigSelection.CustomCommand("Boundary", "CreateBoundary")
  62. ' s1.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  63. Set brk1 = s1.BreakApartEx
  64. For Each s In brk1
  65. If s.SizeHeight > 10 Then
  66. Set sh = ActivePage.SelectShapesFromRectangle(s.LeftX, s.TopY, s.RightX, s.BottomY, False)
  67. sh.Shapes.All.Group
  68. End If
  69. s.Delete
  70. Next
  71. ' ActiveDocument.ClearSelection
  72. ' ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelections
  73. '// 代码操作结束恢复窗口刷新
  74. ActiveDocument.EndCommandGroup
  75. Application.Optimization = False
  76. ActiveWindow.Refresh: Application.Refresh
  77. Exit Function
  78. ErrorHandler:
  79. Application.Optimization = False
  80. MsgBox "请先选择一些物件来确定群组范围!"
  81. On Error Resume Next
  82. End Function