Skip to main content
action cheese
Participant
Nov 29, 2017 5:07 AM UTC
Answered

Does anybody have a script for resizing objects to round numbers?

I have a halftone from Phantasm but I need each dot to be a round number, ie 3mm, not 3.452mm. I've found scripts for rounding text sizes but I've been unsuccessful in adapting them to resizing multiple objects at once.

Does anybody have a solution?

Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
OMOTI
OMOTICorrect answer
Inspiring
Nov 29, 2017 12:47 PM UTC

If a halftone pattern is object like path item, the following script may help your work.

This changes the size of each selected object to an integer millimeter size. (with regarding group item as single object)

However, if dots are expressed by a pattern swatch, it does not run well as it is.

Please try it if you can.

(function () {

    var doc = app.activeDocument,

        sel = doc.selection,

        size,

        i,

        max;

   

    for (i = 0, max = sel.length; i < max; i += 1) {

        if (sel.hasOwnProperty("resize")) {

            size = Math.round(Number(new UnitValue(sel.width, "pt").as("mm")));

            size = new UnitValue(size, "mm").as("pt");

            sel.resize(size / sel.width * 100, size / sel.height * 100);

        }

    }

   

}());

13 replies

OMOTI
Inspiring
Nov 30, 2017 10:09 PM UTC

Are you kidding me? I think the professor Shilly-V has completely mastered. I'm sorry. I am not good at English, so I can not understand your intentions and nuances so much. Is it better not to use UnitValue?

Translate
Silly-V
Legend
Nov 30, 2017 11:16 PM UTC

No, I just never knew about it or used it. Just always hand-made conversion ratios.

Translate
CarlosCanto
Community Expert
Community Expert
Dec 2, 2017 9:06 PM UTC

really? where were you 8 years ago?

Re: I need a script, is it possible?

Translate
OMOTI
Inspiring
Nov 29, 2017 9:38 AM UTC

Hi.

I have a few questions.

Which target object is a plug-in item, a non-native item, a placed item, or else? If I know what type, I might be able to help you.

Would you like to resize the width and height to 3 mm?

Translate
action cheese
Participant
Nov 29, 2017 10:28 AM UTC

Hi,

The target objects will be circles generated by the Phantasm plugin.

Because it's a halftone pattern the dots are coming out at 5-10 different sizes, but they are all several decimal places long. I need whole numbers because I will be getting the designs turret punched​ and the circles need to match the die diameters which are whole numbers in metric sizes. Ideally I would like to be able to select all of the dots and have the sizes rounded to the nearest whole number.

I can supply a test file if needed when I get back to work tomorrow.

Translate
OMOTI
OMOTICorrect answer
Inspiring
Nov 29, 2017 12:47 PM UTC

If a halftone pattern is object like path item, the following script may help your work.

This changes the size of each selected object to an integer millimeter size. (with regarding group item as single object)

However, if dots are expressed by a pattern swatch, it does not run well as it is.

Please try it if you can.

(function () {

    var doc = app.activeDocument,

        sel = doc.selection,

        size,

        i,

        max;

   

    for (i = 0, max = sel.length; i < max; i += 1) {

        if (sel.hasOwnProperty("resize")) {

            size = Math.round(Number(new UnitValue(sel.width, "pt").as("mm")));

            size = new UnitValue(size, "mm").as("pt");

            sel.resize(size / sel.width * 100, size / sel.height * 100);

        }

    }

   

}());

Translate