智能群组和查找.bas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, _
  26. CreateRGBColor(26, 22, 35), CreateRGBColor(26, 22, 35), CreateRGBColor(26, 22, 35), 0, 0, cdrContourSquareCap, cdrContourCornerMiteredOffsetBevel, 15#)
  27. eff1.Separate
  28. End If
  29. Next sh
  30. '// 查找轴线轮廓
  31. ActivePage.Shapes.FindShapes(Query:="@Outline.Color=RGB(26, 22, 35)").CreateSelection
  32. ActivePage.Shapes.FindShapes(Query:="@fill.Color=RGB(26, 22, 35)").AddToSelection
  33. For Each sh In ActiveSelection.Shapes
  34. sr.Add sh
  35. Next sh
  36. '// 新矩形寻找边界,散开,删除刚才画的新矩形
  37. Set s1 = sr.CustomCommand("Boundary", "CreateBoundary")
  38. Set brk1 = s1.BreakApartEx
  39. sr.Delete
  40. '// 矩形边界智能群组,删除矩形
  41. For Each s In brk1
  42. Set sh = ActivePage.SelectShapesFromRectangle(s.LeftX, s.TopY, s.RightX, s.BottomY, False)
  43. sh.Shapes.All.Group
  44. s.Delete
  45. Next
  46. ActiveDocument.EndCommandGroup
  47. Application.Optimization = False
  48. ActiveWindow.Refresh: Application.Refresh
  49. Exit Sub
  50. ErrorHandler:
  51. Application.Optimization = False
  52. MsgBox "请先选择一些物件来确定群组范围!"
  53. On Error Resume Next
  54. End Sub
  55. ' 智能群组_V1 第一版,储备示例代码
  56. Function 智能群组_V1()
  57. On Error GoTo ErrorHandler
  58. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  59. ActiveDocument.Unit = cdrMillimeter
  60. Dim OrigSelection As ShapeRange, brk1 As ShapeRange
  61. Set OrigSelection = ActiveSelectionRange
  62. Dim s1 As Shape, sh As Shape, s As Shape
  63. Set s1 = OrigSelection.CustomCommand("Boundary", "CreateBoundary")
  64. ' s1.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
  65. Set brk1 = s1.BreakApartEx
  66. For Each s In brk1
  67. If s.SizeHeight > 10 Then
  68. Set sh = ActivePage.SelectShapesFromRectangle(s.LeftX, s.TopY, s.RightX, s.BottomY, False)
  69. sh.Shapes.All.Group
  70. End If
  71. s.Delete
  72. Next
  73. ' ActiveDocument.ClearSelection
  74. ' ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelections
  75. '// 代码操作结束恢复窗口刷新
  76. ActiveDocument.EndCommandGroup
  77. Application.Optimization = False
  78. ActiveWindow.Refresh: Application.Refresh
  79. Exit Function
  80. ErrorHandler:
  81. Application.Optimization = False
  82. MsgBox "请先选择一些物件来确定群组范围!"
  83. On Error Resume Next
  84. End Function