Copy link to clipboard
Copied
Is there any way to get scale settings just used with the scale tool into a script for processing other objects?
Because Illustrator graphs cannot be re-sized without distorting applied graph elements, it would be great to get the scaling factors just used, and reverse the scaling on a coppy of the graph elements so that when these are applied in the scaled graph the elements now look correct. I currently do this now by using the scale tool to re-size the graph to my desired size. Then I select the graph element/s I want to re-scale and double click on the scale tool to see the settings previously used. in each of the scale boxes I add 10000/ in front of each of the percentages and this creates the reverse scalng needed. Then I lock the width and height of each element and set the width back to the original element width.
Scripting this scaling is very easy but how do I get the original scale values automatically?
PS. I set paragraph styles for the value axis and category axis text styles and simply reapply them after the graph has been transformed. Works like a charm.
Thanks again @m1b
Here is the single script solution after your scaling suggestion.
Create a graph in Illustrator with column designs.
Create paragraph styles for the Axis styles (to re-apply after re-sizing)
Re-size the graph using the scale tool (so scaling is done in both directions at once)
Paste the graph column designs (Object>Graph>Design...)
Run the script
Re-define the column designs from the newly scaled elements
/*
=========================================================================
Gra
...
Copy link to clipboard
Copied
Have a script workaround. If I create a square that is 100pt x 100pt and scale it along with my graph, the new dimensions of the square will be the percentages I need to re-scale the graph design elements. The whole process takes literally minutes to complete. After both scripts have been run, just redefine the graph designs from the newly scaled graph designs. The first script requires the scaled square to be in front (will probably still add logic to handle it if it is at the back instead). Also, I use paragraph styles for the vertical and horizontal axis labels and remove the overrides from these after scaling the graph. Here are my scripts:
#target illustrator
Copy link to clipboard
Copied
Hi @Tim Sheasby, I sort of know what you are doing, but it would help a lot if you could share a simplified demo file with a step-by-step explanation of how you got there.
Or... does this script help at all? It derives the last-used transform by using the "Transform Again" feature on a unit square. If that doesn't help, the demo file and step-by-step would be a great help.
- Mark
/**
* @author m1b
*/
(function () {
var scale = getLastTransformScale(app.activeDocument);
alert(scale.join('%, ') + '%');
})();
/**
* Returns the scale associated with the 'transform again' function.
* @param {Document} doc - an Illustrator Document.
* @returns {Array<Number>} - [scaleX%, scaleY%]
*/
function getLastTransformScale(doc) {
var sel = doc.selection,
scale = [],
size = 100,
square = doc.pathItems.rectangle(0, 0, size, size); // TLWH
doc.selection = [square];
app.executeMenuCommand('transformagain');
square = doc.selection[0];
scale[0] = Math.round(square.width / size * 100 * 1000) / 1000;
scale[1] = Math.round(square.height / size * 100 * 1000) / 1000;
square.remove();
doc.selection = sel;
return scale;
};
Copy link to clipboard
Copied
Thanks again @m1b
Here is the single script solution after your scaling suggestion.
Create a graph in Illustrator with column designs.
Create paragraph styles for the Axis styles (to re-apply after re-sizing)
Re-size the graph using the scale tool (so scaling is done in both directions at once)
Paste the graph column designs (Object>Graph>Design...)
Run the script
Re-define the column designs from the newly scaled elements
/*
=========================================================================
Graph Column Fix.jsx
=========================================================================
Author: Tim Sheasby
Date: 18 April 2024
Version: 0.1
Thanks: Thanks to m1b on the Adobe Community for help with getting
the previous scale by drawing a unit square and running the
"transformagain" menu command to retrieve the settings.
For use where you need to re-scale graph design elements after
re-sizing a graph.
1. Scale the graph
2. Paste graph elements used in the graph
3. Run this script
4. Redefine the graph elements
=========================================================================
*/
if (app.activeDocument.selection) {
var myDoc = app.activeDocument;
var myElements = myDoc.selection;
// Get previous scale factors
var myScaleRect = myDoc.pathItems.rectangle(0,0,100,100);
myDoc.selection = [myScaleRect];
app.executeMenuCommand("transformagain");
alert (myDoc.selection[0].width);
var myHScale = 100/myDoc.selection[0].width;
var myVScale = 100/myDoc.selection[0].height;
var newBoundWidth = myDoc.selection[0].width;
myDoc.selection[0].remove();
// Scale the graph designs
alert ("ScaleFactors:\n" + myHScale + "\n" + myVScale + "\n" + newBoundWidth);
for (var i = 0; i < myElements.length; i ++) {
if (myElements[i].typename == "GroupItem") {
// var myWidth = myElements[i].width;
var theGroup = myElements[i];
theGroup.height *= myVScale;
theGroup.width *= myHScale;
try {
var bottomItem = theGroup.pathItems.length -1;
theGroup.pathItems[bottomItem].resize(newBoundWidth,100.0);
} catch (e) {
}
}
}
alert("Redefine the graph elements");
}