Hi. I have been using X7 for years, utilising a macro found on this forum to label my colors in a spec sheet for my artwork.
We have recently decided to upgrade to 2021.
The color label macro no longer recognises color names from my custom color palettes. It produces "unnamed color" instead.
If I run the macro on a color from a default palette such as Pantone+ Uncoated, as an example, the macro does recognises the color name.
If I run the stock ColorChartCreator macro on my custom palette, it does recognise the color names.
I am not sure with the 2021 update whether there is a compatibility issue with the col.name label in the macro, the macro itself or the color palette.
I have included the code below. If anyone has experienced and solved I would greatly appreciate it.
Sub LabelSwatches() Dim sr As ShapeRange, sh As Shape, cn As Shape, col As Color ActiveDocument.Unit = cdrInch Set sr = ActiveSelectionRange If sr.Count = 0 Then MsgBox "Nothing selected!": Exit Sub ActiveDocument.BeginCommandGroup "ColorsNames" For Each sh In sr Set col = sh.Fill.UniformColor Set cn = ActiveDocument.ActiveLayer.CreateArtisticText(sh.CenterX, sh.CenterY + (sh.SizeHeight / 2.5), col.Name & vbCr & col.Name(True), cdrEnglishUS, , "Arial", sh.SizeWidth / 0.18, , , , cdrCenterAlignment) cn.Fill.ApplyUniformFill CreateCMYKColor(0, 0, 0, 0) Next sh ActiveDocument.EndCommandGroupEnd Sub
This appears to have solved it. Thank you so much Shelby.
Shelby,
You can also use Color.Palette to get the palette from which the color was applied (if that palette exists). That does not require that the palette currently be open in CorelDRAW; just that it is registered so that CorelDRAW is aware of it.
If you are looking for an exact match, you can use Palette.GetIndexOfColor to try to find that color in that palette, and then use Palette.Color (index) to refer to that color in the palette and get the color name.
I went through some of this working on a project recently, so I have that wrapped up in a "get_color_name_from_color" function. It can optionally return a message string about how the search went, search all open palettes, or search all registered palettes.
Eskimo,
Thank you for the tips. Indeed you can get the palette from the color. So here is an improved version that does not require the palette to be open.
Sub LabelSwatches() Dim sr As ShapeRange, sh As Shape, cn As Shape, col As Color, pal As Palette ActiveDocument.Unit = cdrInch Set sr = ActiveSelectionRange If sr.Count = 0 Then MsgBox "Nothing selected!": Exit Sub ActiveDocument.BeginCommandGroup "ColorsNames" For Each sh In sr Set col = sh.Fill.UniformColor Set pal = col.Palette Set cn = ActiveDocument.ActiveLayer.CreateArtisticText(sh.CenterX, sh.CenterY + (sh.SizeHeight / 2.5), pal.Color(pal.GetIndexOfColor(col)).Name & vbCr & col.Name(True), cdrEnglishUS, , "Arial", sh.SizeWidth / 0.18, , , , cdrCenterAlignment) cn.Fill.ApplyUniformFill CreateCMYKColor(0, 0, 0, 0) Next sh ActiveDocument.EndCommandGroup End Sub
Thanks again,
-Shelby
This is great, thank you team.