Copy link to clipboard
Copied
Hi @r28071715i111 , here is a version that will scale in percentage :
/**
* Apply Scale to graphics with a "Scale" script label.
* eg. if label is "s:10", then the graphic will be scaled to 10%
* @Originally authored by m1b for roation version
* Updated Scale Version By M.Hasanin
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*/
function main() {
var doc = app.activeDocument,
images = doc.a
...
hi @r28071715i111 , here is another version as you asked me in private message that will scale and rotate in same time :
/**
* Apply Scale and Rotation to graphics script labels
* eg. if label is "r:30 s:10", then the graphic will be rotated to 30 degree and scaled to 10%
* @Originally authored by m1b for rotation version
* Updated Mixed Rotation and Scale Version By M.Hasanin
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data
...
Hi @M.Hasanin, thank you for doing this, very well done. Your scripting is going very well. As it happened (one minute later than you!) I was about to post a version of my same script that handled scaling also. I will post it here so you may see if I did anything differently.
- Mark
/**
* Apply scale and rotation to graphics according to their script label.
* eg. if label is "scale: 110, rotate: 15" then the graphic will be
* scaled to 110% and rotated to 15° counter-clockwise.
* @author m1b
...
Copy link to clipboard
Copied
Any Help here
Copy link to clipboard
Copied
It's a simple modification of the other script you've already received on the other thread about rotating objects - I'm not JS guy so can't help you but please ask there.
Copy link to clipboard
Copied
Thanks for your reply
I hope one one of js can help me in this script
Copy link to clipboard
Copied
Hello,
Yes, you can automate the process of scaling X and Y for each content graphic frame using a script. However, the exact script you need will depend on the software or website programming language you are using to work with these graphic frames.
If you are working with a graphic design software like Adobe Illustrator or Photoshop, you might be able to use their built-in scripting capabilities. Both applications support scripting using JavaScript. You can write a script that iterates through the graphic frames and applies the desired scaling percentage to each one.
Here's a general outline of how the script might work in JavaScript for Adobe Illustrator:
For Adobe Photoshop, the scripting process would be similar, but you would use Photoshop's JavaScript API to manipulate the graphic frames.
If you are working with a different software or a programming language, the approach might vary. Some graphic design software might have their own scripting languages or APIs to achieve similar results.
If you provide more details about the software you are using or the specific programming language you want to work with, I can try to help you with a more specific script example.
Copy link to clipboard
Copied
Thanks For Your great reply
I want script for Adobe indesign only
Not illustrator and photoshop
Copy link to clipboard
Copied
As I've already said - base of the script has been already created - just needs small modification:
Copy link to clipboard
Copied
Iam not a js , can't make modifcation for the script
If you can make this small modifcation please do it
Copy link to clipboard
Copied
My reply wasn't to your post.
I'll try.
Copy link to clipboard
Copied
Thanks For your reply
Copy link to clipboard
Copied
/**
* Apply rotation to graphics with a "rotate" script label.
* eg. if label is "rotate: 15", then the graphic will be
* rotated by 15° counter-clockwise.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*
* @MODIFIED Robert Tkaczyk
* Scale graphics with a "scale" script label.
* eg. if label is "scale:50", - no space after ":" - then the graphic will be
* scaled by 50%.
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-scale-selected-content-graphic-frame-data-merge/td-p/13956297
*/
function main() {
var doc = app.activeDocument,
// tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: 0 }),
tm = app.transformationMatrices.add({ horizontalScaleFactor: 1, verticalScaleFactor: 1 }),
images = doc.allGraphics,
// matcher = /^rotate:(-?\d+\.?\d*)/i,
matcher = /^scale:(-?\d+\.?\d*)/i,
label,
value;
for (var i = 0; i < images.length; i++) {
label = images[i].label || images[i].parent.label;
if (!label)
continue;
value = label.match(matcher);
if (!value
|| value.length < 2
|| isNaN(value = Number(value[1]))
)
continue;
images[i].transform(
CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor,
tm.scaleMatrix(value/100 ,value/100 ),
);
// tm.rotateMatrix(-images[i].absoluteRotationAngle + value),
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Rotate Graphics');
Copy link to clipboard
Copied
Thanks For your Reply
But When I tried it , Scaling Presentage is not correct
Copy link to clipboard
Copied
Like I've said - I'm not JS guy.
Version with setting scale directly - instead of using matrices - is much better.
Copy link to clipboard
Copied
Thanks for your effort and concern
Copy link to clipboard
Copied
Hi @r28071715i111 , here is a version that will scale in percentage :
/**
* Apply Scale to graphics with a "Scale" script label.
* eg. if label is "s:10", then the graphic will be scaled to 10%
* @Originally authored by m1b for roation version
* Updated Scale Version By M.Hasanin
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*/
function main() {
var doc = app.activeDocument,
images = doc.allGraphics,
matcher = /^s:(-?\d+\.?\d*)/i,
label,
value;
for (var i = 0; i < images.length; i++) {
label = images[i].label || images[i].parent.label;
if (!label)
continue;
value = label.match(matcher);
if (!value
|| value.length < 2
|| isNaN(value = Number(value[1]))
)
continue;
images[i].horizontalScale = images[i].verticalScale = value;
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Scale Graphics Percent');
Copy link to clipboard
Copied
Thanks For Great effort Mr Mohammad Hasanin
I tried it and worked like a charm
very very Thanks
Copy link to clipboard
Copied
hi @r28071715i111 , here is another version as you asked me in private message that will scale and rotate in same time :
/**
* Apply Scale and Rotation to graphics script labels
* eg. if label is "r:30 s:10", then the graphic will be rotated to 30 degree and scaled to 10%
* @Originally authored by m1b for rotation version
* Updated Mixed Rotation and Scale Version By M.Hasanin
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*/
function main() {
var doc = app.activeDocument,
tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: 0 }),
images = doc.allGraphics,
matcher = /^r:(-?\d+\.?\d*)\s+s:(-?\d+\.?\d*)/i, // match both values in one regex (Rotation and Scale with Space)
label,
value1,
value2;
for (var i = 0; i < images.length; i++) {
label = images[i].label || images[i].parent.label;
if (!label)
continue;
var matches = label.match(matcher);
if (!matches || matches.length < 3) // check for both values
continue;
value1 = Number(matches[1]); // set value1 to the first match Rotate
value2 = Number(matches[2]); // set value2 to the second match Scale Percentage
images[i].transform( //Roatation
CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor,
tm.rotateMatrix(-images[i].absoluteRotationAngle + value1),
);
images[i].horizontalScale = images[i].verticalScale = value2; //Scale Percentage
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Scale and Rotate Graphics');
Copy link to clipboard
Copied
Thanks For Great effort Mr Mohammad Hasanin
I also tried it and worked like a charm
That script that I need definitly
Thanks
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi @M.Hasanin, thank you for doing this, very well done. Your scripting is going very well. As it happened (one minute later than you!) I was about to post a version of my same script that handled scaling also. I will post it here so you may see if I did anything differently.
- Mark
/**
* Apply scale and rotation to graphics according to their script label.
* eg. if label is "scale: 110, rotate: 15" then the graphic will be
* scaled to 110% and rotated to 15° counter-clockwise.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*/
function main() {
var doc = app.activeDocument,
images = doc.allGraphics,
rotationMatcher = /\brotate:\s*(-?\d+\.?\d*)/i,
scaleMatcher = /\bscale:\s*(\d+\.?\d*)/i,
label,
scale,
rotation;
for (var i = 0; i < images.length; i++) {
label = images[i].label || images[i].parent.label;
if (!label)
continue;
rotation = label.match(rotationMatcher);
scale = label.match(scaleMatcher);
if (
!rotation
|| rotation.length < 2
|| isNaN(rotation = Number(rotation[1]))
)
rotation = undefined;
else
rotation -= images[i].absoluteRotationAngle;
if (
!scale
|| scale.length < 2
|| isNaN(scale = Number(scale[1]))
)
scale = undefined;
else
scale = scale / images[i].absoluteHorizontalScale;
if (!rotation && !scale)
continue;
var tm = app.transformationMatrices.add({
counterclockwiseRotationAngle: rotation,
horizontalScaleFactor: scale,
verticalScaleFactor: scale,
});
images[i].transform(
CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor,
tm,
);
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Transform Graphics');
Copy link to clipboard
Copied
Hi @m1b , your script is excellent also, thank you, very briliant idea from its base, cheers
Copy link to clipboard
Copied