Skip to main content
Bedazzled532
Inspiring
December 26, 2022
Answered

Find and replace Object with text using GREP

  • December 26, 2022
  • 1 reply
  • 1736 views

Hi
I am working on Al-Quran which has many anchors to the text (red color text frame with text in the attached image)

I now want to replace the red frame with some other box. Say the blue box (shown in the image).

How do I do that with grep. I tried find and replace with ~a and ~c but that is deleting all the text inside the red text box.

I want the text to remain and change the box only. What would be the process using grep?

Thanks

This topic has been closed for replies.
Correct answer Peter Kahrel

Thanks for the effort.

 

I am getting an error message while running the script.  "Object is Invalid"

I have attached the screenshot.


The problem is that the background frame is anchored. Sorry, I should have mentioned that it should be floating, as it were, not anchored. You can simply copy and paste the frame that you placed, then it should work.

1 reply

Adobe Expert
December 26, 2022

GREP finds text, not frames. Well, it can frames but only via text. But the solution is simple: change the object style that's applied to those boxes. If no specific object style was used, now's the time to create a style and apply the style.  You can't do that in the interface, but a small script can do it for you.

First, create an object style for the blue box (if you don't have it already). The script assumes blue box, you can use something else but then you need to change the name in the script.

Here's the script:

 

ostyle = app.documents[0].objectStyles.item('blue box');
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '~a';
frames = app.documents[0].findGrep();
for (i = 0; i < frames.length; i++) {
  frames[i].pageItems[0].appliedObjectStyle = ostyle;
}

 

 

P.

Bedazzled532
Inspiring
December 27, 2022

Thank you so much Peter. 

This worked partly. Its my mistake, I should have mentioned it in my question.

The code is replacing other anchors also who doesnot have any object style applied to them or some other object style is applied.

In short. I want to replace all the RedsBox object style Text Frame with Blue Box. 
Thanks

Bedazzled532
Inspiring
December 27, 2022

I don't entirely understand. Please elaborate. The red frame is an image?


First of all I am sorry, I am not able to explain it properly. I'll try to explain once again by the help of attached image.

In the attachment, the ones circled in red color are text frames (object style named Waqf has been applied to these boxes ) attached to the main text. I want to put some line art image here (Circled with magenta color in the attachement. My final output should look like this)

 

The one circled in blue color is my line art image.

 

I tried the GREP method which did not work. Its replacing the text in red circle

There are approx 1000 pages where modification is required.

Sorry for the inconvenience and thanks in advance.