4 Replies Latest reply on Nov 7, 2011 2:58 AM by seba1395

    How change size of an anchored object ?

    seba1395

      Hello, I make a script that change size of a element by looking name (label and name).

       

      So It's work very well :

       

      var myStories = app.activeDocument.pageItems.everyItem().getElements();

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

       

      if(myStories[i].name=="Post_it"){

      var g_obj1 = get1(myStories[i]);

      var g_obj2 = get2(myStories[i]);

      var g_obj3 = get3(myStories[i]);

      var g_obj4 = get4(myStories[i]) + 5 ;

       

      myStories[i].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];

       

      }

      }

       

      But when I copy it and paste in a text to do a anchored object, it doesn't work!

       

      I check the name and the label, it's the same.

       

      Why it doesn't work when the object in anchored and how can I resolved it ?

       

      Thanks a lot!

       

        • 1. Re: How change size of an anchored object ?
          கற்பனை (Imagine) Level 3

          Because the anchored objects are nested to the parent objects.  you must have the second iteration for getting those objects.

          • 2. Re: How change size of an anchored object ?
            seba1395 Level 1

            Thank for your answer !

             

            How can I do that? Do you have an example ?

            • 3. Re: How change size of an anchored object ?
              csm_phil Level 4

              Hi Seba,

               

              Can you please try the below JS code, this code will check the anchored items whose label name is "Post_it" corect it will change the anchored frame size is 5 pica.

              I hope you expect this. Otherwise please revert if you have update any.

               

              var myDoc = app.activeDocument;
              myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.picas;
              myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.picas; 
              
              var myPg = myDoc.allPageItems;
              for (i=0; i<myPg.length; i++){
                  var myFrame = myPg[i];
                  if(myFrame instanceof TextFrame){
                      //alert(myFrame.label);
                      if(myFrame.label==" Post_it"){
                          if(myFrame.parent.constructor.name=="Character"){
                              tf = myFrame.parent.textFrames[0].geometricBounds;
                              tf[2] = tf[0] + 5;
                              myFrame.parent.textFrames[0].geometricBounds = tf;
                              }
                          }
                      }
                  }
              

               

               

              thx

              csm_phil

              • 4. Re: How change size of an anchored object ?
                seba1395 Level 1

                Yes! Very nice ! Thank a lot !

                 

                Like this :

                 

                var myStories = app.activeDocument.allPageItems;

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

                        if(myStories[i]  instanceof TextFrame){

                                if(myStories[i].name=="Post_it" || myStories[i].label=="Post_it"){

                                        var num_page_active = myStories[i].parentPage.name;

                                        alert(num_page_active);

                                        var g_obj1 = get1(myStories[i]);

                                        var g_obj2 = get2(myStories[i]);

                                        var g_obj3 = get3(myStories[i]);

                                        var g_obj4 = get4(myStories[i]) + 5 ;

                                        myStories[i].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];

                                  }

                        }

                }

                 

                 

                 

                So, It's work! Now, I would like to do this only on the even page.

                In CS5, all is ok :

                 

                 

                var myStories = app.activeDocument.allPageItems;

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

                        if(myStories[i]  instanceof TextFrame){

                                if(myStories[i].name=="Post_it" || myStories[i].label=="Post_it"){

                                        var num_page_active = myStories[i].parentPage.name;

                                         Number.prototype.isEven = function (){return (this%2 == 0) ? true : false;}

                                        if(Number(num_page_active).isEven()==false){

                                            var g_obj1 = get1(myStories[i]);

                                            var g_obj2 = get2(myStories[i]);

                                            var g_obj3 = get3(myStories[i]);

                                            var g_obj4 = get4(myStories[i]) + 5 ;

                                            myStories[i].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];

                                            myStories[i].name="Post_it_Dec";

                                            myStories[i].label="Post_it_Dec";

                                        }

                                  }

                        }

                }

                 

                 

                But in CS4, the parent.name give me some problème that I can't resolved.

                In CS4, it does'nt know ".name" but ".label" only.

                 

                So this does'nt work for CS4 :

                 

                var myStories = app.activeDocument.allPageItems;

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

                 

                 

                                              if( myStories[i].label=="Post_it"){

                                                        myStories[i].select();

                                                        var num_page_active = myStories[i].parent.name;

                                                        Number.prototype.isEven = function (){return (this%2 == 0) ? true : false;}

                                                        if(Number(num_page_active).isEven()==false){

                                                   var g_obj1 = get1(myStories[i]);

                                                                                      var g_obj2 = get2(myStories[i]);

                                                                                      var g_obj3 = get3(myStories[i]);

                                                                                      var g_obj4 = get4(myStories[i]) + 5 ;

                                                                                      myStories[i].geometricBounds = [g_obj1,g_obj2,g_obj3,g_obj4];

                                                                                      myStories[i].label ="Post_it_Dec";

                                                        }

                          }

                }


                 

                Can you help me here or I create a new topic?