Sg2.9
bounding box generator /surfa...
Recent RSS
bounding box generator /surface calculator
From:  timbre
Date:  1. June 2010, 20:30

Hi, does anyone have a script that returns an editable/printable bounding box from a selection of objects ?

Also im looking for a script that selects objects based on identical fill or stroke color, then
calculates bounding box surface area in square cm, and with option to multiply the result with a user given constant value.

It is for calculating the cost of flexo print plates, since their size (thus cost) is directly related to the total surface per spot color used in a document.

made a schematic to clarify :

picture here

Re: bounding box generator /surface calculator
Date:  2. June 2010, 18:13

Let me help you along. This code does not check stroke color and also not if the path is visible (not covered by another path). I think both of these things are unneeded, since you will need to flatten the document anyway for printing.

It now returns the color and the square point area.. you can figure out how to convert to square cm..

// get all visible path items in the document
var items = document.getItems({
	type: Path,
	hidden: false
});

for(var i = 0; i < items.length; i++) {
	var item = items[i];
	if(item && item.fillColor) {
		var rect = item.bounds.clone();
		for(var j = 0; j < items.length; j++) {
			if(i != j) {
				var checkItem = items[j];
				if(checkItem && checkItem.fillColor == item.fillColor) {
					// add its bounds to the rect
					rect = rect.unite(checkItem.bounds);
					// nullify, so we don't check it again later
					items[j] = null;
				}
			}
		}

		print(item.fillColor, rect.width * rect.height + ' square pt');

		var path = new Path.Rectangle(rect);
		path.strokeColor = item.fillColor;
		path.fillColor = null;
	}
}
Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Grid Generator 04.01.12