1 Reply Latest reply on Feb 15, 2010 2:40 AM by Andreas Jansson

    [CS4 JS] Conditions for WHOLE paragraph

    Andreas Jansson Level 2

      For certain pieces of text I'd like to apply a condition named "Empty fields", to be able to hide those pieces of text.


      I have a reference to an XMLElement and need to hide the FULL paragraph if the text of that XMLElement is a paragraph of its own.


      The closest I got was to include any trailing CHAR(13), that is a "new paragraph" starting directly after the xmlElement. But doing so, I end up with the wrong paragraphStyle on the paragraph flowing up one step when hiding the "Empty Fields" condition (clicking the eye in the conditions panel). Since the data I'm trying this out on for example has bullet points on one place, I can not have it, that the following paragraph end up with bullets...


      So... I try include any leading paragraph characters instead. That seems to work better trying it manually so to say.That however does not seem to have any effect.

      I try to get hold of the characters before the actually tagged text, which I have access to through an XMLElement:


      var firstCharIndexBeforeEmptyText = elemToUpdate.texts[iText].insertionPoints.firstItem().index - 1

      // The starting XML tag...
      elemToUpdate.parentStory.characters.item(firstCharIndexBeforeEmptyText).applyConditions(ne w Array('Empty fields'), false);

      // The paragraph character, last in the previous paragraph
      elemToUpdate.parentStory.characters.item(firstCharIndexBeforeEmptyText-1).applyConditions( new Array('Empty fields'), false);


      But checking the appliedConditions of the same characters (firstCharIndexBeforeEmptyText and firstCharIndexBeforeEmptyText-1) after this code has run displays no appliedCondition at all for those characters. It does not show up checking while running (checking in the javascript console) nor in real life, putting the cursor on the place and looking at the conditions panel.


      What should I do to actually hide the text?

      Hide it including its format (the bullet of the format is visible unless I hide the whole paragraph), and not making the next paragraph in the text be affected of the hidden one.


      Please anyone?



        • 1. Re: [CS4 JS] Conditions for WHOLE paragraph
          Andreas Jansson Level 2
          // Add a document with a text frame containing three paragraphs
          doc = app.documents.add();
          frame = doc.textFrames.add({geometricBounds:["12.8mm","12.8mm","50mm","100mm"]});
          frame.contents = 'Line 1 no format\r';
          frame.contents += 'Line 2 Bulllets\r';
          frame.contents += 'Line 3 no format\r';
          // Create a paragraph style (with bullet list style)
          bulletStyle = doc.paragraphStyles.add()
          bulletStyle.bulletsAndNumberingListType= 1280598644
          // Assign the bullet style to the middle paragraph
          frame.paragraphs[1].appliedParagraphStyle = bulletStyle
          // Create a text condition.
          myCondition = doc.conditions.add({name:'Empty fields'});
          myCondition.visible = false;
          frame.paragraphs[1].applyConditions(new Array(myCondition));


          Answering myself here:


          The sample code above works fine. However, since my production code (or production code to be) involves XML tags and I apply the conditions to the XMLElement and not to the paragraph.

          The solution I'll try next is to check whether the the XML Element is also a paragraph on it's own. Only then I'll set the condition to the paragraph but otherwise I apply it to the XML Element.