Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
adobe error 2 93
Illustrator CS5 under Yosemite 1 74
hide show div element in asp.net 3 74
Adobe Audition with VAC 2 66
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 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 tutorial viewers will learn how to increase their history states in Photoshop To undo more than one history state, use Ctrl + Alt + Z, not just Ctrl + Z: View the History window by going to Window > History: The default number of history sta…
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…

743 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