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

Text Wrap Only Applying to TextWrapModes.CONTOUR via JS

New Here ,
Jul 27, 2018 Jul 27, 2018

Copy link to clipboard

Copied

Here's a weird one. I'm trying to write a script that applies TextWrapSideOptions.LARGEST_AREA to every graphic in my document. However, my script only applies this to graphics already set to TextWrapModes.CONTOUR. I have no idea why, as TextWrapModes aren't specified anywhere in this script. Here's what I've got.

for (i=0; i<app.activeDocument.allGraphics.length; i++)

{

    wrapIt (app.activeDocument.allGraphics);

}

function wrapIt (img)

{

    img.textWrapPreferences.textWrapSide = TextWrapSideOptions.LARGEST_AREA;

}

Anyone have any insights for me? The alternative is either doing this manually or convincing my layout designers to properly format images. I'll let you guess which is more likely to happen.

Thanks!

TOPICS
Scripting

Views

754

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 , Jul 30, 2018 Jul 30, 2018

Hi Phil,
I cannot see why this should not work:

 

var doc = app.documents[0];
var allGraphics = doc.allGraphics;
var allGraphicsLength = allGraphics.length;

for ( n=0; n<allGraphicsLength; n++)
{

    allGraphics[n].textWrapPreferences.properties =
    {
      //  textWrapMode : TextWrapModes.CONTOUR ,
        textWrapSide : TextWrapSideOptions.LARGEST_AREA ,
        textWrapOffset : NothingEnum.NOTHING ,
        applyToMasterPageOnly : false
    };

};

 

Just tested with some placed graphics wi

...

Votes

Translate

Translate
Community Expert ,
Jul 27, 2018 Jul 27, 2018

Copy link to clipboard

Copied

Hi Phil,

see into all read/write properties for textWrapPreferences.

If textWrapPreferences.textWrapMode is set to TextWrapModes.NONE you see no effect of textWrapSide.

 

Something like that should work:

 

 

 

var doc = app.documents[0];
var allGraphics = doc.allGraphics;
var allGraphicsLength = allGraphics.length;

for ( n=0; n<allGraphicsLength; n++)
{

    allGraphics[n].textWrapPreferences.properties =
    {
        textWrapMode : TextWrapModes.CONTOUR ,
        textWrapSide : TextWrapSideOptions.LARGEST_AREA ,
        textWrapOffset : NothingEnum.NOTHING ,
        applyToMasterPageOnly : false
    };

};

 

 

 

Regards,
Uwe

 

//EDITED 2020-01-09: Repaired the posted code in this message, because moving this old thread to the new forum changed the code.

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
New Here ,
Jul 27, 2018 Jul 27, 2018

Copy link to clipboard

Copied

Hey there, thanks for the quick response.

Unfortunately, this doesn't quite address or solve my problem. My issue isn't with converting all graphics to "TextWrapModes.CONTOUR" and "TextWrapSideOptions.LARGEST_AREA." In fact, I could already do that by simply adding "

img.textWrapPreferences.textWrapMode = TextWrapModes.CONTOUR;" to my original function. What I'm trying to do is to set every graphic to "TextWrapSideOptions.LARGEST_AREA: regardless of its textWrapModes setting.

On a side note, I found that if I substitute a different TextWrapModes setting (e.g., substituting "TextWrapModes.BOUNDING_BOX_TEXT_WRAP" for TextWrapModes.CONTOUR"), I always get the same result: all graphics change their TextWrapModes setting to "NONE." This is true for both my original script and your. Even though my goal isn't to change ant TextWrapModes setting, I find this extremely frustrating because I can't find any reason this should happen.

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 ,
Jul 29, 2018 Jul 29, 2018

Copy link to clipboard

Copied

Hi Phil,

did you check if you can achieve what you want using InDesign without scripting?
And if so couldn't you check the properties and the values with text wrap then?

Regards,
Uwe

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 ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

Hi Phil,
I cannot see why this should not work:

 

var doc = app.documents[0];
var allGraphics = doc.allGraphics;
var allGraphicsLength = allGraphics.length;

for ( n=0; n<allGraphicsLength; n++)
{

    allGraphics[n].textWrapPreferences.properties =
    {
      //  textWrapMode : TextWrapModes.CONTOUR ,
        textWrapSide : TextWrapSideOptions.LARGEST_AREA ,
        textWrapOffset : NothingEnum.NOTHING ,
        applyToMasterPageOnly : false
    };

};

 

Just tested with some placed graphics with different values for text wrap mode on InDesign CC 2018.1 on Windows 10.

Can you make up a case where it is not working and show it using some screenshots?

 

Before > After > How it should be

 

Regards,
Uwe

 

//EDITED 2020-01-09: Repaired the posted code in this message, because moving this old thread to the new forum changed the code.

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
New Here ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

Oh good—I'm not crazy. Yeah, that should work. The fact that it doesn't makes this most likely not a scripting issue.

To elaborate, I decided to take a different approach and use Find/Change Object commands the way I've successfully manipulated grep quarries via JS. No dice. In fact, when attempting to manually search for any graphic frames set to wrap to both side, it came up empty every time. This is starting to look like a bug to me. I suppose this is a matter for tech support to sort out.

As a novice, I really appreciate your help on this, if only to reassure me that I wasn't doing anything too far off. Thank you!

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 ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

Hi Phil,

oh. Please check if it makes a difference if you are addressing the placed graphic and/or the frame holding the placed graphic.

The frame holding the placed graphic is the parent of the graphic.

Reards,
Uwe

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 ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

And I really like to see a case where the script snippet above will not work.

You can use a download service like Dropbox and add a link here.

Use InDesign's package command and zip the packaged document with the Links folder.

Regards,
Uwe

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
New Here ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

Good idea. I just tried that, and it doesn't seem to make a difference. Here's a screenshot of me attempting to do this manually via the Find/Change Object module.

Screen Shot 2018-07-30 at 7.28.29 AM.png

Forgive my silliness.

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 ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

My, my…

I think Object Find/Change is a bag of bugs.

Better work around this and work with the allPageItems array of the document and filter that for known property/value pairs.

Regards,
Uwe

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
New Here ,
Jul 30, 2018 Jul 30, 2018

Copy link to clipboard

Copied

LATEST

Yeah... I was starting to suspect that could be the case. I guess I'm going to have to roll up my sleeves and get a bit deeper into scripting to sort this out. I'll just call this inspiration to get better at scripting (assuming I can find enough spare time to do that).

Much obliged for your time and effort,

—Phi

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