Hi folks,
In my work we make use of a fair number of symbol objects. Once we've completed a design we create production-ready artwork where the symbols need to be converted to regular shapes.
The problem I'm having is that when I try to do this with my script (below) in Coreldraw X8 I'm definitely not getting the desired result.
With my sample script I would create a symbol made up of 3 random rectangles. I would select the symbol and run the script.
What I expect to happen is that the script would duplicate the selected items, moving it over 20 units (to preserve the original artwork) and on the duplicate item would revert all symbols to shapes.
When I run the actual script I get weirdness that I can't pin down. At first blush it looks like I have a symbol and a duplicate of shapes, but on closer examination that isn't all I have.
The duplicate shape instead consists of 3 copies of the original symbol. Two of the copies are all separate rectangles and the third shape is now part of the original symbol.
I'm stumped, so I'm hoping that someone else might have some feedback!
Sub ShaperangeWithSymbol() ' This will give a break-down of what happens to our ShapeRange when a symbol is converted to objects ' If there is no selection then we can stop the process right now Dim sr As ShapeRange Dim workRange As ShapeRange Dim symbolRange As ShapeRange Dim s As Shape ' Set the range from the current selection Set sr = ActiveSelectionRange.Shapes.FindShapes.All ' Make a copy so that we do not work on the original artwork Set workRange = sr.Duplicate(20).UngroupAllEx If (sr.count < 1) Then MsgBox ("Please select at least one shape.") Exit Sub End If ' Find all the symbols in our duplicate range and convert them to objects Set symbolRange = workRange.Shapes.FindShapes(Query:="@type = 'symbol'") For Each s In symbolRange If (s.Type = cdrSymbolShape) Then s.Symbol.RevertToShapes End If Next s End Sub
Jeff said:What I expect to happen is that the script would duplicate the selected items, moving it over 20 units (to preserve the original artwork) and on the duplicate item would revert all symbols to shapes.
To do what you describe, here is how I might approach it:
Sub dupe_sr_revert_symbols() Dim sr As ShapeRange Dim srWorking As ShapeRange Dim srSymbols As ShapeRange Dim s As Shape Set sr = ActiveSelectionRange If sr.Count > 1 Then Set srWorking = sr.Duplicate(20) Set srSymbols = srWorking.Shapes.FindShapes(, cdrSymbolShape) For Each s In srSymbols s.Symbol.RevertToShapes Next s Else MsgBox "Nothing is selected." End If End Sub
I had to modify the "Set sr = ActiveSelectionRange" to "Set sr = ActiveSelectionRange.Shapes.FindShapes.All", otherwise sr returns a count of zero.
Unfortunately on my file this gives me the same result as my original script. Thanks, though!
Are your symbols in groups?
Full disclosure: I don't have a lot of experience with symbols and how they work with FindShapes queries.
Symbols seem to make my life both infinitely easier and more difficult at the same time.
This seems to work for me (ungrouping all after duplicating the shaperange).
Sub dupe_sr_revert_symbols() Dim sr As ShapeRange Dim srWorking As ShapeRange Dim srSymbols As ShapeRange Dim s As Shape Set sr = ActiveSelectionRange If sr.Count > 1 Then Set srWorking = sr.Duplicate(20).UngroupAllEx Set srSymbols = srWorking.Shapes.FindShapes(query:="@type='symbol'") For Each s In srSymbols s.Symbol.RevertToShapes Next s Else MsgBox "Nothing is selected." End If End Sub
I am accustomed to FindShapes drilling down into groups recursively, so it didn't occur to me at first to ungroup anything. I've never tried doing that to find symbols before.
Perhaps I'm getting more education here than I bargained for!