Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

delete textframe by fillcolor -- VBS

Contributor ,
Jan 08, 2022 Jan 08, 2022

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

TOPICS
Scripting
928
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Valorous Hero , Jan 15, 2022 Jan 15, 2022

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
...
Translate
Contributor , Feb 07, 2022 Feb 07, 2022

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

...
Translate
Adobe
Community Expert ,
Jan 08, 2022 Jan 08, 2022

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 09, 2022 Jan 09, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 15, 2022 Jan 15, 2022

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.

SillyV_0-1642266709269.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 06, 2022 Feb 06, 2022

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2022 Feb 07, 2022

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 07, 2022 Feb 07, 2022

Can confirm :hundred_points:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2022 Feb 07, 2022

hahaha thanks, I miss the good 'ol points system. I wonder how the top ten illustrator scripting rank would be nowadays

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2022 Feb 07, 2022

Thanks CarlosCanto for your explanation. You're a lovely guy!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2022 Feb 07, 2022

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"

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2022 Feb 07, 2022
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines