ANyone been around here long enough to remember CCCFER (Create Closed Curves From Enclosed Regions)??
Well all the tools exist in CorelCraw , have done for a while but I've never found a way to automate it, I keep trying and thought I'd give it another go with the help of CoPilot. HAH, completely useless.
So, the premise. I have a bunch of lines and curves all with an outline. I have a background rectangle the encloses them all. I want to turn the enclosed regions into fillable objects. Currently I use Tracev12 for this by exporting as a mono bitmap and trace outline with max details. Works well, however Trace v12 is unreliable on Win11 so I'm looking to the future and seeing if I can do something that works as quickly within Draw. For info, the export,trace,import takes less than a minute.
SO my procedure is
Create 3 new layers, one for the trace and two for the trace background (one black fill one white as the trimming object)
Copy all the curves to the trace layer and turn of visibility of the original layer 1
Copy/create the trimming object to white background layer, copy the black background to the black background layer.
Select all on Trace layer, Break Apart to remove master clone relationships
Remove all Symbol instances by converting them to regular objects
Group everything, then ungroup All to remove nested layers.
Then convert all outlines to Object on Trace layer
So far so good. The problem comes when I try and weld all these objects together. I tried combining first then welding to self like I would if doing it manually. I tried using the VB command Simplify but that gave errors too. Do I need to iteratively weld each curve to the next singularly? I enlisted the help of CoPilot but each suggestion was riddled with different errors, even errors that were the subject of a previous request. It appears there are problems with the VBA coding of Weld and Simplify, what do I need to be aware of when using weld in Draw2018? Are the issues resolved in later Draw versions?And the bit I haven't got to yet is how I do Front Minus Back on the traced objects using the white rectangle as the trimmer?
I will post my VB attempt, but I need to go and tidy it up after CoPilot sent me down the wrong path. Rename the file to .cdr to use it.
TIA
Hywel Harris
TraceTest-LayersCreated1.zip
If I had a better understanding of what you're trying to accomplish maybe I could help. Maybe a sample in in the form of snip-its here. Lines and curves are "outlines", you have a "line" with outline? Enclosed regions?
Thanks Myron. The file I'm working on as a test file shows the lineart. All are curves with an non-zero outline. My aim is to convert all to outlines and weld them all together, then trim with the white rectangle. That will leave me with a file like the attached. Easy enough to do manually, but it wont work programmatically.
Here all the 'holes' have been converted to enclosed fullable objects, and the original lineart remains on Layer1.
TraceTest-CompletedConversion .zip
I'm using X7 here but have 20 at home. Try making a pdf. I can should be able to make heads or tails with it.
Here's a PDF of the completed conversion. Not sure all the layers will be set correctly though. The original lineart is on Layer 1, I copy these without the white and black rectangles to the Trace layer then let the macro do its thing. This is the macro I'm using, but it always fails with errors on the final Weld command. I guess I'm using the command incorrectlyThis code works fine up to the weld command (bear in mind I start with a slightly different file and previous subs create the layers, copy the artwork, remove symbols, check for underlying duplicates etc etc, they all work fine leaving me with the file in my fisrt post)Sub CleanAndWeld() Dim s, s1 As Shape Dim sr1, tempSR As ShapeRange Dim curves As New ShapeRange Dim welded As New Shape Set sr1 = ActivePage.Layers("Trace").Shapes.All '----------------------------------------- ' 1. Break them apart (remove clones, etc.) '----------------------------------------- Set tempSR = sr1.BreakApartEx '----------------------------------------- ' 2. Group then UngroupAll (remove nested groups) '----------------------------------------- Dim grp As Shape Set grp = tempSR.Group Set tempSR = grp.UngroupAllEx '----------------------------------------- ' 3. Convert all outlines to objects '----------------------------------------- tempSR.ConvertOutlineToObject Set tempSR = ActivePage.Layers("Trace").Shapes.All Set s = tempSR.Combine Set s1 = s.Weld(welded, False, True) End Sub
PDF
See if this gets you there. I would keep what you have and just add this to the module to test.
Sub WeldAllLineShapes() Dim sh As ShapeRange Dim sf As Shape Dim i As Integer
' Get selected shapes Set sh = ActiveSelectionRange
If sh.Count = 0 Then MsgBox "No shapes selected." Exit Sub End If Optimization = True ActiveDocument.BeginCommandGroup "WeldAllShapes"
' Convert outlines to objects sh.Shapes.All.ConvertOutlineToObject
' Refresh selection after conversion Set sh = ActiveSelectionRange
If sh.Count < 2 Then ' Only one shape left after conversion Exit Sub End If
' Start with the first shape Set sf = sh(1)
' Weld each subsequent shape into the first For i = 2 To sh.Count Set sf = sf.Weld(sh(i), False, True) sh(i).Delete Next i
ActiveDocument.EndCommandGroup Optimization = False: RefreshEnd Sub