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

remove end of paragraph symbol in a textFrame using javascript

Engaged ,
Mar 25, 2022 Mar 25, 2022

KarthikSG_0-1648201761223.pngexpand image

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.appliedParagraphStyle = String(dropdown1.selection);
app.findGrepPreferences.findWhat = "\\r";  
 var foundItems = app.activeDocument.findGrep(true);
app.changeGrepPreferences.changeTo = "";
 app.activeDocument.changeText ( );
 app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

I am trying to remove this end of paragraph symbol(due to this i am getting new empty line)!

TOPICS
How to , Scripting
522
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 ,
Mar 25, 2022 Mar 25, 2022

Your code looks fine. What issue are you seeing? Check if the value of the dropdown selection is correct or not

-Manan

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 ,
Mar 25, 2022 Mar 25, 2022

Hi Karthic,

try this pattern:

findWhat = "\\r+\\Z";

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Mar 25, 2022 Mar 25, 2022

@Laubender this grep is also working! thanks for your response!

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

But this replaces content. If the paragraph contains any formating, it's more than likely to get messed up. Better to use something like this:

 

// Assuming a story
while (myStory.characters[-1].contents == '\r') {
  myStory.characters[-1].contents = '';
}
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
Engaged ,
Mar 25, 2022 Mar 25, 2022

instead of changeGrep "app.activeDocument.changeGrep ( );",i coded as changeText "app.activeDocument.changeText ( );", Now its working fine! thanks for your response!

 

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.appliedParagraphStyle = String(dropdown1.selection);
app.findGrepPreferences.findWhat = "\\r";  
app.changeGrepPreferences.changeTo = "";
app.activeDocument.changeGrep( );
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

 

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 ,
Mar 25, 2022 Mar 25, 2022

 

findWhat = "\\r";

 

in combination with:

 

changeTo = "";
app.activeDocument.changeGrep( );

 

 

would remove every end of paragraph character that is formatted with the selected paragraph style in your document. Not only the one that is at the end of a story or at the end of a text cell.

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Mar 27, 2022 Mar 27, 2022
LATEST

@Laubender Yes, you are absolutely right but it works fine for my purpose! thanks for your time!

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 ,
Mar 25, 2022 Mar 25, 2022

Hi @Karthik SG , just to clarify are you trying to remove the paeragraph return or the end of story invisible (#)?

 

Removing the return I would expect this:

 

Screen Shot 8.pngexpand imageScreen Shot 9.pngexpand image

 

 

app.findGrepPreferences.findWhat=NothingEnum.NOTHING
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING
app.findGrepPreferences.findWhat = "\\r";
app.changeGrepPreferences.changeTo = "";
app.activeDocument.changeGrep()
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