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

Splitting Text Frame By Paragraph Style

Community Beginner ,
Jun 18, 2018 Jun 18, 2018

Copy link to clipboard

Copied

Hello,

I'm quite new to InDesign. I'm having some difficulties with a problem.

I've considered and tried a few approaches. I'm not sure where I'm going wrong / which approach is best (or possible).

---ISSUE---

I'm trying to extract product details from Text Frames in an InDesign product catalog file, so that they can be modified and then replaced.

The file was put together by a third party.

The information for each product is in a single text frame. Paragraph styles were used to apply the styles to sections within the frame. (title, description, table headers)

---EXAMPLE---                                                 ______________________

<Name>REWRITABLE MARKERS                |                                                |

FOR DRY ERASE BOARDS</Name>           |             WHITE SPACE           |

<Desc> Low odour, non-toxic, fine             |             RESERVED                 |

point markers. Each marker cap                 |              FOR IMAGE               |

included a built in magnet.</desc>           |______________________|

<header> PRODUCTNUMBER          DESCRIPTION          UNIT          PRICE </header>

<line>      000-000-000                         Assorted Colours     6/PK          4.99</line>

The <> tags being the start and end of paragraph styles.

---APPROACH 1--- (splitting content string)

Initially, I thought I would be able to just get the contents and split the string by line breaks to get the contents of each section.

This worked, but the line breaks aren't where I expected.

(The first line break in the initial frame I examined was after the first line of the description style, so it includes the name and the start of the description... Not sure why)

So I don't think this will work for my needs.

It also made me question how the width of the Name and Description content was being set to leave white space for the image, if they weren't using line breaks.

I thought maybe the Name and Description paragraph styles had a set width, but I haven't come across this setting in the style options 😕

I don't think this will help me solve the problem, but I am curious if anyone has any ideas how / where this width could be defined

---APPROACH 2--- (map tags to styles)

My second thought was to use map XML tags to the styles, and then pull and replace content using the XML tag element.
I have worked with XML tags this way before to analyze and replace content, but never with the Map feature.

I can't seem to get the Map Tags to Styles feature to apply the tags when I set one up.

Does this work alright with parts of a text frame?

To use a simplified example, if I have a textframe

     {TEXT FRAME}   <style1> Example Text </style1>  <style2> Example Content </style2>   {/TEXT FRAME}

Can I set a create tags [S1] and [S2], set up a Map Tags to Styles 'rule'  mapping Tag [S1] to Style <style1> and Tag [S2] to Style <style2> to get:

     {TEXT FRAME}   [S1] Example Text [/S1]  [S2] Example Content [/S2]   {/TEXT FRAME}

(obviously with the paragraph styles still applied, just excluded to show the frame tags easier)

This would be my ideal approach if I could get it working, as I already have very similar scripts working with the XML elements that I could modify.

But I have no idea why I can't seem to get any tags to apply...

---APPROACH 3--- (split contents by style)

This is probably less likely to be achievable, but I'm running out of ideas

I was hoping if I get a list of the textFrames, I could somehow get the contents of a specific paragraph style (or font size/family, whatever).
Any way that I could move through the contents and see when the styling has changed..

Much like I am doing here with XML Tags.

Get a list of items with a 'Product' tag within the document.

Then get a list of items with a 'Code' tag from within the previously stored list.

     var doc = app.activeDocument;

     var xmlTag = doc.xmlElements[0];

     var productTags = xmlTag.evaluateXPathExpression("//Product")

     for(var i=0;i<productTags.length;i++)

     {

          var codeTags = productTags.evaluateXPathExpression("//Code") ; 

          //..Process Code

     }

Sorry for the long post, I just wanted to show that I had tried a few things, and was hoping maybe one of them was on the right track.

---TLDR---

I'm trying to get contents from different sections of a Text Frame that are defined by paragraph styles.

Is there any way to get the contents of a text frame, and then split that based on the paragraph style applied to different sections of the content?

I'd really like to get the Map Tags to Styles feature working to tag each section of the frame based on the style, but no tags are applied when I set up a tag-style relationship.

Thanks in advance to anyone that has some input to provide.

I'm quite stuck at the moment.

TOPICS
Scripting

Views

909

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 Beginner , Jun 18, 2018 Jun 18, 2018

Hello,

I think I found the issue that was preventing me from tagging the styles.
The styles that they had names that started with numbers. Which InDesign doesn't seem to like (reasonably so).
I've renamed the styles and I've been able to get a script working that is adding XML tags to the styled elements.

I still wasn't able to get the Map Tags to Styles working. But the script seems to have done the trick.
If anyone has any other approaches or feedback, I'd still love to hear it!

But I think I ca

...

Votes

Translate

Translate
Community Beginner ,
Jun 18, 2018 Jun 18, 2018

Copy link to clipboard

Copied

LATEST

Hello,

I think I found the issue that was preventing me from tagging the styles.
The styles that they had names that started with numbers. Which InDesign doesn't seem to like (reasonably so).
I've renamed the styles and I've been able to get a script working that is adding XML tags to the styled elements.

I still wasn't able to get the Map Tags to Styles working. But the script seems to have done the trick.
If anyone has any other approaches or feedback, I'd still love to hear it!

But I think I can move forward with my project at this point.
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