Solved

How do I create Illustrator Script to resize image not based on percentage?

Posted on 2011-02-18
2
1,732 Views
Last Modified: 2012-05-11
I need a script that will resize a layer and if at all possible group all pageitems together before it resizes it. Or if there is a better way, please let me know. here is the script that I have currently. Right now it will resize the layer 50%, I need it to size based on "pt", I want the Height of all images ran through this script to be 100pt and the width to be proportionate to that.

try {
	if (app.documents.length == 0 ) {
		throw new Error('There are no document open!');
        }
	else{
        var docRef = app.activeDocument;
        var layerRef = docRef.layers[0];
        // now to resize based on the percentage
        layerRef.pageItems[0].resize(50,50);
    }
}
catch(e) {
	alert( e.message, "Script Alert", true);
}

Open in new window

0
Comment
Question by:agosselinelt
  • 2
2 Comments
 

Author Comment

by:agosselinelt
ID: 34930382
I have been able to modify my script to do what I need, but I still need to group the items before I can use it (ctrl+a then ctrl+g) then I run the script and everything is resized how I need. Is there a way I can script the grouping? Also here is my code for reference:

try {
	if (app.documents.length == 0 ) {
		throw new Error('There are no document open!');
        }
	else{
        var docRef = app.activeDocument;
        var layerRef = docRef.layers[0];
        // generate percentage from height
        var percRef = (100/layerRef.pageItems[0].height*100);
        // now to resize based on the percentage
        layerRef.pageItems[0].resize( percRef , percRef );
        alert( [percRef] );
    }
}
catch(e) {
	alert( e.message, "Script Alert", true);
}

Open in new window

0
 

Accepted Solution

by:
agosselinelt earned 0 total points
ID: 34930580
I have been able to group the items here is the full code:

try {
	if (app.documents.length == 0 ) {
		throw new Error('There are no document open!');
        }
	else{
        var docRef = app.activeDocument;
        var layerRef = docRef.layers[0];
        // group pageItems
        layerRef.hasSelectedArtwork=true;
        docSelection = app.activeDocument.selection;
        newGroup = app.activeDocument.groupItems.add();
        for ( i = 0; i < docSelection.length; i++ ) {
            newItem = docSelection[i];
            newItem.moveToBeginning( newGroup );
        }
        // generate percentage from height
        var percRef = (100/layerRef.pageItems[0].height*100);
        // now to resize based on the percentage
        layerRef.pageItems[0].resize( percRef , percRef );
        alert( [percRef] );
    }
}
catch(e) {
	alert( e.message, "Script Alert", true);
}

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
black magic design 1 128
Cutting a video file into multiple smaller clips. 6 59
Add server behaviors to Dreamweaver CC 2015 2 156
Converting dates in JavaScript 2 35
Because of still there more are people in the world using Adobe Illustrator older versions like CS & CS2 I wish to forward this article.. Since a long time Adobe Illustrator CS, CS2 has released, sometimes that there was a problem when someone tr…
In this article, I'll explain how to change the color of a selection in Photoshop. I'm sure there are a couple different ways to do this in photoshop, but this is my preferred method in Photoshop. I am using Photoshop CS6 and I will be adjusting the…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question