Browse Source

Add imposition-container-select the same module and window

Hongwenjun 1 year ago
parent
commit
8a1f2ec7f3
5 changed files with 1340 additions and 0 deletions
  1. 87 0
      UI/frmArrange.bas
  2. 258 0
      UI/frmEditPowerClip.bas
  3. 692 0
      UI/frmSelectSame.bas
  4. 114 0
      module/AutoCutLines.bas
  5. 189 0
      module/Container.bas

+ 87 - 0
UI/frmArrange.bas

@@ -0,0 +1,87 @@
+VERSION 5.00
+Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} joyar01 
+   Caption         =   "蘭雅sRGB 手动拼版 │ 嘉盟赞助"
+   ClientHeight    =   2475
+   ClientLeft      =   45
+   ClientTop       =   330
+   ClientWidth     =   4650
+   OleObjectBlob   =   "joyar01.frx":0000
+   ShowModal       =   0   'False
+   StartUpPosition =   2  '屏幕中心
+   WhatsThisButton =   -1  'True
+   WhatsThisHelp   =   -1  'True
+End
+Attribute VB_Name = "joyar01"
+Attribute VB_GlobalNameSpace = False
+Attribute VB_Creatable = False
+Attribute VB_PredeclaredId = True
+Attribute VB_Exposed = False
+Private Sub CommandButton1_Click()
+  On Error GoTo ErrorHandler
+  ActiveDocument.Unit = cdrMillimeter
+  Dim ls As Integer, hs As Integer
+  Dim lj As Double, hj As Double
+  Dim matrix As Variant
+  Dim s As ShapeRange
+  
+  ls = Val(TextBox1.text)
+  hs = Val(TextBox2.text)
+  lj = Val(TextBox3.text)
+  hj = Val(TextBox4.text)
+  matrix = Array(ls, hs, lj, hj)
+  
+  Set s = ActiveSelectionRange
+
+  If ls * hs = 0 Then Exit Sub
+  If ls = 1 Or hs = 1 Then
+    arrange_Clone_one matrix, s
+    Exit Sub
+  End If
+  
+  '// 代码运行时关闭窗口刷新
+  ActiveDocument.BeginCommandGroup:  Application.Optimization = True
+  '// 拼版矩阵
+  arrange_Clone matrix, s
+
+  ActiveDocument.EndCommandGroup
+  Unload Me
+  
+  '// 代码操作结束恢复窗口刷新
+  ActiveDocument.EndCommandGroup
+  Application.Optimization = False
+  ActiveWindow.Refresh:    Application.Refresh
+  Exit Sub
+ErrorHandler:
+  Application.Optimization = False
+  On Error Resume Next
+End Sub
+
+'// 拼版矩阵  matrix = Array(ls,hs,lj,hj)
+Private Function arrange_Clone(matrix As Variant, s As ShapeRange)
+  ls = matrix(0): hs = matrix(1)
+  lj = matrix(2): hj = matrix(3)
+  x = s.SizeWidth: y = s.SizeHeight
+  Set s1 = s.Clone
+  '// StepAndRepeat 方法在范围内创建多个形状副本
+  Set dup1 = s1.StepAndRepeat(ls - 1, x + lj, 0#)
+  Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(hs - 1, 0#, -(y + hj))
+  s1.Delete
+End Function
+
+Private Function arrange_Clone_one(matrix As Variant, s As ShapeRange)
+  ls = matrix(0): hs = matrix(1)
+  lj = matrix(2): hj = matrix(3)
+  x = s.SizeWidth: y = s.SizeHeight
+  Set s1 = s.Clone
+  '// StepAndRepeat 方法在范围内创建多个形状副本
+  If ls > 1 Then
+    Set dup1 = s1.StepAndRepeat(ls - 1, x + lj, 0#)
+  Else
+    Set dup1 = s1
+  End If
+  If hs > 1 Then
+    Set dup2 = ActiveDocument.CreateShapeRangeFromArray(dup1, s1).StepAndRepeat(hs - 1, 0#, -(y + hj))
+  End If
+  s1.Delete
+End Function
+

+ 258 - 0
UI/frmEditPowerClip.bas

@@ -0,0 +1,258 @@
+VERSION 5.00
+Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmEditPowerClip 
+   Caption         =   "容器便捷调整"
+   ClientHeight    =   3090
+   ClientLeft      =   120
+   ClientTop       =   465
+   ClientWidth     =   3510
+   OleObjectBlob   =   "frmEditPowerClip.frx":0000
+   ShowModal       =   0   'False
+   StartUpPosition =   2  '屏幕中心
+End
+Attribute VB_Name = "frmEditPowerClip"
+Attribute VB_GlobalNameSpace = False
+Attribute VB_Creatable = False
+Attribute VB_PredeclaredId = True
+Attribute VB_Exposed = False
+
+Option Explicit
+Dim xzbj As Boolean
+Private Sub Frame2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call commdanliu(Lab001)
+    Call commdanliu(Lab002)
+    Call commdanliu(Lab003)
+    Call commdanliu(Lab004)
+    Call commdanliu(Lab005)
+    Call commdanliu(Lab006)
+    Call commdanliu(Lab007)
+    Call commdanliu(Lab008)
+End Sub
+Private Sub Lab001_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab001)
+End Sub
+Private Sub Lab002_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab002)
+End Sub
+Private Sub Lab003_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab003)
+End Sub
+Private Sub Lab004_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab004)
+End Sub
+Private Sub Lab005_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab005)
+End Sub
+Private Sub Lab006_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab006)
+End Sub
+Private Sub Lab007_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab007)
+End Sub
+Private Sub Lab008_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    Call anliumove(Lab008)
+End Sub
+Private Sub Lab001_Click()
+    BeginOpt "提取裁切框内容"
+    Container.Extractall (IIf(CheckBox1.Value, True, False))
+    EndOpt
+End Sub
+Private Sub Lab002_Click()
+    BeginOpt "清空裁切框"
+    Container.Emptyall
+    EndOpt
+End Sub
+Private Sub Lab003_Click()
+    BeginOpt "按比例调整内容"
+        Container.Bilingtznr
+    EndOpt
+End Sub
+Private Sub Lab004_Click()
+    BeginOpt "按比例填充"
+        Container.Bilintianchun
+    EndOpt
+End Sub
+Private Sub Lab005_Click()
+    BeginOpt "延展填充"
+    Container.Qiangzhitianmian
+    EndOpt
+End Sub
+Private Sub Lab006_Click()
+    BeginOpt "锁定精确裁剪"
+    Container.Lockall True
+    EndOpt
+End Sub
+Private Sub Lab007_Click()
+    BeginOpt "解锁精确裁剪"
+        Container.Lockall False
+    EndOpt
+End Sub
+Private Sub Lab008_Click()
+    BeginOpt "内容居中"
+    Container.CenterToPC
+    EndOpt
+End Sub
+Private Sub txtNilai_Change()
+   Dim i As Integer
+   Dim s As String
+   With txtNilai
+      For i = 1 To VBA.Len(.text)
+           s = VBA.Mid(.text, i, 1)
+            Select Case s
+              Case ".", "0" To "9"
+              Case Else
+               .text = VBA.Replace(.text, s, "")
+            End Select
+         Next
+     End With
+End Sub
+Private Sub SpinButton1_SpinUp()
+    txtNilai.text = VBA.CStr(txtNilai.Value + 1)
+End Sub
+Private Sub SpinButton1_SpinDown()
+    If txtNilai.Value <= 1 Then Exit Sub
+    txtNilai.text = VBA.CStr(txtNilai.Value - 1)
+End Sub
+Private Sub UserForm_Initialize()
+    If Strbjini = "" Then Strbjini = VBA.GetSetting(xylAppName, xylSection, "Apppath"): BJAppLJ = Strbjini & "\DaTa\dat\"
+    If GetmdbValue(BJAppLJ & "xylTools.ini", "Form", "rqtzFr_l", "") <> "" Then
+        Me.StartUpPosition = 0
+        Me.Left = GetmdbValue(BJAppLJ & "xylTools.ini", "Form", "rqtzFr_l", "")
+        Me.Top = GetmdbValue(BJAppLJ & "xylTools.ini", "Form", "rqtzFr_t", "")
+    End If
+    Call AddStroyComandBox(Me.cboUnit, "毫米,厘米,英寸,像素")
+    Me.cboUnit.text = GetmdbValue(BJAppLJ & "xylTools.ini", "Rongqibjtz", "单位", "毫米")
+    xzbj = False
+    cboUnit.Enabled = False
+    txtNilai.Enabled = False
+    SpinButton1.Enabled = False
+    spnPositionX.Enabled = False
+    spnPositionY.Enabled = False
+    spnZoom.Enabled = False
+    spnRotate.Enabled = False
+    Me.Tis.BackColor = RGB(0, 147, 222)
+    Me.Tis.ForeColor = RGB(255, 255, 255)
+    Me.Tis.Caption = "  可以选择一个容器对象后操作!"
+End Sub
+Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
+    SetmdbValue BJAppLJ & "xylTools.ini", "Form", "rqtzFr_l", frmEditPowerClip.Left
+    SetmdbValue BJAppLJ & "xylTools.ini", "Form", "rqtzFr_t", frmEditPowerClip.Top
+    SetmdbValue BJAppLJ & "xylTools.ini", "Rongqibjtz", "单位", Me.cboUnit.text
+End Sub
+Sub getShapeByUser()
+re:
+    Dim doc As Document, retval As Long
+    Dim x As Double, Y As Double, Shift As Long
+    Dim o_seleksi As ShapeRange
+    Set doc = ActiveDocument
+    doc.ReferencePoint = cdrCenter
+    retval = doc.GetUserClick(x, Y, Shift, 10, True, cdrCursorPick)
+    doc.ActivePage.SelectShapesAtPoint x, Y, True
+    Dim SC As Shape
+    Dim sp As PowerClip
+    Set SC = ActiveShape
+    If SC Is Nothing Then xzbj = False: Me.Show: Exit Sub
+    Set sp = SC.PowerClip
+    If sp Is Nothing Then
+        AutoMsgbox "选择对象不是容器;" & vbCrLf & "可以重新选择,或点击空白处退出!", vbCritical, "新印联提示": GoTo re
+    Else
+        If sp.Shapes.Count = 0 Then
+            AutoMsgbox "容器为空;" & vbCrLf & "可以重新选择,或点击空白处退出!", vbCritical, "新印联提示": GoTo re
+        End If
+    End If
+    xzbj = True
+End Sub
+Sub doAction(ByVal doAction As String, Optional ByVal bolUp As Boolean = False)
+    doAction = VBA.LCase(doAction)
+    ActiveDocument.ReferencePoint = cdrCenter
+    If cboUnit.ListIndex = 0 Then
+        ActiveDocument.Unit = cdrMillimeter
+    ElseIf cboUnit.ListIndex = 1 Then
+        ActiveDocument.Unit = cdrCentimeter
+    ElseIf cboUnit.ListIndex = 2 Then
+        ActiveDocument.Unit = cdrInch
+    ElseIf cboUnit.ListIndex = 3 Then
+        ActiveDocument.Unit = cdrPixel
+    End If '
+    Dim setNilai As Double
+    setNilai = CDbl(txtNilai.Value)
+    If bolUp = False Then setNilai = -setNilai
+    Dim s As Shape, sr As ShapeRange
+    Set sr = ActiveSelectionRange
+    For Each s In sr
+        Call checkPowerClip(s, doAction, setNilai, bolUp)
+    Next s
+End Sub
+Private Function checkPowerClip(s As Shape, ByVal doAction As String, ByVal setNilai As Double, ByVal bolUp As Boolean)
+    Dim pwc As PowerClip, sr As ShapeRange
+    If Not s.PowerClip Is Nothing Then
+        Set pwc = s.PowerClip
+        Set sr = pwc.Shapes.FindShapes
+        If doAction = "position_x" Then
+            sr.PositionX = sr.PositionX + setNilai
+        ElseIf doAction = "position_y" Then
+            sr.PositionY = sr.PositionY + setNilai
+        ElseIf doAction = "rotate" Then
+            sr.Rotate setNilai
+        ElseIf doAction = "zoom" Then
+            sr.Stretch sr.SizeWidth / (sr.SizeWidth + setNilai)
+        End If
+    End If
+End Function
+Private Sub cmdPickObject_Click()
+    Me.Hide
+    Call getShapeByUser
+    If xzbj = True Then
+       Me.Tis.Caption = "  可以重新选择一个容器操作!"
+       If cmdPickObject.ControlTipText = "选择容器" Then
+          cboUnit.Enabled = True
+          txtNilai.Enabled = True
+          SpinButton1.Enabled = True
+          spnPositionX.Enabled = True
+          spnPositionY.Enabled = True
+          spnZoom.Enabled = True
+          spnRotate.Enabled = True
+       End If
+       Me.Show
+       cmdPickObject.ControlTipText = "重新选择一个容器"
+    End If
+End Sub
+Private Sub spnPositionX_SpinDown()
+    Call doAction("position_x", False)
+End Sub
+Private Sub spnPositionX_SpinUp()
+    Call doAction("position_x", True)
+End Sub
+Private Sub spnPositionY_SpinDown()
+    Call doAction("position_y", False)
+End Sub
+Private Sub spnPositionY_SpinUp()
+    Call doAction("position_y", True)
+End Sub
+Private Sub spnRotate_SpinUp()
+    Call doAction("rotate", False)
+End Sub
+Private Sub spnRotate_SpinDown()
+    Call doAction("rotate", True)
+End Sub
+Private Sub spnZoom_SpinUp()
+    Call doAction("zoom", False)
+End Sub
+Private Sub spnZoom_SpinDown()
+    Call doAction("zoom", True)
+End Sub
+Private Sub Frame1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+     cmdPickObject.SpecialEffect = fmSpecialEffectEtched
+End Sub
+Private Sub cmdPickObject_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+   cmdPickObject.SpecialEffect = fmSpecialEffectSunken
+End Sub
+Private Sub cmdPickObject_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    cmdPickObject.SpecialEffect = fmSpecialEffectRaised
+End Sub
+Private Sub cmdPickObject_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
+    If Button = 0 Then
+        cmdPickObject.SpecialEffect = fmSpecialEffectRaised
+    ElseIf Button = 1 Then
+        cmdPickObject.SpecialEffect = fmSpecialEffectSunken
+    End If
+End Sub

+ 692 - 0
UI/frmSelectSame.bas

@@ -0,0 +1,692 @@
+VERSION 5.00
+Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmSelectSame 
+   Caption         =   "相似选择"
+   ClientHeight    =   4770
+   ClientLeft      =   495
+   ClientTop       =   5895
+   ClientWidth     =   2625
+   OleObjectBlob   =   "frmSelectSame.frx":0000
+   ShowModal       =   0   'False
+End
+Attribute VB_Name = "frmSelectSame"
+Attribute VB_GlobalNameSpace = False
+Attribute VB_Creatable = False
+Attribute VB_PredeclaredId = True
+Attribute VB_Exposed = False
+
+Option Explicit         'Requires explicit declaration of all
+                        'variables. This protects against
+                        'inadvertent use of the slow 'Variant' type
+                        'variables which are used when the specific
+                        'type is unknown.
+                        
+Private Const TOOLNAME As String = "VBA_SelectSame"
+Private Const SECTION As String = "Options"
+
+ Private Sub btnSelect_Click()
+    On Error Resume Next
+    Dim fLeft As Double, fTop As Double
+    fLeft = frmSelectSame.Left
+    fTop = frmSelectSame.Top
+    SaveSetting "SelectSame", "Preferences", "form_left", fLeft
+    SaveSetting "SelectSame", "Preferences", "form_top", fTop
+    beg
+    
+    If (chkFill = False And _
+        chkOutline = False And _
+        chkOutlineColor = False And _
+        chkOutlineLength = False And _
+        chkSize = False And _
+        chkWHratio = False And _
+        chkType = False And _
+        chkNodes = False And _
+        chkSegments = False And _
+        chkPaths = False) Then
+            MsgBox "请至少选择一个选项", vbCritical, "JH Select Same 2"
+            Exit Sub
+    End If
+            
+    With Me '"Me" is a VBA reserved word, returning a
+                        'reference to the form (or class module)
+                        'in which the current code is located.
+                        'The chk... functions return the current
+                        'Value of the check buttons of the same
+                        'name.
+        .SelectAllSimilar .chkFill, .chkOutline, .chkOutlineColor, .chkOutlineLength, _
+            .chkSize, .chkWHratio, .chkType, .chkNodes, .chkSegments, .chkPaths, _
+             .OptDoc, .Optpage, .Optlayer, .chkInGroups, .chkColorMark, .chkIndiv
+    End With
+    
+    EndOpt
+    
+'Added to fix refresh issues
+ActiveWindow.Refresh
+Application.Refresh
+
+'On Error Resume Next
+'    If VersionMajor = 13 Then
+'        AppActivate "CorelDRAW X3"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 14 Then
+'        AppActivate "CorelDRAW X4"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 15 Then
+'        AppActivate "CorelDRAW X5"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 16 Then
+'        AppActivate "CorelDRAW X6"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 17 Then
+'        AppActivate "CorelDRAW X7"
+'        AppActivate ActiveDocument
+'    End If
+'        If VersionMajor = 18 Then
+'        AppActivate "CorelDRAW X8"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 19 Then
+'        AppActivate "CorelDRAW 2017"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 20 Then
+'        AppActivate "CorelDRAW 2018"
+'        AppActivate ActiveDocument
+'    End If
+'    If VersionMajor = 21 Then
+'        AppActivate "CorelDRAW 2019"
+'        AppActivate ActiveDocument
+'    End If
+End Sub
+Sub SelectAllSimilar(Optional CheckFill As Boolean = True, _
+                    Optional CheckOutline As Boolean = True, _
+                    Optional CheckOutlineColor As Boolean = True, _
+                    Optional CheckOutlineLength As Boolean = True, _
+                    Optional CheckSize As Boolean = False, _
+                    Optional CheckWHratio As Boolean = False, _
+                    Optional CheckType As Boolean = True, _
+                    Optional CountNodes As Boolean = False, _
+                    Optional CountSegments As Boolean = False, _
+                    Optional CountPaths As Boolean = False, _
+                    Optional WithinDoc As Boolean = False, _
+                    Optional WithinPage As Boolean = True, _
+                    Optional WithinLayer As Boolean = False, _
+                    Optional WithinGroups As Boolean = True, _
+                    Optional CheckColorMark As Boolean = False, _
+                    Optional CheckIndiv As Boolean = True)
+                    
+    'Object variables.              Reference to:
+    Dim shpsSelected As Shapes          'selected shapes,
+    Dim shpsToTest As Shapes            'full set of shapes to be tested,
+    Dim pagesr As ShapeRange           'pages shapes collection,
+    Dim docsr As New ShapeRange
+    Dim shpModel As Shape               'a pre-selected shape,
+    Dim shpToMatch As Shape             'a shape to be matched,
+    'Dim oScript As Object               'CorelScript object,
+    Dim clnModelShapes As Collection    'our list of pre-selected shapes,定义源对象集合
+    Dim clnSubShapes As Collection      'our list of shapes inside a group. 定义群组内的目标对象
+    Dim P As Page, p1 As Page           '文档中查找使用
+    Dim shr As ShapeRange, sr As New ShapeRange
+    Dim i As Integer  ' '文档中循环查找计数使用
+                                            
+    On Error GoTo NothingSelected       'Get a reference to any
+    Set shr = ActiveSelectionRange
+    Set shpsSelected = ActiveDocument.Selection.Shapes
+    On Error GoTo 0                     'pre-selected shapes. 将文档中当前选中的范围作为源对象
+    
+    If shpsSelected.Count > 0 Then          'Gather the pre-selected shapes
+        Set clnModelShapes = New Collection 'into a new collection for
+        For Each shpModel In shpsSelected   'simple processing. 建立源对象集合
+           clnModelShapes.Add shpModel
+        Next
+        
+        '===================================
+        ' TurnOptimizations cdrOptimizationOn
+        '===================================
+       
+        
+        If WithinPage Then
+            Set shpsToTest = ActivePage.Shapes
+                                            'Ensure that "Edit across layers"
+                                            'is ON. Otherwise, selecting
+'            Set oScript = CorelScript       'across layers, followed by
+'            oScript.SetMultiLayer True      'grouping, can flatten all
+'            Set oScript = Nothing           'layers into one. 选中表示将对当前页面的所有对象与源对象进行匹配,否则只匹配当前图层的对象
+ 
+            'Replace the above with this line, CoreScript is not longer support X7+
+            ActiveDocument.EditAcrossLayers = True
+        End If
+        If WithinLayer Then
+            Set shpsToTest = ActivePage.ActiveLayer.Shapes
+        End If
+        
+        If WithinDoc Then '在当前文档查找,将当前页面相应的对象加入到待比较范围
+            
+            'Set p1 = ActivePage
+            For i = 1 To ActiveDocument.Pages.Count
+                ActiveDocument.Pages(i).Activate
+                Set pagesr = ActivePage.SelectShapesFromRectangle(0, 2480, 1820, 0, False).Shapes.All
+                docsr.AddRange pagesr '各页面依次查找,相应的对象加入到待比较范围
+                
+            Next i
+            Set shpsToTest = docsr.Shapes
+'            MsgBox "共有待比较对象 " & shpsToTest.Count & " 个"
+            Label13.Caption = "共有待比较对象 " & shpsToTest.Count & " 个"
+            'p1.Activate
+        End If
+        
+        If WithinGroups Then                'Check through flattened list.
+            Set clnSubShapes = FlatShapeList(shpsToTest)
+            '=======
+            For Each shpToMatch In clnSubShapes
+                If Not shpToMatch.Selected Then 'If the shape is not yet selected,
+                
+                   '====================     'check the models for a match.
+                    For Each shpModel In clnModelShapes
+                        If ShapesMatch(shpToMatch, shpModel, CheckFill, _
+                                CheckOutline, CheckOutlineColor, CheckOutlineLength, CheckSize, CheckWHratio, _
+                                CheckType, CountNodes, CountSegments, CountPaths, CheckIndiv) Then
+                            'shpToMatch.AddToSelection
+                            sr.Add shpToMatch
+                            Exit For        'If a match has now been found,
+                        End If              'we can skip any remaining models.
+                    Next
+                   '=====================
+                   
+                End If
+            Next
+            '=======
+        Else                                'Check through top-level list.
+            For Each shpToMatch In shpsToTest
+                If Not shpToMatch.Selected Then 'If the shape is not yet selected,
+                                            'check the models for a match.
+                    For Each shpModel In clnModelShapes
+                        If ShapesMatch(shpToMatch, shpModel, CheckFill, _
+                                CheckOutline, CheckOutlineColor, CheckOutlineLength, CheckSize, CheckWHratio, _
+                                CheckType, CountNodes, CountSegments, CountPaths, CheckIndiv) Then
+                            'shpToMatch.AddToSelection
+                            sr.Add shpToMatch
+                            Exit For        'If a match has now been found,
+                        End If              'we can skip any remaining models.
+                    Next
+                    
+                End If
+            Next
+        End If
+            
+        '===================================
+       ' TurnOptimizations cdrOptimizationOff
+        'CorelScript.RedrawScreen
+        '===================================
+        'sr.Add ActiveDocument.Selection
+        If CheckColorMark And sr.Count > 0 Then sr.SetOutlineProperties , , CreateCMYKColor(0, 100, 0, 0) '轮廓线上色
+        sr.AddRange shr
+        sr.CreateSelection
+'        MsgBox "共找到 " & sr.Count & " 个对象"
+        Label13.Caption = "共找到 " & sr.Count & " 个对象"
+    End If
+    
+    Set clnModelShapes = Nothing               'Release the memory allocated
+    Set shpsToTest = Nothing
+    Exit Sub
+NothingSelected:
+End Sub
+
+Private Function ShapesMatch(shpShape As Shape, shpModel As Shape, _
+                    Optional CheckFill As Boolean = True, _
+                    Optional CheckOutline As Boolean = True, _
+                    Optional CheckOutlineColor As Boolean = True, _
+                    Optional CheckOutlineLength As Boolean = True, _
+                    Optional CheckSize As Boolean = False, _
+                    Optional CheckWHratio As Boolean = False, _
+                    Optional CheckType As Boolean = True, _
+                    Optional CountNodes As Boolean = False, _
+                    Optional CountSegments As Boolean = False, _
+                    Optional CountPaths As Boolean = False, _
+                    Optional CheckIndiv As Boolean = False) As Boolean
+    
+    'Sizes "match" if they differ by less than one per cent
+    Dim ToleranceSize As Double     '面积大小允许波动
+    ToleranceSize = Me.TextBox1 / 100  '面积大小允许波动,以百分比为单位
+    
+    Dim ToleranceLength As Double   '线长允许波动
+    ToleranceLength = Me.TextBox2 / 100 '长度允许波动,以百分比为单位
+    
+    Dim ToleranceNodesCount As Long  '节点数量允许波动,以 点 单位
+    ToleranceNodesCount = Me.TextBox3 '节点数量允许波动,以 点 单位
+    
+    Dim ToleranceSubPathsCount As Long  '子路径 子线段 允许波动,以 条 为单位
+    ToleranceSubPathsCount = Me.TextBox4 '子路径 子线段 允许波动,以 条 为单位
+    
+    Dim ToleranceWHratio As Double  '长宽比 允许波动,以 百分比 为单位
+    ToleranceWHratio = Me.TextBox5  '长宽比 允许波动,以 百分比 为单位
+    
+    Dim ToleranceSegmentsCount As Long  '线段数 允许波动,以 个 为单位
+    ToleranceSegmentsCount = Me.TextBox6 '线段数 允许波动,以 个 为单位
+        
+    'Object Variables.        'Reference to:
+    Dim clrModel As Color           'color features of model shape,
+    Dim clrShape As Color           'color features of shape to be tested
+    Dim fillModel As Fill           'fill style of model shape,
+    Dim outlnModel As Outline       'outline style of model shape,
+    Dim crvModel As Curve           'Bezier curve of model shape,
+    Dim crvShape As Curve           'Bezier curve of shape to be tested,
+    Dim fntModel As StructFontProperties  'font properties of model text shape,
+    Dim trgModel As Text            'general text properties of model shape.
+    Dim spath As SubPath, opath As SubPath
+    Dim j As Integer
+    
+    'Simple Variables.              Storage of:
+    Dim dblWidth As Double              'width of a shape,
+    Dim dblHeight As Double             'height of a shape,
+    Dim lngShapeType As cdrShapeType    'code for type of shape to be tested,
+    Dim lngModelType As cdrShapeType    'code for the type of a model shape,
+    Dim lngType As Long                 'code for the type of a fill, color,
+                                        'or outline.
+                                        
+    
+                                        'Does the SHAPE match the MODEL ?
+                                        'Exit immediately on any mismatch.
+    With shpShape
+        lngShapeType = .Type            'Same basic TYPE of shape ?
+        lngModelType = shpModel.Type
+        
+        If CheckType Then If lngShapeType <> lngModelType Then GoTo NoMatch
+                                        'A GROUP ? delegate to GroupsMatch()
+'        If lngShapeType = cdrGroupShape Then
+'            ShapesMatch = GroupsMatch(shpShape, shpModel, CheckSize, _
+'                                CountNodes, CountPaths)
+'            Exit Function
+'        End If
+
+                                        'Does SIZE count ? Is so, are the
+        If CheckSize Then               'size differences significant ?
+            dblWidth = shpModel.SizeWidth
+            If Abs(.SizeWidth - dblWidth) > (dblWidth * _
+                 ToleranceSize) Then GoTo NoMatch
+            dblHeight = shpModel.SizeHeight
+            If Abs(.SizeHeight - dblHeight) > (dblHeight * _
+                ToleranceSize) Then GoTo NoMatch
+        End If
+        
+        If CheckWHratio Then               'size width and height ratio differences significant ?
+            dblWidth = shpModel.SizeWidth
+            dblHeight = shpModel.SizeHeight
+            If Abs(.SizeHeight / .SizeWidth - dblHeight / dblWidth) > (dblHeight / dblWidth * ToleranceWHratio) Then GoTo NoMatch
+        End If
+        
+
+            If CountNodes Or CountPaths Or CheckOutlineLength Or CountSegments Then
+                                        'Only Curves can match ...
+                If lngShapeType <> cdrCurveShape Then GoTo NoMatch
+                
+                Set crvShape = .Curve
+                Set crvModel = shpModel.Curve
+                
+                'If CheckIndiv Then '逐条子路径比较
+                    'If Abs(crvShape.SubPaths.Count - crvModel.SubPaths.Count) <> 0 Then GoTo NoMatch
+                    'For j = 1 To crvShape.SubPaths.Count
+                            'If Abs(crvShape.SubPath(j).Nodes.Count - crvModel.SubPath(j).Nodes.Count) > ToleranceNodesCount Then GoTo NoMatch
+                     
+                     'Next j
+                
+                If CountPaths Then      'Do the PATH counts match ?
+                    
+                    If VersionMajor > 12 Then 'GDG ##########################################
+                        If Abs(crvShape.SubPaths.Count - crvModel.SubPaths.Count) > ToleranceSubPathsCount Then GoTo NoMatch
+                        'MsgBox "subpaths1: " & crvShape.SubPaths.Count & "subpaths2: " & crvModel.SubPaths.Count
+                    Else
+                        If Abs(crvShape.SubPathCount - crvModel.SubPathCount) > ToleranceSubPathsCount Then GoTo NoMatch
+                    End If 'GDG #############################################################
+                    
+                End If
+                
+                
+                 
+                 
+                If CountNodes Then      'Do the NODE counts match ?
+                
+                    If VersionMajor > 12 Then 'GDG ##########################################
+                        If Abs(crvShape.Nodes.Count - crvModel.Nodes.Count) > ToleranceNodesCount Then GoTo NoMatch
+                    Else
+                        If Abs(crvShape.NodeCount - crvModel.NodeCount) > ToleranceNodesCount Then GoTo NoMatch
+                    End If 'GDG #############################################################
+                    
+                End If
+                
+                If CountSegments Then      'Do the Segments counts match ?
+                
+                    If VersionMajor > 12 Then 'GDG ##########################################
+                        If Abs(crvShape.Segments.Count - crvModel.Segments.Count) > ToleranceSegmentsCount Then GoTo NoMatch
+                    Else
+                        If Abs(crvShape.SegmentCount - crvModel.SegmentCount) > ToleranceSegmentsCount Then GoTo NoMatch
+                    End If 'GDG #############################################################
+                    
+                End If
+        
+                
+                
+                If CheckOutlineLength Then      'Do the curve length match ?
+                
+                    If VersionMajor > 12 Then 'GDG ##########################################
+                        If Abs(crvShape.Length - crvModel.Length) > crvModel.Length * ToleranceLength Then GoTo NoMatch
+                        'MsgBox "subpaths1: " & crvShape.SubPaths.Count & "subpaths2: " & crvModel.SubPaths.Count
+                    Else
+                        If Abs(crvShape.Length - crvModel.Length) > crvModel.Length * ToleranceLength Then GoTo NoMatch
+                    End If 'GDG #############################################################
+                    
+                End If
+            End If
+        If CheckFill Then
+            Set fillModel = shpModel.Fill
+            With .Fill                  'Is the FILL type the same ?
+                lngType = .Type
+                If lngType <> shpModel.Fill.Type Then GoTo NoMatch
+                If lngType = cdrUniformFill Then
+'Does the uniform fill match ?
+                    If VersionMajor > 12 Then 'GDG ##########################################
+                        'GDG ##########################################
+                        Dim col1 As New Color
+                        col1.CopyAssign .UniformColor
+                        Dim col2 As New Color
+                        col2.CopyAssign shpModel.Fill.UniformColor
+                        'GDG ##########################################
+                        If col1.IsSame(col2) = False Then GoTo NoMatch
+                    Else
+                        Set clrModel = fillModel.UniformColor
+                        lngType = .UniformColor.Type
+                        If lngType <> clrModel.Type Then GoTo NoMatch
+                        If .UniformColor.Name(True) <> clrModel.Name(True) Then GoTo NoMatch
+                    End If  'GDG #############################################################
+                End If
+            End With
+        End If
+        
+        
+        
+        If CheckOutline Then            '(Groups have no outline)
+            If lngShapeType <> cdrGroupShape Then
+                Set outlnModel = shpModel.Outline
+                If Not outlnModel Is Nothing Then
+                    With .Outline
+                        lngType = .Type
+                        If lngType <> outlnModel.Type Then GoTo NoMatch
+                                                
+                        If lngType > 0 Then     'Does the shape have an OUTLINE ?
+                                                'Same LINE WIDTH ?
+                            If .Width <> outlnModel.Width Then GoTo NoMatch
+                                                'Matching LINE COLOR ?
+'                            Set clrShape = .Color
+'                            lngType = clrShape.Type
+'                            Set clrModel = outlnModel.Color
+'                            If lngType <> clrModel.Type Then GoTo NoMatch
+'                            If clrShape.Name(True) <> clrModel.Name(True) Then GoTo NoMatch
+                        End If
+                    End With
+                End If
+            End If
+        End If
+        
+        
+        If CheckOutlineColor Then            '(Groups have no outline)
+            If lngShapeType <> cdrGroupShape Then
+ 
+               
+                Set outlnModel = shpModel.Outline
+                If Not outlnModel Is Nothing Then
+                    
+                    With .Outline
+                        lngType = .Type
+                        If lngType <> outlnModel.Type Then GoTo NoMatch
+                                                
+                        If lngType > 0 Then     'Does the shape have an OUTLINE ?
+                                                'Matching LINE COLOR ?
+                            
+                            If VersionMajor > 12 Then 'GDG ##########################################
+                                'GDG ##########################################
+                                Dim col3 As New Color
+                                col3.CopyAssign .Color
+                                Dim col4 As New Color
+                                col4.CopyAssign shpModel.Outline.Color
+                                'GDG ##########################################
+                                If col3.IsSame(col4) = False Then GoTo NoMatch
+                            Else
+                                Set clrShape = .Color
+                                lngType = clrShape.Type
+                                Set clrModel = outlnModel.Color
+                                If lngType <> clrModel.Type Then GoTo NoMatch
+                                If clrShape.Name(True) <> clrModel.Name(True) _
+                                    Then GoTo NoMatch
+                            End If
+                        End If
+                    End With
+                End If
+            End If
+        End If
+        
+    End With
+    
+    ShapesMatch = True
+    Exit Function
+    
+NoMatch:
+    ShapesMatch = False
+    
+NoMatchExit:
+    ShapesMatch = False
+    Exit Function
+End Function
+
+Private Function GroupsMatch(Group As Shape, GroupModel As Shape, _
+                    Optional CheckFill As Boolean = True, _
+                    Optional CheckOutline As Boolean = True, _
+                    Optional CheckOutlineColor As Boolean = True, _
+                    Optional CheckOutlineLength As Boolean = True, _
+                    Optional CheckSize As Boolean = False, _
+                    Optional CheckType As Boolean = True, _
+                    Optional CountNodes As Boolean = False, _
+                    Optional CountPaths As Boolean = False) As Boolean
+    
+    'Object Variables.              Reference to:
+    Dim shpsModels As Shapes            'shapes in the pre-selected group,
+    Dim shpsInGroup As Shapes           'shapes in the group to be tested,
+    Dim shpModel As Shape               'a shape in the pre-selected group,
+    Dim shpInGroup As Shape             'a shape in the group to be tested.
+    
+    'Simple Variables               Storage of:
+    Dim lngInGroup As Long              'number of shapes in a group,
+    Dim i As Long                       'a numeric index to a
+                                        'particular sub-group.
+                                        
+    'On Error GoTo NoMatch              'Shape & model must be groups.
+    Set shpsModels = GroupModel.Shapes
+    Set shpsInGroup = Group.Shapes
+    'On Error GoTo 0
+                                        'Same number of shapes
+    lngInGroup = shpsModels.Count       'in each group ?
+    If shpsInGroup.Count <> lngInGroup Then GoTo NoMatch
+        
+    For i = 1 To lngInGroup             'Try to Match all sub-shapes,
+        Set shpInGroup = shpsInGroup(i) 'and GroupsMatch all sub-groups.
+        Set shpModel = shpsModels(i)
+        
+        If shpModel.Type <> cdrGroupShape Then
+            If Not ShapesMatch(shpInGroup, shpModel, _
+                            CheckSize, CountNodes) Then GoTo NoMatch
+        Else
+            If Not GroupsMatch(shpInGroup, shpModel, _
+                            CheckSize, CountNodes) Then GoTo NoMatch
+        End If
+    Next i
+    
+    GroupsMatch = True
+    Exit Function
+NoMatch:
+    GroupsMatch = False
+End Function
+
+
+Private Function FlatShapeList(TopLevelShapes As Shapes) As Collection
+    
+    'Object Variables.          Reference to:
+    Dim shpTopLevel As Shape        'a top-level shape,
+    Dim shpInGroup As Shape         'a shape inside a group,
+    Dim clnAllShapes As Collection  'our list of all members and
+                                    'descendants of TopLevelShapes.
+                                       
+    If TopLevelShapes.Count Then
+        Set clnAllShapes = New Collection
+        For Each shpTopLevel In TopLevelShapes
+                                    'Add shape to list, keyed under
+                                    'a string version of its unique ID
+             clnAllShapes.Add shpTopLevel
+                                    'If the shape is a group, then
+                                    'also gather all its descendants
+                                    'and add them to the list.
+            If shpTopLevel.Type = cdrGroupShape Then
+                For Each shpInGroup In ShapesInGroup(shpTopLevel)
+               clnAllShapes.Add shpInGroup
+                Next
+            End If
+        Next
+        Set FlatShapeList = clnAllShapes  'Return the assembled collection.
+    Else
+        Set FlatShapeList = Nothing
+    End If
+End Function
+
+Private Function ShapesInGroup(GroupShape As Shape) As Collection
+
+    'Object Variables.              Reference to:
+    Dim shpsInGroup As Shapes           'the set of shapes inside a group,
+    Dim shpInGroup As Shape             'a particular shape in a group,
+    Dim shpNested As Shape              'a shape inside a sub-group,
+    Dim clnShapeList As Collection      'our list of all nested shapes.
+    
+    If GroupShape.Type = cdrGroupShape Then
+        Set shpsInGroup = GroupShape.Shapes 'Get a reference to the
+                                            'shapes in this group.
+        Set clnShapeList = New Collection
+        For Each shpInGroup In shpsInGroup
+            clnShapeList.Add shpInGroup     'Add all shapes in the group to
+                                            'our main collection.
+            If shpInGroup.Type = cdrGroupShape Then
+                                            'Recurse to get nested shapes.
+                For Each shpNested In ShapesInGroup(shpInGroup)
+                    clnShapeList.Add shpNested
+                Next
+            End If
+        Next
+        Set ShapesInGroup = clnShapeList    'Return the assembled collection.
+    Else
+        Set ShapesInGroup = Nothing         'Release the memory if the
+    End If                                  'collection is not needed
+End Function
+
+Private Sub Image2_Click()
+    frminfo.Show vbModeless
+End Sub
+
+Private Sub UserForm_Activate()
+    Const YES As String = "True"
+    Const NO As String = "False"
+   
+    Optpage = GetSetting(TOOLNAME, SECTION, "InPage", YES)
+    OptDoc = GetSetting(TOOLNAME, SECTION, "InDoc", NO)
+    Optlayer = GetSetting(TOOLNAME, SECTION, "InLayer", NO)
+    chkColorMark = GetSetting(TOOLNAME, SECTION, "ColorMark", YES)
+    chkFill = GetSetting(TOOLNAME, SECTION, "Fill", YES)
+    chkInGroups = GetSetting(TOOLNAME, SECTION, "InGroups", YES)
+    chkNodes = GetSetting(TOOLNAME, SECTION, "Nodes", NO)
+    chkSegments = GetSetting(TOOLNAME, SECTION, "Segments", NO)
+    chkOutline = GetSetting(TOOLNAME, SECTION, "Outline", YES)
+    chkOutlineColor = GetSetting(TOOLNAME, SECTION, "OutlineColor", NO)
+    chkOutlineLength = GetSetting(TOOLNAME, SECTION, "OutlineLength", YES)
+    chkPaths = GetSetting(TOOLNAME, SECTION, "Paths", NO)
+    chkSize = GetSetting(TOOLNAME, SECTION, "Size", NO)
+    chkWHratio = GetSetting(TOOLNAME, SECTION, "WHratio", NO)
+    chkType = GetSetting(TOOLNAME, SECTION, "Type", YES)
+    chkIndiv = GetSetting(TOOLNAME, SECTION, "Indiv", NO)
+    chkColorMark = GetSetting(TOOLNAME, SECTION, "ColorMark", NO)
+    saveFormPos False
+End Sub
+
+Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
+    saveFormPos True
+End Sub
+
+Sub saveFormPos(bDoSave As Boolean)
+    Dim dL, dT
+    If bDoSave Then 'save position
+         SaveSetting TOOLNAME, SECTION, "form_left", Me.Left
+         SaveSetting TOOLNAME, SECTION, "form_top", Me.Top
+    Else 'place instead.
+        dL = GetSetting(TOOLNAME, SECTION, "form_left", 900)
+        dT = GetSetting(TOOLNAME, SECTION, "form_top", 200)
+        Me.Left = dL: Me.Top = dT
+    End If
+End Sub
+
+Private Sub OptDoc_Click()
+    SaveSetting TOOLNAME, SECTION, "InDoc", CStr(OptDoc)
+End Sub
+Private Sub Optlayer_Click()
+    SaveSetting TOOLNAME, SECTION, "InLayer", CStr(Optlayer)
+End Sub
+Private Sub Optpage_Click()
+    SaveSetting TOOLNAME, SECTION, "InPage", CStr(Optpage)
+End Sub
+Private Sub chkColorMark_Click()
+    SaveSetting TOOLNAME, SECTION, "ColorMark", CStr(chkColorMark)
+End Sub
+Private Sub chkIndiv_Click()
+    SaveSetting TOOLNAME, SECTION, "Indiv", CStr(chkIndiv)
+End Sub
+Private Sub chkFill_Click()
+    SaveSetting TOOLNAME, SECTION, "Fill", CStr(chkFill)
+End Sub
+Private Sub chkInGroups_Click()
+    SaveSetting TOOLNAME, SECTION, "InGroups", CStr(chkInGroups)
+End Sub
+Private Sub chkNodes_Click()
+    SaveSetting TOOLNAME, SECTION, "Nodes", CStr(chkNodes)
+End Sub
+Private Sub chkSegments_Click()
+    SaveSetting TOOLNAME, SECTION, "Segments", CStr(chkSegments)
+End Sub
+Private Sub chkOutline_Click()
+    SaveSetting TOOLNAME, SECTION, "Outline", CStr(chkOutline)
+End Sub
+Private Sub chkOutlineColor_Click()
+    SaveSetting TOOLNAME, SECTION, "OutlineColor", CStr(chkOutlineColor)
+End Sub
+Private Sub chkPaths_Click()
+    SaveSetting TOOLNAME, SECTION, "Paths", CStr(chkPaths)
+End Sub
+Private Sub chkSize_Click()
+    SaveSetting TOOLNAME, SECTION, "Size", CStr(chkSize)
+End Sub
+Private Sub chkWHratio_Click()
+    SaveSetting TOOLNAME, SECTION, "WHratio", CStr(chkWHratio)
+End Sub
+Private Sub chkType_Click()
+    SaveSetting TOOLNAME, SECTION, "Type", CStr(chkType)
+End Sub
+Private Sub chkOutLineLength_Click()
+    SaveSetting TOOLNAME, SECTION, "OutlineLength", CStr(chkOutlineLength)
+End Sub
+Sub beg()
+    ActiveDocument.Unit = cdrMillimeter
+    ActiveDocument.BeginCommandGroup "aa"
+    Optimization = True
+End Sub
+Sub EndOpt()
+    Optimization = False
+    ActiveDocument.EndCommandGroup
+    ActiveWindow.Refresh
+    Application.Refresh
+End Sub
+

+ 114 - 0
module/AutoCutLines.bas

@@ -0,0 +1,114 @@
+Attribute VB_Name = "AutoCutLines"
+#If VBA7 Then
+  Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
+#Else
+  Private Declare Sub Sleep Lib "kernel32" (ByValdwMilliseconds As Long)
+#End If
+
+Public Sub AutoCutLines()
+  Nodes_TO_TSP
+  START_Cut_Line_Algorithm 3#
+  
+  '延时500毫秒,如果电脑够快,可以调整到100ms
+  Sleep 500
+  TSP_TO_DRAW_LINES
+End Sub
+
+Private Function Nodes_TO_TSP()
+  On Error GoTo ErrorHandler
+  API.BeginOpt "Nodes_TO_TSP"
+  
+  Set fs = CreateObject("Scripting.FileSystemObject")
+  Set f = fs.CreateTextFile("C:\TSP\CDR_TO_TSP", True)
+
+  Dim s As Shape, ssr As ShapeRange
+  Set ssr = ActiveSelectionRange
+
+  Dim TSP As String
+  TSP = (ssr.Count * 4) & " " & 0 & vbNewLine
+
+  For Each s In ssr
+      lx = s.LeftX:   rx = s.RightX
+      By = s.BottomY: ty = s.TopY
+      TSP = TSP & lx & " " & By & vbNewLine
+      TSP = TSP & lx & " " & ty & vbNewLine
+      TSP = TSP & rx & " " & By & vbNewLine
+      TSP = TSP & rx & " " & ty & vbNewLine
+  Next s
+  f.WriteLine TSP
+  f.Close
+  
+  '// 刷新一下文件流,延时的效果
+  Set f = fs.OpenTextFile("C:\TSP\CDR_TO_TSP", 1, False)
+  Dim str
+  str = f.ReadAll()
+  f.Close
+  
+  API.EndOpt
+Exit Function
+ErrorHandler:
+    Application.Optimization = False
+    On Error Resume Next
+End Function
+
+'//  TSP功能画线-多线段
+Private Function TSP_TO_DRAW_LINES()
+  On Error GoTo ErrorHandler
+  API.BeginOpt "TSP_TO_DRAW_LINES"
+  
+  Set fs = CreateObject("Scripting.FileSystemObject")
+  Set f = fs.OpenTextFile("C:\TSP\TSP2.txt", 1, False)
+  Dim str, arr, n
+  Dim line As Shape
+  str = f.ReadAll()
+  f.Close
+  Set f = fs.OpenTextFile("C:\TSP\TSP2.txt", 1, False)
+  str = f.ReadAll()
+  
+  str = VBA.Replace(str, vbNewLine, " ")
+  Do While InStr(str, "  ")
+    str = VBA.Replace(str, "  ", " ")
+  Loop
+  
+  arr = Split(str)
+  For n = 2 To UBound(arr) - 1 Step 4
+    x = Val(arr(n))
+    Y = Val(arr(n + 1))
+    x1 = Val(arr(n + 2))
+    y1 = Val(arr(n + 3))
+
+    Set line = ActiveLayer.CreateLineSegment(x, Y, x1, y1)
+    set_line_color line
+    
+    ' 调试线条顺序
+    puts x, Y, (n + 2) / 4
+    
+  Next
+  
+  ActivePage.Shapes.FindShapes(Query:="@colors.find(RGB(26, 22, 35))").CreateSelection
+  ActiveSelection.Group
+  ActiveSelection.Outline.SetProperties 0.2, Color:=CreateCMYKColor(0, 100, 100, 0)
+  
+  API.EndOpt
+Exit Function
+ErrorHandler:
+    Application.Optimization = False
+    On Error Resume Next
+End Function
+
+'// 运行裁切线算法 Cut_Line_Algorithm.py
+Private Function START_Cut_Line_Algorithm(Optional ext As Double = 3)
+    cmd_line = "python C:\TSP\Cut_Line_Algorithm.py" & " " & ext
+    Shell cmd_line
+End Function
+
+'// 设置线条标记(颜色)
+Private Function set_line_color(line As Shape)
+  line.Outline.SetProperties Color:=CreateRGBColor(26, 22, 35)
+End Function
+
+Public Sub puts(x, Y, n)
+  Dim st As String
+  st = str(n)
+  Set s = ActiveLayer.CreateArtisticText(x, Y, st)
+End Sub

+ 189 - 0
module/Container.bas

@@ -0,0 +1,189 @@
+Attribute VB_Name = "Container"
+' ① 标记容器盒子
+Public Function SetBoxName()
+  API.BeginOpt "标记容器盒子"
+  
+  Dim box As ShapeRange, s As Shape
+  Set box = ActiveSelectionRange
+  
+  ' 设置物件名字,以供CQL查询
+  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) ' 智能群组容差 0.5mm
+  
+  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
+  ' CQL查找容器盒物件
+  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
+
+' 图片OneKey置入容器
+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) ' 智能群组容差 0.5mm
+  
+  Application.Optimization = True
+  For Each s In ssr
+    Image_ToPowerClip s
+  Next s
+
+  API.EndOpt
+End Sub
+
+' ② 删除容器盒子边界外面的物件    ③④
+Public Function Remove_OutsideBox()
+  Dim s As Shape
+  Dim ssr As ShapeRange, box As ShapeRange
+  Dim rmsr As New ShapeRange
+  Dim x As Double, Y As Double
+  
+  Set ssr = ActiveSelectionRange
+  ' CQL查找容器盒物件
+  Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
+  ssr.RemoveRange box
+  
+  If box.Count = 0 Then Exit Function
+  
+  ActiveDocument.Unit = cdrMillimeter
+  For Each s In ssr
+    x = s.CenterX: Y = s.CenterY
+    If box(1).IsOnShape(x, Y) = cdrOutsideShape Then rmsr.Add s
+  Next s
+
+  rmsr.Delete
+End Function
+
+
+Public Function Remove_OnMargin()
+  Dim s As Shape
+  Dim ssr As ShapeRange, box As ShapeRange
+  Dim rmsr As New ShapeRange
+  Dim x As Double, Y As Double
+  
+  Set ssr = ActiveSelectionRange
+  ' CQL查找容器盒物件
+  Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
+  ssr.RemoveRange box
+  
+  If box.Count = 0 Then Exit Function
+  
+  ActiveDocument.Unit = cdrMillimeter
+  For Each s In ssr
+    x = s.CenterX: Y = s.CenterY
+    If box(1).IsOnShape(x, Y) = cdrOnMarginOfShape Then rmsr.Add s
+  Next s
+
+  rmsr.Delete
+End Function
+
+
+Public Function Select_OutsideBox()
+  Dim s As Shape
+  Dim ssr As ShapeRange, box As ShapeRange
+  Dim SelSr As New ShapeRange
+  Dim x As Double, Y As Double, radius
+  
+  Set ssr = ActiveSelectionRange
+  ' CQL查找容器盒物件
+  Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
+  ssr.RemoveRange box
+  
+  If box.Count = 0 Then Exit Function
+  
+  ActiveDocument.Unit = cdrMillimeter
+  For Each s In ssr
+    x = s.CenterX: Y = s.CenterY
+    radius = s.SizeWidth / 2
+    If box(1).IsOnShape(x, Y, radius) = cdrOutsideShape Then SelSr.Add s
+  Next s
+  
+  ActiveDocument.ClearSelection
+  SelSr.AddToSelection
+
+End Function
+
+
+Public Function Select_OnMargin()
+  Dim s As Shape
+  Dim ssr As ShapeRange, box As ShapeRange
+  Dim SelSr As New ShapeRange
+  Dim x As Double, Y As Double, radius
+  
+  Set ssr = ActiveSelectionRange
+  ' CQL查找容器盒物件
+  Set box = ssr.Shapes.FindShapes(Query:="@name ='Container'")
+  ssr.RemoveRange box
+  
+  If box.Count = 0 Then Exit Function
+  
+  ActiveDocument.Unit = cdrMillimeter
+  For Each s In ssr
+    x = s.CenterX: Y = s.CenterY
+    radius = s.SizeWidth / 2
+    If box(1).IsOnShape(x, Y, radius) = cdrOnMarginOfShape Then SelSr.Add s
+  Next s
+  
+  ActiveDocument.ClearSelection
+  SelSr.AddToSelection
+
+End Function
+
+
+' 这个子程序遍历对象,调用解散物件和居中
+Public Sub Batch_Center()
+    Dim s As Shape, ssr As ShapeRange
+    Set ssr = Smart_Group
+    For Each s In ssr
+      Ungroup_Center s
+    Next s
+End Sub
+
+
+' 以下函数,解散物件,以面积排序居中
+Private Function Ungroup_Center(os As Shape)
+    Set grp = os.UngroupEx
+    grp.Sort "@shape1.Width * @shape1.Height> @shape2.Width * @shape2.Height"
+    cx = grp(1).CenterX
+    cy = grp(1).CenterY
+    For Each s In grp
+      s.CenterX = cx
+      s.CenterY = cy
+    Next s
+End Function
+