Copy link to clipboard
Copied
Hi Scripters,
I would like to apply the same width/height to a selection of frames and distribute them in the original area!
To be a little clearer:
I select the four frames (above) and I would like to have the result below!
… I get this:
Yes! It seems to be good! Aha! … but not really!! I've an error message!
The code I've written is:
var myDoc = app.activeDocument;
var mySel = app.selection;
var myGroup = myDoc.groups.add(mySel);
var myGB = myGroup.geometricBounds;
myGroup.ungroup();
var myNewWidth = UnitValue('25mm').as('pt');
var myNewHeight = UnitValue('10mm').as('pt');
for (i = 0; i < mySel.length; i++) {
if (mySel.geometricBounds[1] == myGB[1]) mySel.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myNewWidth, myNewHeight]);
if (mySel.geometricBounds[3] == myGB[3]) mySel.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_RIGHT_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myNewWidth, myNewHeight]);
mySel.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myNewWidth, myNewHeight]);
}
myDoc.distribute(mySel, DistributeOptions.HORIZONTAL_SPACE, AlignDistributeBounds.ITEM_BOUNDS);
Thanks in advance!
(^/)
Copy link to clipboard
Copied
The problem doesn't seem to be linked to your code specifically but from the Rorohiko API implementation which weirdly you doesn't seem to call here.
Do you include it somewhere in the code ?
Plus, if you really want to be effective and error free, you should secure your code by avoiding reaching objects that may not be avalaile at some point.
var myDoc = app.activeDocument;
That relies on a existing document but you may run your script when there aren't any.
So you may prefer
function main() {
var doc;
if ( app.documents.length) return;
//Now you can go safe
doc = app.activeDocument;
//do something with doc
}
HTH
Copy link to clipboard
Copied
Hi Loic,
No real reason to run this script without open file!
… but you're right: no reason to run it without a selection!! … So [including an "undo!"]:
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Resize and Distribute! …");
function main()
{
var myDoc = app.activeDocument;
var mySel = app.selection;
if (mySel.length == 0) exit();
else {
var myGroup = myDoc.groups.add(mySel);
var myGB = myGroup.geometricBounds;
myGroup.ungroup();
var myNewWidth = UnitValue('25mm').as('pt');
var myNewHeight = UnitValue('10mm').as('pt');
for (i = 0; i < mySel.length; i++) {
if (mySel.geometricBounds[1] == myGB[1]) mySel.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myNewWidth, myNewHeight]);
if (mySel.geometricBounds[3] == myGB[3]) mySel.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_RIGHT_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myNewWidth, myNewHeight]);
mySel.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myNewWidth, myNewHeight]);
}
myDoc.distribute(mySel, DistributeOptions.HORIZONTAL_SPACE, AlignDistributeBounds.ITEM_BOUNDS);
}
}
However, I've the same error message!
(^/)
Copy link to clipboard
Copied
@@Hi,
Notice an error message:
Source: if(theNewLabel == "subscribe") ....
I cant see this line in provided code so make it clear first.
Jarek
Copy link to clipboard
Copied
Hi Jarek and Loic!
I've just discussed with Kris from Rorohiko!
The problem came from "PlaceAutoSynchronizer" plugin installed in the ID "Plug-Ins" folder, sub-folder "Rorohiko".
Kris told me to remove this plugin and the problem is fixed now!
Cool! No more error now! … That doesn't mean my script is … perfect!
But I keep learning! …
(^/)
Copy link to clipboard
Copied
No real reason to run this script without open file!
Ha ha ha . Well you may not work much with end users
I mean it's better to take good habits
Copy link to clipboard
Copied
Well! I know you're right! I read, especially here, so "nice" comments of users who really don't know how to use ID!
… and not only newbies! … So, I need to have good habits before they apply on a "pretty" button and trigger World War III by inadvertence! Knowledge give us Responsibility, as Uwe Laubender said once in another topic!
(^/)