Skip to main content
action cheese
Participant
November 29, 2017
Answered

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

  • November 29, 2017
  • 2 replies
  • 2939 views

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 has been closed for replies.
Correct answer OMOTI

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

        }

    }

   

}());

2 replies

OMOTI
Inspiring
November 30, 2017

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?

Silly-V
Legend
November 30, 2017

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

CarlosCanto
Community Expert
Community Expert
December 2, 2017

really? where were you 8 years ago?

Re: I need a script, is it possible?

OMOTI
Inspiring
November 29, 2017

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?

action cheese
Participant
November 29, 2017

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.

OMOTI
OMOTICorrect answer
Inspiring
November 29, 2017

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

        }

    }

   

}());