Skip to main content
runew73276507
Known Participant
December 27, 2015
Answered

Script who moves an already placed frame to a new position (x/y)

  • December 27, 2015
  • 1 reply
  • 2196 views

Hi,

I need help with a simple scriptcode who can move an already placed frame in x=6,99mm /  y=4,801 to a new posistion x=10mm / y=10mm

Can anyone please help?

Merry X-mas!

This topic has been closed for replies.
Correct answer Ronald63

Hi,

Hope this help you :

var doc = app.activeDocument;

var mItems=doc.allPageItems;

var len = mItems.length;

while(len--){

    var mItem = mItems[len];

    var mBounds = mItem.geometricBounds;

    var mX = getRound(mBounds[1],3);

    var mY= getRound(mBounds[0],3);

    if(mX == 6.99 && mY == 4.801){

        mItem.move([10, 10]);

    }

}

/* round */

function getRound(number, digits) {

        digits = (digits) ? Math.pow(10, digits) : 1000; 

        return Math.round(number * digits) / digits; 

}

Regards

1 reply

Ronald63Correct answer
Legend
December 27, 2015

Hi,

Hope this help you :

var doc = app.activeDocument;

var mItems=doc.allPageItems;

var len = mItems.length;

while(len--){

    var mItem = mItems[len];

    var mBounds = mItem.geometricBounds;

    var mX = getRound(mBounds[1],3);

    var mY= getRound(mBounds[0],3);

    if(mX == 6.99 && mY == 4.801){

        mItem.move([10, 10]);

    }

}

/* round */

function getRound(number, digits) {

        digits = (digits) ? Math.pow(10, digits) : 1000; 

        return Math.round(number * digits) / digits; 

}

Regards

runew73276507
Known Participant
December 27, 2015

Thank you so much - you have saved me for at lot of manual work

Ronald63 skrev:

Hi,

Hope this help you :

  1. var doc = app.activeDocument; 
  2. var mItems=doc.allPageItems; 
  3. var len = mItems.length; 
  4.  
  5. while(len--){ 
  6.     var mItem = mItems[len]; 
  7.     var mBounds = mItem.geometricBounds; 
  8.     var mX = getRound(mBounds[1],3); 
  9.     var mY= getRound(mBounds[0],3); 
  10.     if(mX == 6.99 && mY == 4.801){ 
  11.         mItem.move([10, 10]); 
  12.     } 
  13. /* round */ 
  14. function getRound(number, digits) { 
  15.         digits = (digits) ? Math.pow(10, digits) : 1000;   
  16.         return Math.round(number * digits) / digits;   

Regards

Legend
February 2, 2016

Ahh of course - stupid me - now it works great, thank you!

What if:

1. I run the script and everything works fine

2. now suddenly the placed object is back to 100% / 100%

3. When I run the script again nothing happens

When this situation appears I would want it to still fit content to frame.

Is it possible?


Hi,

try this (add code from line 18 to 20)

    var doc = app.activeDocument;   

    var mItems=doc.allPageItems;   

    var len = mItems.length;   

     

    // save measurement unit & set measurement unit to mm 

    savedUnits = app.scriptPreferences.measurementUnit; 

    app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS; 

     

    while(len--){   

        var mItem = mItems[len];   

        var mBounds = mItem.geometricBounds;   

        var mX = getRound(mBounds[1],3);   

        var mY= getRound(mBounds[0],3);   

       

        // fit content

        if(mX == 10 && mY == 10){  

            mItem.fit(FitOptions.FILL_PROPORTIONALLY); 

        }

        if(mX == 6.999 && mY == 4.801){ 

            resizeItem(mItem, 240,340) 

            mItem.move([10, 10]); 

            mItem.fit(FitOptions.FILL_PROPORTIONALLY); 

        }   

    } 

    // restore measurement unit 

    app.scriptPreferences.measurementUnit = savedUnits; 

    // export PDF 

    var _PDFExportPreset = app.pdfExportPresets.item('MyJobOptionName');    

    if (_PDFExportPreset == null){ 

       alert('PDF Export Presets not found'); 

       exit(); 

    } 

    app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;                   

    doc.exportFile(ExportFormat.pdfType, _PDFfile, false,_PDFExportPreset); 

     

    /* round */   

    function getRound(number, digits) {   

            digits = (digits) ? Math.pow(10, digits) : 1000;     

            return Math.round(number * digits) / digits;     

    }  

    /* resize object */  

    function resizeItem(mItem, mWidth,mHeight) { 

        mBounds = mItem.geometricBounds; 

        mBounds[3] = mBounds[1] + mWidth; 

        mBounds[2] =mBounds[0] + mHeight; 

        mItem.geometricBounds = mBounds;  

    }