Solved

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

Posted on 2011-02-18
2
1,819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction When sharing photos, especially via e-mail, the large resolution images that most cameras take today make for extremely large file sizes. The time required to upload these files to forums, send in e-mails, post to blogs or even placi…
In this article, I’ll explain how I make a clipping mask out of several separate vector objects by using the Compound Path option in Adobe Illustrator. A compound path in Illustrator allows grouping of separate objects into one set of vector paths t…
In this tutorial viewers will learn how to apply a non-rasterized, vector-scalable texture to a vector using opacity texture masks in Illustrator Open a vector in Illustrator. Black and white vectors work best, but this effect can also be used to ad…
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.

724 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