1 Reply Latest reply on May 8, 2012 1:44 PM by John Hawkinson

    Place object from Library than scale

    beh_gras_beh Level 1

      Dear people,

       

      I'm trying to build a script that’s placing an object (in a text frame) and than scale the object to xx%.

       

      The script place the object but it is not being scaled, any idea why?

       

       

      var setting;
      setting = app.transformPreferences.whenScaling;
      app.transformPreferences.whenScaling = WhenScalingOptions.ADJUST_SCALING_PERCENTAGE;
        
       t=app.libraries.item("test.indl").
          assets.item("item1").
          placeAsset(app.activeDocument);
      
      allSel = app.libraries.item[t];
      if (allSel.length > 0) {
                xScale = 60 / 100;
                yScale = 60 / 100;
         
          for (t=0; t<app.selection.length; t++) {
                           app.libraries.item[t].horizontalScale = app.libraries.item[t].horizontalScale * xScale; 
                           app.libraries.item[t].verticalScale = app.libraries.item[t].verticalScale * yScale;
          }
      }
      

       

      Thanks for anyone who wants to help!

      Greetings from Holland

        • 1. Re: Place object from Library than scale
          John Hawkinson Level 5

          Your example seems pretty confused.

          You use the variable t for two differennt things. First it is the array of placed items from the placeAsset() call.

          Then it is the index into the the library.

          That's a bad idea, it causes confusion.

           

          You appear to be changing the library item's scaling after you have plcaed it. That modifies the library (perhaps) but does nothing for the item already placed. Instead you need to perform your operations on the array returned by placeAsset().

           

          Since it is an array, you must either group the contents or iterate over the array to transform them. I suggest grouping.