Solved

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

Posted on 2011-02-18
2
1,714 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 article I share how to make a vector texture from a digital image. Vector textures are useful because they are scalable without losing in image quality. I'll be using Adobe Photoshop to adjust the highlights and contrast of a digital imag…
Make a selection using the pen tool to trace the selection. Then alter the color of the selection by using the color balance option in Adobe Photoshop.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now