cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline bitmap trace?

Hello esteemed CDR &CorelDESIGNER API Members,
                                                                                        and thanks for such excellent programming, scripts and productive support.

1) I hoped you might please advise how to use cdrTraceType cdrTraceLineDrawing which FAILS, only producing a single linear path instead of CENTERLINE trace?

When using cdrTraceLineArt the same macros below WORK, producing vectorized OUTLINE paths from bitmap textures:
(please feel free to forward this to anyone who may instruct remedy. Thanks for any help, Jeff)

(2) Bitmap Trace via With(reference) to ActivePage Shapes:
Sub TraceActivePage()
        Dim s As Shape, sr As ShapeRange, p As Page
        For Each p In ActiveDocument.Pages
               p.Activate
              Set sr = ActivePage.Shapes.FindShapes(, cdrBitmapShape)
              Set s = ActiveShape
              For Each s In sr
                     With s.Bitmap.Trace(cdrTraceLineDrawing, 25, 100, cdrColorBlackAndWhite, cdrUniform, , True, True, True)
                    .Finish
                     End With
              Next s
        Next p
End Sub


(1) Bitmap Trace via Set(parameter) TraceSettings:
Sub TraceSettings()
Dim s As Shape, sr As ShapeRange
Dim t As TraceSettings
For Each s In ActivePage.FindShapes(, cdrBitmapShape)
       Set t = s.Bitmap.Trace(cdrTraceLineDrawing, 25, 100, cdrColorBlackAndWhite, cdrUniform, , True, True, True)
       t.Finish
       Next s
       Set t = Nothing
       Set s = Nothing
End Sub

Parents Reply
  • Phew, getting this to work has been quite tough (and took nearly two hours), but it feels like I have what you wanted above.

    First of all, as always, Shelby has come through by having answered an important question about color conversion to a specific palette. 

    After that I could modify the current macro to trace the image and then change the colors to a custom palette. It looks like this:

    Sub TraceActivePage()
        Dim BitmapToTrace As Shape, ShapesOnPage As ShapeRange, CurrentPage As Page
        
        Dim OurCustomPalette As Palette
        Dim ColorCode As Long, TempShape As Shape
        
        Set OurCustomPalette = ActiveDocument.Palette
        
        For Each CurrentPage In ActiveDocument.Pages
            CurrentPage.Activate
            Set ShapesOnPage = ActivePage.Shapes.FindShapes(, cdrBitmapShape)
            
            For Each BitmapToTrace In ShapesOnPage
                With BitmapToTrace.Bitmap.Trace(cdrTraceClipart, 10 * 2.55, 45 * 2.55, cdrColorRGB, , 256, False, , False)
                    .Finish
                End With
                
                If Not ActiveSelectionRange Is Nothing Then
                    ActiveSelectionRange.Group.UngroupAll
                End If
                
                Set ShapesOnPage = ActiveSelectionRange
                
                For Each TempShape In ShapesOnPage
                    ColorCode = OurCustomPalette.MatchColor(TempShape.Fill.UniformColor)
                    TempShape.Fill.ApplyUniformFill OurCustomPalette.Color(ColorCode)
                Next TempShape
                
                BitmapToTrace.Delete
            Next BitmapToTrace
        Next CurrentPage
    End Sub
    

    And to give you a better idea on usage I created a video: https://vimeo.com/501373471

    While recording the video I had a CorelDRAW crash 13 times. There is something it does not like when the sequence of actions is not correct. So make sure you follow this exactly.

    If this is what you wanted let me know and optimizations can be added so it happens basically instantly without all that selection blinking, etc.

    The code is far from perfect, but it seems to do what you wanted, so hopefully that helps.

Children