• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Previous scale tool settings

Participant ,
Apr 16, 2024 Apr 16, 2024

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.

TOPICS
Scripting

Views

269

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Apr 18, 2024 Apr 18, 2024

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
...

Votes

Translate

Translate
Adobe
Participant ,
Apr 17, 2024 Apr 17, 2024

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

// Graph Distortion Fix.jsx
// Script to re-size graph column designs after scaling
// Before running, create a rectangle 100pt x 100pt
// Scale graph and rectangle my identical amount
// Select rectangle (must be in front) and all pasted
// graph designs and run this script.

var myDoc = app.activeDocument;
var myElements = myDoc.selection;
var myRectangle = myElements.shift();
var myWidth = myRectangle.width;
var myHeight = myRectangle.height;
var myHScale = 10000/myWidth;
var myVScale = 10000/myHeight;

for (var i = 0; i < myElements.length; i ++) {
myElements[i].resize(myHScale,myVScale);
myElements[i].resize(myWidth,myWidth);
myRectangle.remove();
}

alert("Copy/paste plotted bounding box, select graph element, and run 'Scale Bar Widths.jsx'");
 
and the script to rescale the graph column designs:
 
// Scale Bar Widths.jsx
#target illustrator

// Script to re-size graph elements
main ();

function main () {
var myDoc = app.activeDocument;
var mySelection = myDoc.selection;
var myPathItems = [];
var myGroupItems = [];
var newWidth;
if (mySelection.length < 2) {
alert ("Not enough items selected\r\
You need a rectangle on top and one or more graph design elements below it\
(all selected).\n\
PROCESS:\r\
With the direct selection tool,\
option-click on the graph element bounding box.\n\
Copy, deselect the graph, and paste.\n\
Then shift select the graph designs with the normal selection tool and run the script again.");
return;
}
// Find path for bounding box
for (var i = 0; i<mySelection.length; i++) {
// alert (mySelection[i].typename);
switch (mySelection[i].typename) {
case "PathItem":
myPathItems.push(mySelection[i]);
break;
case "GroupItem":
myGroupItems.push(mySelection[i]);
break;
default:
}
}


if (myPathItems.length == 0) {
alert ("No bounding box path selected");
return;
} else if (myPathItems.length >1) {
alert ("Too many bounding box paths selected");
return;
} else {
newWidth = myPathItems[0].width;
};

if (myGroupItems.length == 0) {
alert ("No groups (graph design elements) selected");
return;
};

var boundingBoxWidth = myPathItems[0].width;
for (var i = 0; i < myGroupItems.length; i++) {
try {
var bottomItem = myGroupItems[i].pathItems.length -1;
var oldWidth = myGroupItems[i].pathItems[bottomItem].width;
var myWidth = newWidth/oldWidth*100
myGroupItems[i].pathItems[bottomItem].resize(myWidth,100.0);
} catch (e) {
}
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2024 Apr 18, 2024

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;

};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 18, 2024 Apr 18, 2024

Copy link to clipboard

Copied

LATEST

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");
}

  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines