Copy link to clipboard
Copied
I have been struggling to find a way to do the following in javascript:
1) Open an .ai file that contains a shape (in this case its a warped rectangle)
2) Place a PNG file
3) Move the PNG file below the warped shape
4) Perform an envelope distort (Make with Top Object) on the shape + PNG file
This seems stupid simple, but I can't figure out a way to do the Make with Top Object envelope distort using javascript.
Any help would be amazing.
Thanks!
Copy link to clipboard
Copied
Hello!
Copy link to clipboard
Copied
Yes, use them all the time. But I need a javascript solution. This is part of a suite of tools that I have built in Javascript to sit on top of illustrator to automate a ton of our work.
Thanks
Copy link to clipboard
Copied
Here's a JavaScript script for Adobe Illustrator that accomplishes those tasks. The key is using the envelopeDistort method for the "Make with Top Object" functionality:
javascript
// Get the active document
var doc = app.activeDocument;
// 1. Open .ai file - assuming it's already open for this script
// If you need to open it programmatically:
// app.open(File("/path/to/your/file.ai"));
// 2. Place PNG file
var pngFile = new File("/path/to/your/image.png");
var placedItem = doc.placedItems.add();
placedItem.file = pngFile;
// 3. Move PNG below the warped shape
// Assuming the warped rectangle is the topmost path item
var warpedShape = doc.pathItems[0];
placedItem.move(warpedShape, ElementPlacement.PLACEBELOW);
// 4. Perform Envelope Distort (Make with Top Object)
// Select both items
warpedShape.selected = true;
placedItem.selected = true;
// Create envelope distort
app.executeMenuCommand("Make Envelope");
Key notes:
Replace "/path/to/your/image.png" with the actual PNG file path
The script assumes the warped rectangle is the topmost path item
executeMenuCommand("Make Envelope") is equivalent to "Make with Top Object"
Make sure both items are selected before the envelope distort
Run this in Adobe Illustrator's ExtendScript Toolkit or as a .jsx file
If the .ai file isn't open, uncomment the app.open() line and provide the correct path. Let me know if you need help with file paths or error handling!