2 Replies Latest reply on Nov 28, 2014 7:27 AM by Peter Kahrel

    CC2014 Changing unassigned to TEXT_TYPE bug?

    pontusuggla

      If I make a document with one unassigned box and change it to text_type I can add contents to the textframe.


      app.documents[0].pages[0].allPageItems[0].contentType = ContentType.TEXT_TYPE;
      app.documents[0].pages[0].allPageItems[0].contents = 'TEST';
      
      

       

      But if I also create a textframe, group these, and with a script ungroup, loop thru them and to the exact same thing, it changes type but I cant add contents to it:

       

      var group = app.documents[0].pages[0].allPageItems[0];
      var group_items = group.allPageItems;
      
      
      group.ungroup();
      
      
      for( var i = group_items.length - 1; i >= 0; i-- )
      {
        if( group_items[i].contentType == ContentType.unassigned )
        {
        app.select( group_items[i] );
      
        group_items[i].contentType = ContentType.TEXT_TYPE;
      
        group_items[i].contents = 'TEST';
        }
        else
        {
        group_items[i].remove();
        }
      }
      
      
        • 1. Re: CC2014 Changing unassigned to TEXT_TYPE bug?
          Marc Autret Level 4

          Hi pontusuggla,

           

          The issue in your 2nd example is not related to having items grouped. The whole problem is about unresolved specifier. To demonstrate this, let's slightly “improve” the code of your first example:

           

          var spec = app.documents[0].pages[0].allPageItems[0];
          
          spec.contentType = ContentType.TEXT_TYPE;
          spec.contents = 'TEST'; // => ERROR! Object does not support the property or method 'contents'
          
          
          
          

           

          As you can see the only change I made is assigning the long path app.documents[0].pages[0].allPageItems[0] to a variable, spec. And this doesn't work anymore!

          The reason for this is that spec becomes somewhat obsolete—i.e. unresolved—as soon as you change the contentType property, because this command converts the underlying object from a Rectangle (or equivalent) into a TextFrame. But once the mutation is done, spec still refers to the rectangle path—e.g. /document[@id=1]//rectangle[@id=342]—as shown using spec.toSpecifier(). Thus, the property spec.contents is not supported. Syntactically, spec is still a Rectangle.

           

          The problem doesn't occur in your original code because reusing the explicit path app.documents[0].pages[0].allPageItems[0] forces the system to resolve the object again:

           

          app.documents[0].pages[0].allPageItems[0].contentType = ContentType.TEXT_TYPE;
          app.documents[0].pages[0].allPageItems[0].contents = 'TEST';
          
          
          

           

          In line #1, app.documents[0].pages[0].allPageItems[0] points out to a Rectangle (or any equivalent unassigned SplineItem);

          In line #2, app.documents[0].pages[0].allPageItems[0] points out to a TextFrame.

           

          The generic method to repair unresolved specifiers is getElements(). In my code above, the solution is:

           

          var spec = app.documents[0].pages[0].allPageItems[0];
          
          spec.contentType = ContentType.TEXT_TYPE;
          // spec.contents = 'TEST'; // => ERROR!
          spec.getElements()[0].contents = 'TEST'; // OK
          
          
          
          

           

          Similarly, the solution in your grouping example is:

           

          // ...
          group_items[i].contentType = ContentType.TEXT_TYPE;
          // group_items[i].contents = 'TEST';  // ERROR
          group_items[i].getElements()[0].contents = 'TEST'; // OK
          // ...
          
          
          

           

          @+

          Marc

          • 2. Re: CC2014 Changing unassigned to TEXT_TYPE bug?
            Peter Kahrel Adobe Community Professional & MVP

            Very interesting -- thanks for pointing that out, Marc.

             

            Peter