CQL
An additional set of VBA commands were added to Corel in version X3. These commands are known as
CQL.
I have come to the conclusion that CorelDraw VBA users should upgrade to at least X3 to take advantage
of Corel CQL.
CQL has immense power.
It enables you to find shapes with particular attributes, whether they be within groups or not, and
create collections of these shapes.
With the collection you can then change every member of the collection. For example you can change
every shape, in a document, with a particular color to another color.
Without CQL you have to write code to search within each group and sub groups.
You have to anticipate how many sub groups there many be in the document.
CQL does not require you know how many sub groups there are. CQL just finds them.
Below are two examples of the use of CQL code. The CQL code contains the line
.FindShapes(query:="@fill.type = 'Uniform' and @fill.color.PaletteIndex = '67'")
The use of single & double quotation marks are messy but they are important. Notice that 2
criteria must be met in this example.
eg The fill must be Uniform and the color must be 67.
The code could have been rewritten to search for color 67 or color 85. Such as
.FindShapes(query:="@fill.color.PaletteIndex = '67' or @fill.color.PaletteIndex = '85'")
Alternatively as many criteria can be included in the search criteria as necessary even only
one.
Color numbers refer to particular colors.
No 67 is Pantone 130, 85 is Pantone 141 while 267 is Pantone 2563.
For an understanding of this see Pantone Colors.
Example 1: Look through page 1 of a document convert all shapes with a uniform color and a color
index 67 to index 267.
Dim DOC_PAGE As Page
Dim SHAPE_RANGE As ShapeRange
Dim SHAPEE As Shape
Set DOC_PAGE = ThisDocument.Pages(1)
'Create a shape range of every shape on Page 1 that satisfies the search conditions.
Set SHAPE_RANGE = DOC_PAGE.Shapes.FindShapes(query:="@fill.type = 'Uniform' and
@fill.color.PaletteIndex = '67'")
For Each SHAPEE In SHAPE_RANGE
SHAPEE.Fill.UniformColor.FixedAssign cdrPANTONECoated, 267,
100
Next SHAPEE
Example 2: Here is the same thing again but it searches every page in the document and changes the
color.
Dim DOC_PAGE As Page
Dim SHAPE_RANGE As ShapeRange
Dim SHAPEE As Shape
For Each DOC_PAGE In ThisDocument.Pages
'Create a shape range of every shape on the Master Page that
satisfies the search conditions.
Set SHAPE_RANGE = DOC_PAGE.Shapes.FindShapes(query:="@fill.type =
'Uniform' and @fill.color.PaletteIndex = '67'")
For Each SHAPEE In SHAPE_RANGE
SHAPEE.Fill.UniformColor.FixedAssign
cdrPANTONECoated, 267, 100
Next SHAPEE
Next DOC_PAGE
Example 3: In this example you search for every ellipse on the active page but the ellipses must
have the same width as height making them circles.
The circles must also have uniform fill and have color index No 5 (Pantone Red 032).
Dim SR As ShapeRange
Set SR = ActivePage.Shapes.FindShapes _
(query:="@Type='Ellipse' And @Height = @Width and @fill.type = 'Uniform' and
@fill.color.PaletteIndex = '5'")
This page is in the process of being written.
|