Copy link to clipboard
Copied
Good evening everyone:
My script, opens a PNG file and reads its contents. Then the script opens another file (Mockup_001.ai) and pastes the PNG file. The problem now is that I need this PNG image to be in a certain position and with a certain size. How to proceed? Follow the script...
Thanks for any suggestion.
var filePng = "C:\\Temp\\PNG.png";
var fileMockup = "C:\\Temp\\Mockup_001.ai";
var docPng=app.open(File(filePng));
var newItem;
var copiaPNG = app.activeDocument.selection;
mockup = app.open(File(fileMockup));
if (copiaPNG.length > 0) {
for(var i=0; i<copiaPNG.length; i++){
copiaPNG[i].selected = false;
newItem = copiaPNG[i].duplicate(mockup, ElementPlacement.PLACEATBEGINNING);
}
}
opening the png file and copying it to the mockup file is not very efficient. I would open the mockup file and "place" (import) the png file instead
var filePng = "C:\\Temp\\PNG.png";
var fileMockup = "C:\\Temp\\Mockup_001.ai";
var mockup = app.open(File(fileMockup));
var placedPng = mockup.placedItems.add();
placedPng.file = File(filePng);
// you need to figure out the right size and placement;
placedPng.width = 200;
placedPng.height = 300;
placedPng.position = [50, -30];
Adding more what @CarlosCanto suggested, Another way to resize the item can be using the scale factor
var newItem = app.selection[0];
var scaleFactor = 0.25;
newItem.resize(scaleFactor * 100, scaleFactor * 100, true);
newItem.position = new Array(0,0);
The above snippet, will resize the selected item by 25% and will position at x=0 and y=0.
Copy link to clipboard
Copied
opening the png file and copying it to the mockup file is not very efficient. I would open the mockup file and "place" (import) the png file instead
var filePng = "C:\\Temp\\PNG.png";
var fileMockup = "C:\\Temp\\Mockup_001.ai";
var mockup = app.open(File(fileMockup));
var placedPng = mockup.placedItems.add();
placedPng.file = File(filePng);
// you need to figure out the right size and placement;
placedPng.width = 200;
placedPng.height = 300;
placedPng.position = [50, -30];
Copy link to clipboard
Copied
Adding more what @CarlosCanto suggested, Another way to resize the item can be using the scale factor
var newItem = app.selection[0];
var scaleFactor = 0.25;
newItem.resize(scaleFactor * 100, scaleFactor * 100, true);
newItem.position = new Array(0,0);
The above snippet, will resize the selected item by 25% and will position at x=0 and y=0.