Selecting All Text with the same background color
Selecting All Text with the same background color
Is it possible to select All Text with the same background color, no matter what other attributes are going with that text?
Re: Selecting All Text with the same background color
Yes. Put your cursor in an area of text with the colour in question and there should appear on the status bar at the bottom of the window a spot of the colour; click on that and from the menu that appears select all.

Mark
Sorry, I misread your question and also forgot I was in the Macros forum. Someone more on the ball should be along soon, I'm sure.

Mark
Sorry, I misread your question and also forgot I was in the Macros forum. Someone more on the ball should be along soon, I'm sure.
Re: Selecting All Text with the same background color
Well just to continue where Mark left off, first of all, if you just want to select those parts you could use Kino's macro "Select By Attributes". Moreover if you want to know how to do this yourself, you can look there to see how Kino does it. The basic idea for selecting by attribute is to use a "Kino loop", which looks like this:
In your case you will want to check the attributes for the appropriate background color and then use the range to create a selection for the bits you want, and put those selections into an array. Then at the end you can use that selection array as an argument to the .setSelection command.
So the whole thing should be like so:
Code: Select all
# get a text object and put it in $text
$i = 0
while $i < $text.length
$attr = $text.displayAttributesAtIndex $i
$range = $text.rangeOfDisplayAttributesAtIndex $i
# check and do stuff here
$i = $range.bound
end
So the whole thing should be like so:
Code: Select all
$doc = Document.active
$text = $doc.text
$desiredColor = Color.new… # set appropriately (see macro reference)
$bgcolorSels = Array.new
$i = 0
while $i < $text.length
$attr = $text.displayAttributesAtIndex $i
$range = $text.rangeOfDisplayAttributesAtIndex $i
if $attr.textBackgroundColor == $desiredColor
$bgcolorSels.push TextSelection.new($text, $range)
end
$i = $range.bound
end
$doc.setSelection $bgcolorSels
philip
Re: Selecting All Text with the same background color
Thank you Philippe. This is certainly good adivice for the procedure as such.
This said I am not sure about a Kino micro called "select by attributes". I see that there are macros selecting style, language and font. Where you referring to one of these?
But probably my question was not as precise as I had intended . I see now that the word background color is used for text as well as for the shading of a whole paragraph. What I wish to extract from certain documents are paragraphs with the same shading, not considering differences in text attributes.
Would you know how to obtain the paragraph shadings?
This said I am not sure about a Kino micro called "select by attributes". I see that there are macros selecting style, language and font. Where you referring to one of these?
But probably my question was not as precise as I had intended . I see now that the word background color is used for text as well as for the shading of a whole paragraph. What I wish to extract from certain documents are paragraphs with the same shading, not considering differences in text attributes.
Would you know how to obtain the paragraph shadings?
Re: Selecting All Text with the same background color
Exactly it's one of those. At least on my set-up there is also one called "Select by Attributes". In fact all of those macros work on the same basic principle of the "Kino loop".js wrote:Thank you Philippe. This is certainly good adivice for the procedure as such.
This said I am not sure about a Kino micro called "select by attributes". I see that there are macros selecting style, language and font. Where you referring to one of these?
Yes, the macro will look practically the same just replace .textBackgroundColor with .paragraphShadingAttributes. Paragraph Shading Attributes are a bit more complicated. In the simplest case you can just compare .backgroundColor to the $desiredColor variable. So perhapsjs wrote: But probably my question was not as precise as I had intended . I see now that the word background color is used for text as well as for the shading of a whole paragraph. What I wish to extract from certain documents are paragraphs with the same shading, not considering differences in text attributes.
Would you know how to obtain the paragraph shadings?
Code: Select all
if $attr.paragraphShadingAttributes.backgroundColor == $desiredColor
One option might be to have the macro find all parts that have the same Paragraph Shading Attributes as the current selection. It really depends a bit on what you want.
But actually I have to say that if you are looking for paragraph shading attributes, unlike other attributes they will only change for whole paragraphs. So you could probably simplify the macro a bit by only moving from paragraph to paragraph, and checking the attributes once for each paragraph. But the basic idea of looping through the text and collecting the ranges/selections into an array stays the same.
philip
Re: Selecting All Text with the same background color
Thank you again.
In fact my start position is not to chose a background color. The idea is to put the cursor into a paragraph X with para bg color Y and to have the macro select all other paragraphs that have para bg color Y. So rather than to define a para bg color I wonder what I should do to get it, for the para with the insertion point.
But now I discover, a bit by chance and to my surprise the following: If I select, in one of those colored paragraphs, a character written in standard black default font, and copy it to the find window, replacing it there with ".*" and select attribute sensitive, a regex find all will select all paragraphs with the same bg color. What surprises me: all text in the desired paragraphs is selected, including bold, underlined, colored text etc. Well, this is in fact what I wanted.
In fact my start position is not to chose a background color. The idea is to put the cursor into a paragraph X with para bg color Y and to have the macro select all other paragraphs that have para bg color Y. So rather than to define a para bg color I wonder what I should do to get it, for the para with the insertion point.
But now I discover, a bit by chance and to my surprise the following: If I select, in one of those colored paragraphs, a character written in standard black default font, and copy it to the find window, replacing it there with ".*" and select attribute sensitive, a regex find all will select all paragraphs with the same bg color. What surprises me: all text in the desired paragraphs is selected, including bold, underlined, colored text etc. Well, this is in fact what I wanted.