I am trying to figure out how to find if there are any spot colors in the CDR file using CQL
I am able to find Fountains by during thisActivePage.Shapes.FindShapes(Query:="@fill.type = 'fountain'")
But how do I write the query to see if there are any spot colors, pantones, cmyk, rgb, lab, etc.So tried this and it does not workActivePage.Shapes.FindShapes(Query:="@colors.find('cmyk')")Any ideas?
Thanks ,
Tom
I have an idea or two. :-) If you want to find Spot Colors you can do something like this:
Sub FindSpotColors() Dim srSpotFill As ShapeRange Dim srSpotOutline As ShapeRange Set srSpotFill = ActivePage.Shapes.FindShapes(Query:="@fill.color.IsSpot = true") Set srSpotOutline = ActivePage.Shapes.FindShapes(Query:="@outline.color.IsSpot = true") MsgBox "Fill: " & srSpotFill.Count & " Outline: " & srSpotOutline.Count End Sub
Or you could combine them like this:
Sub FindSpotColors2() Dim srSpot As ShapeRange Set srSpot = ActivePage.Shapes.FindShapes(Query:="@fill.color.IsSpot = true or @outline.color.IsSpot = true") MsgBox srSpot.Count End Sub
You can also do the same for CMYK as there is a IsCMYK:
Sub FindCMYKColors() Dim srCMYK As ShapeRange Set srCMYK = ActivePage.Shapes.FindShapes(Query:="@fill.color.IsCMYK = true or @outline.color.IsCMYK = true") MsgBox srCMYK.Count End Sub
There is no IsRGB or IsLAB so you will want to use the color.type to find these, which of course will also still work for Spot and CMYK:
Sub FindColorsByType() Dim srSpot As ShapeRange, srPantoneHex As ShapeRange Dim srCMYK As ShapeRange, srLAB As ShapeRange Set srSpot = ActivePage.Shapes.FindShapes(Query:="@fill.color.type = 'spot' or @outline.color.type = 'spot'") Set srPantoneHex = ActivePage.Shapes.FindShapes(Query:="@fill.color.type = 'pantone hex' or @outline.color.type = 'pantone hex'") Set srCMYK = ActivePage.Shapes.FindShapes(Query:="@fill.color.type = 'cmyk' or @outline.color.type = 'cmyk'") Set srLAB = ActivePage.Shapes.FindShapes(Query:="@fill.color.type = 'lab' or @outline.color.type = 'lab'") MsgBox "Spot: " & srSpot.Count & vbNewLine & _ "Pantone Hex: " & srPantoneHex.Count & vbNewLine & _ "CMYK: " & srCMYK.Count & vbNewLine & _ "LAB: " & srLAB.Count End Sub
Pantone are tricky as sometimes they will be spot, pantone hex, etc... If you want to see what CQL reports the color type as you can select your shape and type this into the immediate window:
?ActiveShape.Evaluate("@fill.color.type")
You should get a result like this:
lab
Or if you really want to get crazy. Draw several shapes, fill them with different color types, GROUP them, make sure the new group is selected and type this into the immediate window:
?ActiveShape.Evaluate("@children.foreach(array(), $lasteval.addarray($item.colors)).unique.convert($item.type).join(',')")
pantone hex,cmyk,lab,spot,spot
Hope that helps,
-Shelby
Alright Tom you may want to grab the bottle of Excedrin now as this one is going to make your head hurt. I will do my best to explain the why and how this works.
The Distortion.Type is available only on Effect so it is not going to work with DistortionEffects and that is why you are seeing the error. In order to get the single effect we need to loop each effect in effects. So a simple example of this would look like this:
Sub DistortionExample() Dim s As Shape, eff As Effect Set s = ActiveShape For Each eff In s.Effects If eff.Type = cdrDistortion Then Debug.Print eff.Distortion.Type End If Next eff End Sub
As you can see I am taking the ActiveShape looping through the effects and if a distortion effect is found I then print the type. So the goal would be to convert the above to CQL. I know your saying to yourself, not possible right, how on earth would you loop in CQL. Good news is that it is possible. Here is the same code as above converted to CQL:
Sub DistortionExampleCQL() Dim s As Shape Set s = ActiveShape Debug.Print s.Evaluate("@com.effects.toArray.foreach(array(), $item.distortion.type)") End Sub
Lets step through what it is doing. We are taking the effects and converting it to an array that we can loop through. We then use a foreach loop to look at the effect and output the distortion type. Now that we know this works, we can fix your code with it. The new code would look like this:
Sub CompletedExample() Dim effectsDistortion As ShapeRange Dim effectsPushPullDistortion As ShapeRange Dim effectsZipperDistortion As ShapeRange Dim effectsTwisterDistortion As ShapeRange Dim effectsCustomDistortion As ShapeRange Set effectsDistortion = ActivePage.Shapes.FindShapes(Query:="@com.Effects.DistortionEffects.Count > 0") If (effectsDistortion.Count > 0) Then Set effectsPushPullDistortion = effectsDistortion.Shapes.FindShapes(Query:="@com.effects.toArray.foreach(array(), $item.distortion.type) = 0") Set effectsZipperDistortion = effectsDistortion.Shapes.FindShapes(Query:="@com.effects.toArray.foreach(array(), $item.distortion.type) = 1") Set effectsTwisterDistortion = effectsDistortion.Shapes.FindShapes(Query:="@com.effects.toArray.foreach(array(), $item.distortion.type) = 2") Set effectsCustomDistortion = effectsDistortion.Shapes.FindShapes(Query:="@com.effects.toArray.foreach(array(), $item.distortion.type) = 3") End If End Sub
Notice, I also change from searching the entire ActivePage to only the ShapeRange that we know has a distortion effect. This is because CQL would error out if it hit a shape that didn't have the effect.
Shelby,
My headache has subsided. Thank you.
I understand how it is working now, I would have thought Contour, DropShadow and Extrude would be the same as the Distortion but I have those working without using the toarray.
Set effectsExtrude = ActivePage.Shapes.FindShapes(Query:="!@com.Effects.ExtrudeEffect.IsNull")
If (effectsExtrude.Count > 0) ThenSet effectsSmBackExtrude = effectsExtrude.Shapes.FindShapes(Query:="@com.Effects.extrudeEffect.Extrude.Type = 0")Set effectsSmFrontExtrude = effectsExtrude.Shapes.FindShapes(Query:="@com.Effects.extrudeEffect.Extrude.Type = 1")Set effectsBigBackExtrude = effectsExtrude.Shapes.FindShapes(Query:="@com.Effects.extrudeEffect.Extrude.Type = 2")Set effectsBigFrontExtrude = effectsExtrude.Shapes.FindShapes(Query:="@com.Effects.extrudeEffect.Extrude.Type = 3")Set effectsBackParallelExtrude = effectsExtrude.Shapes.FindShapes(Query:="@com.Effects.extrudeEffect.Extrude.Type = 4")Set effectsFrontParallelExtrude = effectsExtrude.Shapes.FindShapes(Query:="@com.Effects.extrudeEffect.Extrude.Type = 5")
End If
Set effectsContour = ActivePage.Shapes.FindShapes(Query:="!@com.Effects.ContourEffect.IsNull")
If (effectsContour.Count > 0) ThenSet effectsInsideContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.direction = 0")Set effectsOutsideContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.direction = 1")Set effectsToCenterContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.direction = 2")Set effectsCornerBevelContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.cornertype = 0")Set effectsOffSetBevelContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.cornertype = 1")Set effectsCornerRoundContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.cornertype = 2")Set effectsCornerMiteredBevelContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.cornertype = 3")Set effectsCornerMiteredOffSetBevelContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.cornertype = 4")Set effectsCornerMiteredRoundContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.cornertype = 5")Set effectsButtCapContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.endcaptype = 0")Set effectsRoundCapContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.endcaptype = 1")Set effectsSquareCapContour = ActivePage.Shapes.FindShapes(Query:="@com.Effects.ContourEffect.contour.endcaptype = 2")
Set effectsDropShadow = ActivePage.Shapes.FindShapes(Query:="!@com.Effects.DropshadowEffect.IsNull")
If (effectsDropShadow.Count > 0) ThenSet HasFlatDropShadow = ActivePage.Shapes.FindShapes(Query:="@com.Effects.DropshadowEffect.dropshadow.Type = 0")Set HasBottomDropShadow = ActivePage.Shapes.FindShapes(Query:="@com.Effects.DropshadowEffect.dropshadow.Type = 1")Set HasTopDropShadow = ActivePage.Shapes.FindShapes(Query:="@com.Effects.DropshadowEffect.dropshadow.Type = 2")Set HasLeftDropShadow = ActivePage.Shapes.FindShapes(Query:="@com.Effects.DropshadowEffect.dropshadow.Type = 3")Set HasRightDropShadow = ActivePage.Shapes.FindShapes(Query:="@com.Effects.DropshadowEffect.dropshadow.Type = 4")
************************************************************************************************************
***** That said here is another problem I found. *****
Fill Patterns
This CQL throws an error
Run-time error '-2147467259Failed to invoke the method 'frontcolor' of object 'COM:IVGPatternFill'.COM method returned error code 800200009
In the Debugger of fillPatternShapesCount is 2 so I drilled down
Item 1 Fill Pattern FrontColor Type is cdrColorCMYKItem 2 Fill Pattern FrontColor <Two color pattern fill required>
Set fillPatternShapes = ActivePage.Shapes.FindShapes(Query:="@fill.type = 'pattern'")
If (fillPatternShapes.Count > 0) ThenSet PantoneFills = fillPatternShapes.Shapes.FindShapes(Query:="@com.fill.pattern.frontcolor.type = 1 or @com.fill.pattern.backcolor.type = 1")
I even tried !@com.fill.pattern.frontcolor.IsNull and that gave the same error.
If (fillPatternShapes.Count > 0) ThenSet PantoneFills = fillPatternShapes.Shapes.FindShapes(Query:="!@com.fill.pattern.frontcolor.IsNull")
Am I doing something wrong?