Copy link to clipboard
Copied
Hi, i found the code here, and was wondering why it doesn't affect the stroke width when run.
var selObj = app.selection;
app.transformPreferences.whenScaling = WhenScalingOptions.ADJUST_SCALING_PERCENTAGE;
for (i = 0; i < selObj.length; i++)
{
var myMatrix = app.transformationMatrices.add();
myMatrix = myMatrix.scaleMatrix (0.8,0.8);
selObj[i].transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.BOTTOM_RIGHT_ANCHOR, myMatrix);
}
app.transformPreferences.whenScaling = WhenScalingOptions.APPLY_TO_CONTENT;
ck_my said: "Is there a way to scale a stroked box with a script?"
Of course. It only depends what result you are wishing.
Would you like to see effectively a different stroke weight than the Stroke panel is nominal telling?
Sample below. One rectangle selected that has an nominal and effective stroke weight of 10 Pt:
After running my little script code the nominal stroke weight still is 10 Pt, but the effective stroke weight at top and bottom of the rectangle now is 20 Pt:
Why? Beca
...This is the modified script. Thank you Uwe, it wouldn't have been possible without your help. It needs a little more works, like group and ungrouping, the bounds of actual page (might not be necessary, since this is mostly for single page document). but the main issue has been addressed.
/**
* @@@BUILDINFO@@@ Scale-with-TransformationMatrix-ADJUST SCALING PERCENTAGE.jsx !Version! Wed Oct 13 2021 18:29:40 GMT+0200
*/
(function()
{
app.doScript
(
scaleSelectedObject ,
ScriptLanguage.JAVAS...
Copy link to clipboard
Copied
Never mind, i got this. it actually did scale it. When you clear the transformation, it shows the before size.
I got confused because the palette still show the same pt size.
Copy link to clipboard
Copied
My apology, i wasn't crazy.
The scaling script works with stroke but it doesn't work with frame that has a stroke applied. The stroke of the frame remains unchanged after scaling.
Copy link to clipboard
Copied
"The scaling script works with stroke but it doesn't work with frame that has a stroke applied."
So where is the stroke applied that actually is working?
NOTE: Also check what's assigned to adjustStrokeWeightWhenScaling in the transformPreferences of the application.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
A 10 pt stroke, when scaled with this script, it's 8 pt. even though in the Palette above it reads 10 pts. When you clear the transformation, the stroke changes back to 10 pt thickness.
But a picture frame with a 10 pt stroke will still be 10 pt, no matter if you scale it up or down.
If i scale it with the mouse, the stroke in the box scales correctly...
Ok, i got this.
With the ID pref > General > When Scaling > Apply to Content (both Include Stroke Weight and Include Effects checked) the stroke on the box is not scaling with the script.
But if I selet Adjust Scaling Percentage instead of Apply to Content, the stroke applied to the box is scaling with the script.
I have to play with it a little more. I can set the ID pref via the script and then revert it back, but I am not sure what the Adjust Scaling Percentage will do with Effects.
Copy link to clipboard
Copied
So Apply to Content (both Include Stroke Weight and Include Effects) is the preferred method, otherwise the drop shadow effects retain the original values at the new scaled size. This won't fly.
it seems the adjustStrokeWeightWhenScaling is not sticking when using a script, even when Scaling > Apply to Content (stroke weight and effects checked) is used.
Is there a way to scale a stroked box with a script? It's not the end of the world, this can be done manually with the mouse or with the palette.
Copy link to clipboard
Copied
ck_my said: "Is there a way to scale a stroked box with a script?"
Of course. It only depends what result you are wishing.
Would you like to see effectively a different stroke weight than the Stroke panel is nominal telling?
Sample below. One rectangle selected that has an nominal and effective stroke weight of 10 Pt:
After running my little script code the nominal stroke weight still is 10 Pt, but the effective stroke weight at top and bottom of the rectangle now is 20 Pt:
Why? Because I scaled unproportionally with InDesign's preferences for scaling set to:
ADJUST_SCALING_PERCENTAGE
/**
* @@@BUILDINFO@@@ Scale-with-TransformationMatrix-ADJUST SCALING PERCENTAGE.jsx !Version! Wed Oct 13 2021 18:29:40 GMT+0200
*/
(function()
{
app.doScript
(
scaleSelectedObject ,
ScriptLanguage.JAVASCRIPT ,
[],
UndoModes.ENTIRE_SCRIPT ,
"SCRIPT | Scale Selected Object with ADJUST_SCALING_PERCENTAGE"
);
function scaleSelectedObject()
{
var whenScalingProps = app.transformPreferences.properties;
/* ALLOWS TO SCALE A STROKE UNPROPORTIONALLY */
app.transformPreferences.properties =
{
whenScaling : WhenScalingOptions.ADJUST_SCALING_PERCENTAGE
};
/* NOTE: WE DO NOT SCALE PROPORTIONALLY HERE IN x AND y DIRECTION */
var myMatrix = app.transformationMatrices.add();
myMatrix = myMatrix.scaleMatrix( 1 , 2 );
/* OPTIONAL FOR COMPARISON ONLY */
var dup = app.selection[0].duplicate();
dup.strokeTint = 30;
dup.strokeTransparencySettings.properties =
{
blendingSettings :
{
blendMode : BlendMode.NORMAL ,
opacity : 50
}
}
/* TRANSFORM THE SELECTED OBJECT */
app.selection[0].transform
(
CoordinateSpaces.INNER_COORDINATES ,
AnchorPoint.BOTTOM_RIGHT_ANCHOR ,
myMatrix
);
app.transformPreferences.properties = whenScalingProps;
};
}());
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
hi Uwe, i know that setting pref to ADJUST_SCALING_PERCENTAGE will scale the stroke of a frame correctly with the script. But in a real life scenario, a stroke frame might not be the only object in a group that needs to be resized. There are other objects that has effects applied.
So the ideal pref to use is APPLY_TO_CONTENT (both Stroke Weight and Include Effects checked). If this is done manually with the mouse/drag, everything scaled correctly, including the effects and the stroke in the frame. But somehow, with the script, it is not honoring the application preference.
With your script, actually I found the solution by changing the pref to APPLY_TO_CONTENT.
whenScaling : WhenScalingOptions.APPLY_TO_CONTENT
my next question is how to use APPLY_TO_CONTENT when using
Copy link to clipboard
Copied
Provide a sample document with some items you want to scale.
Duplicate the spread with the objects and scale them through the UI so we have an idea what you like to achieve.
Also provide some screenshots with your results when you do this per script so we can compare them to the desired results.
Put the InDesign document on Dropbox or a similar service and post the download link.
Thanks,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Uwe, take this code, it scales a group of objects proportionally to the width of the document.
var doc = app.activeDocument,
sel = app.selection[0],
w = doc.documentPreferences.pageWidth,
h = doc.documentPreferences.pageHeight;
app.transformPreferences.whenScaling = WhenScalingOptions.APPLY_TO_CONTENT;
// app.transformPreferences.whenScaling = WhenScalingOptions.ADJUST_SCALING_PERCENTAGE;
var currscale = sel.horizontalScale;
selwidth = sel.geometricBounds[3]-sel.geometricBounds[1];
sel.verticalScale = sel.horizontalScale = (((w - selwidth)/selwidth) * currscale) + currscale;
selheight = sel.geometricBounds[2]-sel.geometricBounds[0];
When pref APPLY_TO_CONTENT is used. The width of the stroked frame is not scaled correctly.
When the pref ADJUST_SCALING_PERCENTAGE is used, the stroke on a frame scales but not the effect.
Your script actually works with APPLY_TO_CONTENT, but it's written using a different method.
The idea is to select a group of objects, group it first, scaled it to the width of the document, maintaining the proportion, then ungroup it.
Copy link to clipboard
Copied
idml and the script are here.
https://www.webcargo.net/l/sShsVN3zSq/
Copy link to clipboard
Copied
Alright. Please attach the InDesign document with the "baseline" page.
I'll see into this…
EDIT: OK. You already posted a link. Thanks!
Thanks,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thanks for the link!
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hm. Tested your code and I can see the issue clearly.
I think, you discovered a bug. Maybe even two of them!
First and obvious bug:
app.transformPreferences.adjustStrokeWeightWhenScaling
will result in the same for both possible values, true or false.
Second not so obvious bug:
After scaling the text frame with the applied stroke the frame's inset values changed from 0 to 10 Points * the scaling factor of the frame of 1.4305524541913383. That's exactly that part of the stroke's weight that is missing:
Zoomed in and added a yellow rectangle to show the desired and expected stroke weight:
Well, I have to think about this strange result…
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
hi Uwe, your script actually works when the pref is set to APPLY_TO_CONTENT, but it's using scaleMatrix vs. horizontalScale/verticalScale. I just need to somehow merge the two and use scaleMatrix.
Thank you for your time, at your leisure. Cheers.
Copy link to clipboard
Copied
Hi ck_ny,
the following code is working as expected. Don't know why you think, that you need a different method. Just use scaleMatrix and you are good to go:
/**
* @@@BUILDINFO@@@ Scale-with-TransformationMatrix-APPLY TO CONTENT.jsx !Version! Thu Oct 14 2021 19:44:08 GMT+0200
*/
(function()
{
app.doScript
(
scaleSelectedObject ,
ScriptLanguage.JAVASCRIPT ,
[],
UndoModes.ENTIRE_SCRIPT ,
"SCRIPT | Scale Selected Object with APPLY_TO_CONTENT"
);
function scaleSelectedObject()
{
var whenScalingProps = app.transformPreferences.properties;
/* ALLOWS TO SCALE A STROKE UNPROPORTIONALLY */
app.transformPreferences.properties =
{
whenScaling : WhenScalingOptions.APPLY_TO_CONTENT
};
/* NOTE: TEST WITH PROPORTIONAL SCALING to 200 % */
var myMatrix = app.transformationMatrices.add();
myMatrix = myMatrix.scaleMatrix( 2 , 2 );
/* TRANSFORM THE SELECTED OBJECT */
app.selection[0].transform
(
CoordinateSpaces.INNER_COORDINATES ,
AnchorPoint.CENTER_ANCHOR ,
myMatrix
);
app.transformPreferences.properties = whenScalingProps;
};
}());
Result:
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
hi Uwe,
Because i need to resize the group to the width of a document, not to a fixed percentage.
In your script, the resize is 200%, but a selected group in relation to any page size, could be any percentage.
Copy link to clipboard
Copied
Three notes:
[1] Always build a new group, even if there is only one object and that could even be a group; just add an empty frame on top of the single object and group the two objects to avoid issues with rotated and sheared group objects.
[2] To calculate the width of your final group you want to scale, do not use the geometricBounds, but the visibleBounds in case the stroke position on the outer object(s) is set to outside or center.
[3] Get the factor for scaling with scalingMatrix by using the bounds of the actual page and the dimensions, width or height, of the group. Before check if the page is portrait or landscape. Why? The document could contain different page sizes.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
I was just thinking about it, I need to get the width of the page and divide it by the geometricBounds or visibleBounds of the selected group to get the percentage, i will look up the rule of three. Thank you for your time and insights. Very much appreciated.
Copy link to clipboard
Copied
Calculating the scaling factor is a simple thing with a rule of three.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
This is the modified script. Thank you Uwe, it wouldn't have been possible without your help. It needs a little more works, like group and ungrouping, the bounds of actual page (might not be necessary, since this is mostly for single page document). but the main issue has been addressed.
/**
* @@@BUILDINFO@@@ Scale-with-TransformationMatrix-ADJUST SCALING PERCENTAGE.jsx !Version! Wed Oct 13 2021 18:29:40 GMT+0200
*/
(function()
{
app.doScript
(
scaleSelectedObject ,
ScriptLanguage.JAVASCRIPT ,
[],
UndoModes.ENTIRE_SCRIPT ,
"SCRIPT | Scale Selected Object with ADJUST_SCALING_PERCENTAGE"
);
function scaleSelectedObject()
{
// get width of the
var doc = app.activeDocument;
w = doc.documentPreferences.pageWidth;
// get width of group
var gb = doc.selection[0].visibleBounds;
var groupWidth = gb[3] - gb[1]
var whenScalingProps = app.transformPreferences.properties;
/* ALLOWS TO SCALE EFFECTS AND STROKE*/
app.transformPreferences.properties =
{
whenScaling : WhenScalingOptions.APPLY_TO_CONTENT
};
/* THE WIDTH OF PAGE DIVIDED BY THE WIDTH OF THE GROUP */
var myMatrix = app.transformationMatrices.add();
myMatrix = myMatrix.scaleMatrix( w/groupWidth,w/groupWidth );
/* TRANSFORM THE SELECTED OBJECT */
app.selection[0].transform
(
CoordinateSpaces.INNER_COORDINATES ,
AnchorPoint.BOTTOM_RIGHT_ANCHOR ,
myMatrix
);
app.transformPreferences.properties = whenScalingProps;
};
}());
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more