123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- Attribute VB_Name = "Container"
- Public Function SetBoxName()
- API.BeginOpt "标记容器盒子"
-
- Dim box As ShapeRange, S As Shape
- Set box = ActiveSelectionRange
-
-
- For Each S In box
- S.Name = "Container"
- Next S
-
- API.EndOpt
- MsgBox "标记容器盒子" & vbNewLine & "名字: Container"
- End Function
- Public Sub Batch_ToPowerClip()
- API.BeginOpt "批量置入容器"
- Dim S As Shape, ssr As ShapeRange, box As ShapeRange
- Set ssr = Smart_Group(0.5)
-
- For Each S In ssr
- Image_ToPowerClip S
- Next S
- API.EndOpt
- End Sub
- Public Function Image_ToPowerClip(arg As Shape)
- Dim box As ShapeRange
- Dim ssr As New ShapeRange, rmsr As New ShapeRange
- Set ssr = arg.UngroupEx
-
- Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
- ssr.RemoveRange box
-
- If box.Count = 0 Then Exit Function
-
- box.SetOutlineProperties Width:=0, Color:=Nothing
- ssr.AddToPowerClip box(1), 0
- box(1).Name = "powerclip_ok"
- End Function
- Public Sub OneKey_ToPowerClip()
- API.BeginOpt "图片OneKey置入容器"
- Dim S As Shape, ssr As ShapeRange, box As ShapeRange
-
-
- Set box = ActiveSelectionRange
- For Each S In box
- If S.Type <> cdrBitmapShape Then S.Name = "Container"
- Next S
-
- Set ssr = Smart_Group(0.5)
-
- Application.Optimization = True
- For Each S In ssr
- Image_ToPowerClip S
- Next S
- API.EndOpt
- End Sub
- Public Function Remove_OutsideBox(radius As Double)
- API.BeginOpt "删除容器盒子边界外面的物"
- On Error GoTo ErrorHandler
- Dim S As Shape, bc As Shape
- Dim ssr As ShapeRange, box As ShapeRange
- Dim rmsr As New ShapeRange
- Dim x As Double, Y As Double
-
- Set ssr = ActiveSelectionRange
-
- Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
- ssr.RemoveRange box
-
- If box.Count = 0 Then GoTo ErrorHandler
- Set bc = box(1).Duplicate(0, 0)
- If bc.Type = cdrTextShape Then bc.ConvertToCurves
-
- For Each S In ssr
- x = S.CenterX: Y = S.CenterY
- If bc.IsOnShape(x, Y, radius) = cdrOutsideShape Then rmsr.Add S
- Next S
-
- rmsr.Add bc: rmsr.Delete: API.EndOpt
-
- Exit Function
- ErrorHandler:
- Application.Optimization = False
- On Error Resume Next
- End Function
- Public Function Select_OutsideBox(radius As Double)
- On Error GoTo ErrorHandler
- API.BeginOpt "选择容器外面对象"
- Dim S As Shape, bc As Shape
- Dim ssr As ShapeRange, box As ShapeRange
- Dim SelSr As New ShapeRange
- Dim x As Double, Y As Double
-
- Set ssr = ActiveSelectionRange
-
- Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
- ssr.RemoveRange box
-
- If box.Count = 0 Then GoTo ErrorHandler
- Set bc = box(1).Duplicate(0, 0)
- If bc.Type = cdrTextShape Then bc.ConvertToCurves
-
- ActiveDocument.unit = cdrMillimeter
- For Each S In ssr
- x = S.CenterX: Y = S.CenterY
- If bc.IsOnShape(x, Y, S.SizeWidth / 2 * radius) = cdrOutsideShape Then SelSr.Add S
- Next S
-
- ActiveDocument.ClearSelection
- bc.Delete: SelSr.AddToSelection: API.EndOpt
-
- Exit Function
- ErrorHandler:
- Application.Optimization = False
- End Function
- Public Function Select_by_BlendGroup(radius As Double)
- On Error GoTo ErrorHandler
- API.BeginOpt "使用调和群组选择"
- Dim S As Shape, bc As Shape
- Dim ssr As ShapeRange, box As ShapeRange, gp As ShapeRange
- Dim SelSr As New ShapeRange
- Dim x As Double, Y As Double
-
- Set ssr = ActiveSelectionRange
-
- Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
- ssr.RemoveRange box
-
- If box.Count = 0 Then GoTo ErrorHandler
- Set gp = box.Duplicate(0, 0).UngroupAllEx
- Set bc = gp.BreakApartEx.UngroupAllEx.Combine
- ActiveDocument.unit = cdrMillimeter
- For Each S In ssr
- x = S.CenterX: Y = S.CenterY
- If bc.IsOnShape(x, Y, S.SizeWidth / 2 * radius) = cdrOnMarginOfShape Then SelSr.Add S
- Next S
-
- ActiveDocument.ClearSelection
- bc.Delete: SelSr.AddToSelection: API.EndOpt
-
- Exit Function
- ErrorHandler:
- Application.Optimization = False
- On Error Resume Next
- End Function
- Public Function Select_OnMargin(radius As Double)
- On Error GoTo ErrorHandler
- API.BeginOpt "选择容器边界对象"
- Dim S As Shape, bc As Shape
- Dim ssr As ShapeRange, box As ShapeRange
- Dim SelSr As New ShapeRange
- Dim x As Double, Y As Double
-
- Set ssr = ActiveSelectionRange
-
- Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
- ssr.RemoveRange box
-
- If box.Count = 0 Then GoTo ErrorHandler
- Set bc = box(1).Duplicate(0, 0)
- If bc.Type = cdrTextShape Then bc.ConvertToCurves
-
- ActiveDocument.unit = cdrMillimeter
- For Each S In ssr
- x = S.CenterX: Y = S.CenterY
- If bc.IsOnShape(x, Y, S.SizeWidth / 2 * radius) = cdrOnMarginOfShape Then SelSr.Add S
- Next S
-
- ActiveDocument.ClearSelection
- bc.Delete: SelSr.AddToSelection: API.EndOpt
-
- Exit Function
- ErrorHandler:
- Application.Optimization = False
- On Error Resume Next
-
- End Function
- Private Function Smart_Group(Optional ByVal tr As Double = 0) As ShapeRange
- If 0 = ActiveSelectionRange.Count Then Exit Function
- On Error GoTo ErrorHandler
- Application.Optimization = True
- ActiveDocument.ReferencePoint = cdrBottomLeft
- ActiveDocument.unit = cdrMillimeter
-
- Dim OrigSelection As ShapeRange, sr As New ShapeRange
- Dim s1 As Shape, sh As Shape, S As Shape
- Dim x As Double, Y As Double, w As Double, h As Double
- Dim eff1 As Effect
-
- Set OrigSelection = ActiveSelectionRange
-
- For Each sh In OrigSelection
- sh.GetBoundingBox x, Y, w, h
- If w * h > 4 Then
- Set S = ActiveLayer.CreateRectangle2(x - tr, Y - tr, w + 2 * tr, h + 2 * tr)
- sr.Add S
-
- ElseIf w * h < 0.3 Then
-
- 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#)
- eff1.Separate
- End If
- Next sh
-
- ActivePage.Shapes.FindShapes(Query:="@Outline.Color=RGB(26, 22, 35)").CreateSelection
- ActivePage.Shapes.FindShapes(Query:="@fill.Color=RGB(26, 22, 35)").AddToSelection
- For Each sh In ActiveSelection.Shapes
- sr.Add sh
- Next sh
-
-
- Set s1 = sr.CustomCommand("Boundary", "CreateBoundary")
- Set brk1 = s1.BreakApartEx
- sr.Delete
-
- Dim retsr As New ShapeRange, rmsr As New ShapeRange
- For Each S In brk1
- Set sh = ActivePage.SelectShapesFromRectangle(S.LeftX, S.TopY, S.RightX, S.BottomY, False)
- S.Delete
- retsr.Add sh.Shapes.All.group
- Next
- Set Smart_Group = retsr
-
- Application.Optimization = False
- ActiveWindow.Refresh: Application.Refresh
- Exit Function
- ErrorHandler:
- Application.Optimization = False
- MsgBox "请先选择一些物件来确定群组范围!"
- On Error Resume Next
- End Function
|