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

Find and replace Object with text using GREP

Enthusiast ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

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

TOPICS
How to

Views

506

Translate

Translate

Report

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 1 Correct answer

Community Expert , Dec 27, 2022 Dec 27, 2022

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.

Votes

Translate

Translate
Community Expert ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

In that case you can use the Object tab of the Find/Change window.

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Thanks Peter. It works but in that case I am not able to use my imported line art image which I want to use.

Regards

Votes

Translate

Translate

Report

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 ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

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 ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

I see. What you need to do is to place the images behind the anchored text frames. The best way to do that is to create an object style for the images, then place the anchor immediately before the anchors of the text frames. The precise location of the images is set in the object style -- that'll be a bit fiddly but you need to do it only once.

 

Do this:

1. Place just one image. Name it background on the Layers panel: open the Layers panel (F7), select the image, in the layers panel do a slow double-click and type the name.

2. Create an object style, call it background, and apply it to the image. The object style should be a custom anchor (just like Waqf). Fiddle with the settings until it sits exactly centred behind the anchored text frames.

3. Then run this script:

doc = app.documents[0];
background = doc.pageItems.item('background');
app.findObjectPreferences = null;
app.findObjectPreferences.appliedObjectStyles = doc.objectStyles.item('Waqf');
waqfs = doc.findObject();
for (i = waqfs.length-1; i >= 0; i--) {
  duped = background.duplicate();
  duped.anchoredObjectSettings.insertAnchoredObject (
    waqfs[i].parent.insertionPoints[0],
    AnchorPosition.INLINE_POSITION
  );
  duped.clearObjectStyleOverrides();
}

 

 

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Thanks for the effort.

 

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

I have attached the screenshot.

Votes

Translate

Translate

Report

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 ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

LATEST

Thanks Peter.

 

It worked.

Votes

Translate

Translate

Report

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