1
1

Container.bas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. Attribute VB_Name = "Container"
  2. Public Function SetBoxName()
  3. API.BeginOpt "Undo SetBoxName"
  4. Dim box As ShapeRange, s As Shape
  5. Set box = ActiveSelectionRange
  6. For Each s In box
  7. s.name = "Container"
  8. Next s
  9. API.EndOpt
  10. End Function
  11. Public Function Batch_ToPowerClip()
  12. API.BeginOpt "Batch_ToPowerClip"
  13. Dim s As Shape, ssr As ShapeRange, box As ShapeRange
  14. Set ssr = API.Smart_Group(0.5)
  15. For Each s In ssr
  16. Image_ToPowerClip s
  17. Next s
  18. API.EndOpt
  19. End Function
  20. Public Function Image_ToPowerClip(arg As Shape)
  21. API.BeginOpt "ToPowerClip"
  22. Dim box As ShapeRange
  23. Dim ssr As New ShapeRange, rmsr As New ShapeRange
  24. Set ssr = arg.UngroupEx
  25. Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
  26. ssr.RemoveRange box
  27. If box.count = 0 Then Exit Function
  28. box.SetOutlineProperties width:=0, Color:=Nothing
  29. ssr.AddToPowerClip box(1), 0
  30. box(1).name = "powerclip_ok"
  31. API.EndOpt
  32. End Function
  33. Public Function OneKey_ToPowerClip()
  34. API.BeginOpt "OneKey_ToPowerClip"
  35. Dim s As Shape, ssr As ShapeRange, box As ShapeRange
  36. Set box = ActiveSelectionRange
  37. For Each s In box
  38. If s.Type <> cdrBitmapShape Then s.name = "Container"
  39. Next s
  40. Set ssr = API.Smart_Group(0.5)
  41. Application.Optimization = True
  42. For Each s In ssr
  43. Image_ToPowerClip s
  44. Next s
  45. API.EndOpt
  46. End Function
  47. Public Function Remove_OutsideBox(radius As Double)
  48. API.BeginOpt "Undo Remove"
  49. On Error GoTo ErrorHandler
  50. Dim s As Shape, bc As Shape
  51. Dim ssr As ShapeRange, box As ShapeRange
  52. Dim rmsr As New ShapeRange
  53. Dim X As Double, Y As Double
  54. Set ssr = ActiveSelectionRange
  55. Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
  56. ssr.RemoveRange box
  57. If box.count = 0 Then GoTo ErrorHandler
  58. Set bc = box(1).Duplicate(0, 0)
  59. If bc.Type = cdrTextShape Then bc.ConvertToCurves
  60. For Each s In ssr
  61. X = s.CenterX: Y = s.CenterY
  62. If bc.IsOnShape(X, Y, radius) = cdrOutsideShape Then rmsr.Add s
  63. Next s
  64. rmsr.Add bc: rmsr.Delete: API.EndOpt
  65. Exit Function
  66. ErrorHandler:
  67. Application.Optimization = False
  68. On Error Resume Next
  69. End Function
  70. Public Function Select_SideBox(side As cdrPositionOfPointOverShape)
  71. On Error GoTo ErrorHandler
  72. API.BeginOpt "Undo Select"
  73. Dim s As Shape, bc As Shape
  74. Dim ssr As ShapeRange, box As ShapeRange
  75. Dim SelSr As New ShapeRange
  76. Dim X As Double, Y As Double, radius As Double
  77. If GlobalUserData.Exists("Tolerance", 1) Then radius = Val(GlobalUserData("Tolerance", 1))
  78. Set ssr = ActiveSelectionRange
  79. If ssr.count = 1 Then ssr.AddRange ActivePage.Shapes.FindShapes(Query:="!@name ='Container'")
  80. Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
  81. ssr.RemoveRange box
  82. If box.count = 0 Then GoTo ErrorHandler
  83. Set bc = box(1).Duplicate(0, 0)
  84. bc.Fill.ApplyUniformFill CreateCMYKColor(0, 100, 0, 0)
  85. If bc.Type = cdrTextShape Then bc.ConvertToCurves
  86. ActiveDocument.Unit = cdrMillimeter
  87. For Each s In ssr
  88. X = s.CenterX: Y = s.CenterY
  89. If side = (cdrInsideShape + cdrOnMarginOfShape) Then
  90. If bc.IsOnShape(X, Y, s.SizeWidth / 2 * radius) = cdrInsideShape Then SelSr.Add s
  91. If bc.IsOnShape(X, Y, s.SizeWidth / 2 * radius) = cdrOnMarginOfShape Then SelSr.Add s
  92. Else
  93. If bc.IsOnShape(X, Y, s.SizeWidth / 2 * radius) = side Then SelSr.Add s
  94. End If
  95. Next s
  96. ActiveDocument.ClearSelection
  97. bc.Delete: SelSr.AddToSelection: API.EndOpt
  98. Exit Function
  99. ErrorHandler:
  100. Application.Optimization = False
  101. End Function
  102. Public Function Select_by_BlendGroup(radius As Double)
  103. On Error GoTo ErrorHandler
  104. API.BeginOpt "Undo Select"
  105. Dim s As Shape, bc As Shape
  106. Dim ssr As ShapeRange, box As ShapeRange, gp As ShapeRange
  107. Dim SelSr As New ShapeRange
  108. Dim X As Double, Y As Double
  109. Set ssr = ActiveSelectionRange
  110. Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
  111. ssr.RemoveRange box
  112. If box.count = 0 Then GoTo ErrorHandler
  113. Set gp = box.Duplicate(0, 0).UngroupAllEx
  114. Set gp = gp.BreakApartEx.UngroupAllEx
  115. ActiveDocument.Unit = cdrMillimeter
  116. For Each s In ssr
  117. X = s.CenterX: Y = s.CenterY
  118. For Each bc In gp
  119. If bc.IsOnShape(X, Y, s.SizeWidth / 2 * radius) = cdrOnMarginOfShape Then SelSr.Add s
  120. Next bc
  121. Next s
  122. ActiveDocument.ClearSelection
  123. gp.Delete: SelSr.AddToSelection: API.EndOpt
  124. Exit Function
  125. ErrorHandler:
  126. Application.Optimization = False
  127. On Error Resume Next
  128. End Function
  129. Public Function Select_Quick_BlendGroup(radius As Double)
  130. On Error GoTo ErrorHandler
  131. API.BeginOpt "Undo Select"
  132. Dim s As Shape, bc As Shape
  133. Dim ssr As ShapeRange, box As ShapeRange, gp As ShapeRange
  134. Dim SelSr As New ShapeRange
  135. Dim X As Double, Y As Double
  136. Set ssr = ActiveSelectionRange
  137. Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
  138. ssr.RemoveRange box
  139. If box.count = 0 Then GoTo ErrorHandler
  140. Set gp = box.Duplicate(0, 0).UngroupAllEx
  141. Set bc = gp.BreakApartEx.UngroupAllEx.Combine
  142. ActiveDocument.Unit = cdrMillimeter
  143. For Each s In ssr
  144. X = s.CenterX: Y = s.CenterY
  145. If bc.IsOnShape(X, Y, s.SizeWidth / 2 * radius) = cdrOnMarginOfShape Then SelSr.Add s
  146. Next s
  147. ActiveDocument.ClearSelection
  148. bc.Delete: SelSr.AddToSelection: API.EndOpt
  149. Exit Function
  150. ErrorHandler:
  151. Application.Optimization = False
  152. On Error Resume Next
  153. End Function