Copy link to clipboard
Copied
Is there anyone know how to delete textframe by fillcolor? below are my code, but it don't work. An error message appears: "Property is write/ only" (below red code), thanks.
tfn = doc.Layers("white").TextFrames.Count
For ii = tfn To 1 Step -1
If Not doc.Layers("white").TextFrames(ii).TextRange.CharacterAttributes.FillColor = doc.Swatches("WHITE").Color Then
doc.Layers("white").TextFrames(ii).Delete
End If
Next
This snippet will show you an example where we take just the 1st character of a textframe to see what color it is, and matching the color rgb numbers to the numbers in the swatch named "RGB Red".
Set App = CreateObject("Illustrator.Application")
Set Doc = App.ActiveDocument
Set SwatchOfInterest = Doc.Swatches.GetByName("RGB Red")
SwatchOfInterest_R = SwatchOfInterest.Color.Red
SwatchOfInterest_G = SwatchOfInterest.Color.Green
SwatchOfInterest_B = SwatchOfInterest.Color.Blue
For i = 1 to Doc.Laye
...
Thanks Silly-V and CarlosCanto again!
Here I post the updated feasible code for all reference!
Dim sr1, sg1, sb1 As Double
Dim sr2, sg2, sb2 As Double
Dim tfn, ii As Integer
tfn = doc.Layers("white").TextFrames.Count
Set rgb2 = doc.Swatches("WHITE").Color
sr2 = rgb2.Spot.Color.Red
sg2 = rgb2.Spot.Color.Green
sb2 = rgb2.Spot.Color.Blue
For ii = tfn To 1 Step -1
Set rgb1 = doc.Layers("white").TextFrames(ii).TextRange.CharacterAttributes.FillColor
sr1 = rgb1.Spot.Color.Red
sg1 = rgb1.Spot.Color.Green
sb1 = rg
...Copy link to clipboard
Copied
Hi, you can't compare Objects, like swatchColor vs textFrameColor
You would need to get their color components for example if White is a cmyk color you would need to get c, m, y, k values for both the text frame and the swatch and compare them.
Copy link to clipboard
Copied
Hi, thank you very much for your reply. I'm new to Illustrator script, and it is difficult to find study material. Can you give a simple example of how to get the value of text frame and swatch color and compare them, my color setting is RGB color, thanks for your help.
Copy link to clipboard
Copied
This snippet will show you an example where we take just the 1st character of a textframe to see what color it is, and matching the color rgb numbers to the numbers in the swatch named "RGB Red".
Set App = CreateObject("Illustrator.Application")
Set Doc = App.ActiveDocument
Set SwatchOfInterest = Doc.Swatches.GetByName("RGB Red")
SwatchOfInterest_R = SwatchOfInterest.Color.Red
SwatchOfInterest_G = SwatchOfInterest.Color.Green
SwatchOfInterest_B = SwatchOfInterest.Color.Blue
For i = 1 to Doc.Layers(1).TextFrames.Count
Set TestTextFrame = Doc.TextFrames(i)
Set FirstChar = TestTextFrame.Characters(1)
Set FirstCharColor = FirstChar.CharacterAttributes.FillColor
IsColorArraySame = False
If SwatchOfInterest_R = FirstCharColor.Red AND _
SwatchOfInterest_G = FirstCharColor.Green AND _
SwatchOfInterest_B = FirstCharColor.Blue _
Then
IsColorArraySame = True
MsgBox("Text-Frame at index " & i & " has color '" & SwatchOfInterest.Name & "'.")
End If
Next
In a sample document which has 3 texts and only the middle one is colored with this color, it alerts that an item at index 2 has been found to contain a matching set of color numbers.
Copy link to clipboard
Copied
Hi Silly,
Sorry for late updated, for some reasons, I can reply to you now.
Thanks so much for your code snippet. It really helps me a lot to understand the comparison of color values.
In addition, I'd like to ask, what does these code
IsColorArraySame = False
IsColorArraySame = True
mean? What is its function?
Copy link to clipboard
Copied
IsColorArraySame doesn't do anything, it seems Silly-V wanted use it to show the message box but he realized it wasn't necessary for that rather short sample code.
but generally speaking you would use it like this
if IsColorArraySame = true then
' doSomething
else
' doSomethingElse
end if
Copy link to clipboard
Copied
Can confirm :hundred_points:
Copy link to clipboard
Copied
hahaha thanks, I miss the good 'ol points system. I wonder how the top ten illustrator scripting rank would be nowadays
Copy link to clipboard
Copied
Thanks CarlosCanto for your explanation. You're a lovely guy!
Copy link to clipboard
Copied
Thank you so much,Silly-V.
I learned more from your example code than I wanted to know. For example, the textframe characters properties.
TestTextFrame.Characters(1)
I can use it as follows to change a character contents:
doc.TextFrames(1).Characters(6).Contents = "F"
But I don't know how to change multiple characters in a textframe at a time (For example, "12345678" change to "12abcd78" )? Can you help me again?
At the same time, I found that the following codes have the same function. I don't know the difference between them (Characters and TextRanges properties)?
doc.TextFrames(1).TextRanges(6).Contents = "F"
Copy link to clipboard
Copied
Thanks Silly-V and CarlosCanto again!
Here I post the updated feasible code for all reference!
Dim sr1, sg1, sb1 As Double
Dim sr2, sg2, sb2 As Double
Dim tfn, ii As Integer
tfn = doc.Layers("white").TextFrames.Count
Set rgb2 = doc.Swatches("WHITE").Color
sr2 = rgb2.Spot.Color.Red
sg2 = rgb2.Spot.Color.Green
sb2 = rgb2.Spot.Color.Blue
For ii = tfn To 1 Step -1
Set rgb1 = doc.Layers("white").TextFrames(ii).TextRange.CharacterAttributes.FillColor
sr1 = rgb1.Spot.Color.Red
sg1 = rgb1.Spot.Color.Green
sb1 = rgb1.Spot.Color.Blue
If sr1 <> sr2 Or sg1 <> sg2 Or sb1 <> sb2 Then
doc.Layers("white").TextFrames(ii).Delete
End If
Next
Find more inspiration, events, and resources on the new Adobe Community
Explore Now