Script to scale by area... or script to scale everyting to have the same area





I need a script to scale objects to the same area, in this case 4 sqaure inches. Find the area, reduce to square root, dicive 2 by that number and use that number to scale the object up or down. I've done a hundred or so and have soemthing 1700 left to go. Automating would be a big help.
4th attempt! Now handles GroupItems. Feel free to ignore attempt 3, I've left it just for learning purposes. There are two ways you may want to handle groups: 1) calculate area for each individual item inside the group, or 2) calculate the aggregate area of all the grouped items. If you want option 2) just comment out the itemsInsideGroupItems line.

 

Just for fun I also changed the way the parameters work for specifying the target area value and unit. I put them in a string. Example values are: '4 square inches', '4in','4 sq inch' will give same result. Other examples are:'100mm', '800 pt'. If the parameter is a number, not a string, it will be interpreted as points.

 

 


```
// start with the selected items
var items = app.activeDocument.selection;

// comment out the following line if you want each groups' area to be calculated, rather than the items inside each group individually
items = itemsInsideGroupItems(items);

// this is where you specify your target size ()
scaleItemsToArea(items, '4 square inches');

function scaleItemsToArea(items, targetString) {
    // very simple parsing of targetString
    targetString = String (targetString);
    var targetAreaInSquareUnits = Number(targetString.match(/\d+/)[0]);
    var unitType;
    // note: only looks for 'in' or 'mm'
    if (targetString.search(/(in|\")/) > -1) {
        unitType = 'in';
    } else if (targetString.search(/mm/) > -1) {
        unitType = 'mm';
    } else {
        unitType = 'pt'
    }
    // scale each item
    for (var i = 0; i < items.length; i++) {
        scaleToArea(items[i], targetAreaInSquareUnits, unitType);
    }
}
function scaleToArea(item, targetAreaInSquareUnits, unitType) {
    var itemAreaInSquareUnits = areaOfItem(item, unitType);
    var scaleFactor = (Math.sqrt(targetAreaInSquareUnits / itemAreaInSquareUnits)) * 100;
    if (scaleFactor != NaN) {
        item.resize(scaleFactor, scaleFactor);
    }
}
function areaOfItem(item, unitType) {
    var itemAreaInSquareUnits;
    var itemAreaInSquarePoints = areaOfItemInSquarePoints(item);
    if (unitType == 'in') {
        var ptsIn1inch = 72;
        itemAreaInSquareUnits = itemAreaInSquarePoints / (ptsIn1inch * ptsIn1inch);
    } else if (unitType == 'mm') {
        var ptsIn1mm = 2.834645669;
        itemAreaInSquareUnits = itemAreaInSquarePoints / (ptsIn1mm * ptsIn1mm);
    } else {
        // no unitType specified, use points
        itemAreaInSquareUnits = itemAreaInSquarePoints;
    }
    return itemAreaInSquareUnits;
}
function areaOfItemInSquarePoints(item) {
    var area = 0;
    if (item.typename == 'PathItem') {
        area = item.area;
    } else if (item.typename == 'CompoundPathItem') {
        for (var j = 0; j < item.pathItems.length; j++) {
            area += item.pathItems[j].area;
            // $.writeln('item.pathItems[j].area = ' + item.pathItems[j].area + '     area = ' + area);
        }
    } else if (item.typename == 'GroupItem') {
        for (var j = 0; j < item.pageItems.length; j++) {
            area += areaOfItemInSquarePoints(item.pageItems[j]);
            // $.writeln('item.pathItems[j].area = ' + item.pathItems[j].area + '     area = ' + area);
        }
    } else {
        // for other types of items, resort to width x height
        area = item.width * item.height;
    }
    return Math.abs(Math.round(area * 10000) / 10000);
}
function itemsInsideGroupItems(items) {
    // returns an array containing items, including items found inside GroupItems
    try {
        var found = [];
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.typename == 'GroupItem') {
                found = found.concat(itemsInsideGroupItems(item.pageItems));
            } else {
                found.push(item);
            }
        }
        return found;
    } catch (e) {
        return found;
    }
}
```
 

 

As usual, not much testing done, so please let me know if it works as you'd expect. - Mark
you don't say that the area must be a rectangle. the true largest area would be a circle, with the circumference equal to 400m and the area would be 12,732.4 m^2. however, evidently, the area is restricted to a rectangle, in which case the maximum area is a square, and the side of the square will be 
400/4 = 100 m. the area is 100x100 = 10,000 m^2.
algebraically,
let x = one pair of opposite sides
(400-2x)/2 = 200-x = the other pair of opposite sides

area = a(x) = x(200 - x) = -x^2 + 200x
x-coordinate of vertex = -b/2a = 200/2 = 100
a(100) = 10,000

that's it! ;) the straight distance between two place on a map can be measured by a strip of paper and divider.use a ruler to measure the distance between the two places. if the line is quite curved, use a string to determine the distance, and then measure the string. find the scale for the map you're going to use. it might be a ruler bar scale or a written scale, in words or numbers. you could use kangaroo, but i don’t think it’s needed here.

instead i’d use inverse distance weighting to make a height field like this.

[sharp\_curves.gh](/uploads/short-url/a5wdkm9xiiwabwl6s0jpgf6ry7j.gh) (11.4 kb)

[[image]](https://aws1.discourse-cdn.com/mcneel/uploads/default/original/3x/d/c/dc85a5f42096a341409c4b4727a7d5066bd68745.png "image.png")

the key step here is making a mesh with vertices on the curves you want to keep sharp. one way of doing this is to split a s… 18 sq.units explanation: x2 = 12y ∴ 4b = 12 ∴ b = 3 area of triangle = `1/2 xx "ab" xx "os"` = `1/2 xx 4"a" xx "a"` = `1/2(12)(3)` = 18 sq. units I used [an automatic photoshop script](http://arnaumarch.com/en/sprites.html) once and worked well.


The concept is : 


* Each portion is a different image.
* Each portion (and so, each images) must be in the same folder w/o any other images.
* Run the script indicating the folder and some parameters (size, css name, etc...).
* The script does : 


	1. Merge all images into one with the size you indicated.
	2. Generate the CSS file


In your case, if you modify one image, you regenerate the global image and the CSS via the script and... that's it. Maybe you'll need to copy/paste the CSS in yours if you don't want to use the generated one.


Notes :


I tried it with a few files and worked great. Then, I tried like ~600 pictures and then, you'll need a goooood CPU and patience ;) In this case, don't use it. solution: `1 + omega + omega^2 = 0`   

`z, z omega , z + z omega`   

`z , z omega , z(1 + omega)`   

`z , z omega , - z omega^2 `   

area `/\_ abc= 1/2 xx b xxh `   

`1/2 xx ab xx od`   

`1/2 xx 1 xx sqrt3/2 = sqrt3/4`   

so `1, omega , -omega^2`   

`z, z omega , - z omega^2 `   

area = `|z|^2 xx sqrt3/4 = 4/sqrt3`   

`|z|^2 = 16/3`   

`|z| = 4/ sqrt3`   

answer given;y-axis, y = cos x and y = sin x, 0 ≤ x ≤ π/2⇒ sin x = cos xrequired area= (√2 − 1) sq.units given the boundaries of the area to be found are,• the curve • the x-axis• x = 0 (y-axis)• x = 4 (a line parallel toy-axis)as per the given boundaries,• the curve,is a curve with vertex at .• x=2 is parallel toy-axis at 2 units away from the y-axis.• x=0 is the y-axis.• the four boundaries of the region to be found are,•point a, where the curve y2 = 6x + 4 and x=0 meet.•point b, where the curve y2 = 6x + 4 and x=2 meet.•point c, where the x-axis and x=2 meet i.e. c(2,0).•point o, or the origin i.e. o(0,0).area of the required region = area of oabc.[using the formula ]the area of the required region double click in the figure to bring up the property inspector. make sure the units property is "pixels". then in the position property (expand it to see width and height), type in 900 for the width, and 100 for the height. if that still doesn't work, make sure the resize property is set to "on". if i get this right you are trying to sweep1 circle and have the sweeps come to a point.

if that be the case, you either need to have the sweep paths cross and go far enough past each other to come to a point (at right) or you can place the cross section on the inside of the sweep path rather than …