Delete Segment Macro

Hello folks

Does anyone of you have a good macro at hand with which I can delete segments with a mouse click?

Thanks in advance.

  • Hello!
    I can write such a macro.
    Email me at tv.softlv@gmail.com if you are really interested.
    Best regards.
    Taras

  • I have written a Delete Segment Macro, which I share with you. 

    Sub DeleteSegment()
        Dim x As Double, y As Double
        Dim nr As NodeRange
        Dim clickedShape As shape
        Dim clickedSegment As shape
        Dim seg As Segment
        Dim newnr As New NodeRange
        Dim delNod1 As node
        
        Dim shapeType As String
    
        ' Loop until user clicks on a shape
        While True
            'On Error GoTo ErrorHandler ' ** Note: remove the ' sign before ON if you need the error handler **
            ' Get user click coordinates
            If ActiveDocument.GetUserClick(x, y, 0, 10, False, cdrCursorSmallcrosshair) Then Exit Sub
            
            ' Select shapes at the clicked position
            Set clickedShape = ActivePage.SelectShapesAtPoint(x, y, False).Shapes.Last
                If clickedShape.Type = cdrNoShape _
                    Or clickedShape.Type = cdrBitmapShape Or clickedShape.Type = cdrGroupShape Or clickedShape.Type = cdrSelectionShape Or clickedShape.Type = cdrGuidelineShape Or clickedShape.Type = cdrBlendGroupShape _
                    Or clickedShape.Type = cdrExtrudeGroupShape Or clickedShape.Type = cdrOLEObjectShape Or clickedShape.Type = cdrContourGroupShape Or clickedShape.Type = cdrLinearDimensionShape Or clickedShape.Type = cdrBevelGroupShape _
                    Or clickedShape.Type = cdrDropShadowGroupShape Or clickedShape.Type = cdr3DObjectShape Or clickedShape.Type = cdrArtisticMediaGroupShape Or clickedShape.Type = cdrConnectorShape Or clickedShape.Type = cdrMeshFillShape _
                    Or clickedShape.Type = cdrCustomShape Or clickedShape.Type = cdrCustomEffectGroupShape Or clickedShape.Type = cdrSymbolShape Or clickedShape.Type = cdrHTMLFormObjectShape _
                    Or clickedShape.Type = cdrHTMLActiveObjectShape Or clickedShape.Type = cdrPerfectShape Or clickedShape.Type = cdrEPSShape Then
                    
                                Select Case clickedShape.Type
                        
                                Case cdrNoShape:                                shapeType = "No Shape"
                                Case cdrBitmapShape:                            shapeType = "Bitmap"
                                Case cdrTextShape:                              shapeType = "Text"
                                Case cdrGroupShape:                             shapeType = "Group"
                                Case cdrSelectionShape:                         shapeType = "Selection"
                                Case cdrGuidelineShape:                         shapeType = "Guideline"
                                Case cdrBlendGroupShape:                        shapeType = "Blend Group"
                                Case cdrExtrudeGroupShape:                      shapeType = "Extrude Group"
                                Case cdrOLEObjectShape:                         shapeType = "Ole Object"
                                Case cdrContourGroupShape:                      shapeType = "Contour Group"
                                Case cdrLinearDimensionShape:                   shapeType = "Linear Dimension"
                                Case cdrBevelGroupShape:                        shapeType = "Bevel Group"
                                Case cdrDropShadowGroupShape:                   shapeType = "Drop-Shadow Group"
                                Case cdr3DObjectShape:                          shapeType = "3d Object"
                                Case cdrArtisticMediaGroupShape:                shapeType = "Artistic-Media Group"
                                Case cdrConnectorShape:                         shapeType = "Connector"
                                Case cdrMeshFillShape:                          shapeType = "Mesh Fill"
                                Case cdrCustomShape:                            shapeType = "Custom Shape"
                                Case cdrCustomEffectGroupShape:                 shapeType = "Custom-Effect Group"
                                Case cdrSymbolShape:                            shapeType = "Symbol"
                                Case cdrHTMLFormObjectShape:                    shapeType = "HTML Form Object"
                                Case cdrHTMLActiveObjectShape:                  shapeType = "HTML Active Object"
                                Case cdrPerfectShape:                           shapeType = "Perfect Shape"
                                Case cdrEPSShape:                               shapeType = "EPS"
                            
                            End Select
                    
                    MsgBox "This Macro does not work with " & shapeType & "s!"
                    GoTo CleanUp
                Else
                    If clickedShape.Type <> cdrRectangleShape Or clickedShape.Type <> cdrEllipseShape Or clickedShape.Type <> cdrCurveShape Or clickedShape.Type <> cdrPolygonShape Or clickedShape.Type <> cdrTextShape Then
                            ' Check if a shape was found
                                    If Not clickedShape Is Nothing Then
                                        ActiveDocument.BeginCommandGroup "Delete Segment V2"
                                        ' Convert clicked shape to Curves
                                        clickedShape.ConvertToCurves
                                        Set seg = clickedShape.Curve.FindClosestSegment(x, y, 0.5)
                                        Set delNod1 = seg.StartNode
                                        newnr.Add delNod1
                                        newnr.BreakApart
                                        newnr.Delete
                                    End If
                                        ActiveWindow.Refresh
                                        ActiveDocument.EndCommandGroup
                                Exit Sub
                    Exit Sub
                    End If
                End If
        Wend
        
    CleanUp:
        ActiveDocument.EndCommandGroup
        ActiveWindow.Refresh
        Exit Sub
    
    ErrorHandler:
        MsgBox "An error occurred: " & Err.Description & _
               " in line: " & Erl & _
               " (Error " & Err.Number & ")", vbCritical, "Error"
        Resume CleanUp
    End Sub