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

Need help with my icon design workflow. Scaling artwork to fit its parent artboad and center.

Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

I commonly need to export icons at a specific size (usually 16x16px). My typical starting point looks like this (I usually have more icons, but I've simplified things for the sake of this example):

Scenario 1.png

 

Since I can't find a plugin or script that both resizes artwork to a bounding box of [n x n] (where "n" is an arbitrary pixel size WHILE maintaining each icon's aspect ratio) and then arranges each item in a grid - I do it all manaully. I just drag each icon roughly within each of my predefined artboards. This leaves me here after a minute or two of dragging:

Scenario 2.png

 
Once I've gotten to this point, I use an action that centers a selected object to its parent artboard. I've set the hotkey to F2 so I can rapid fire. Click on icon > F2, Click on icon > F2, Etc. Repeat until all icons are centered.

Lastly, since some of the icons are smaller than my 16x16 artboards, I have to scale them to fit perfectly within the bounds of each artboard. Again since I don't have a working script that fits selected artwork to its artboard without aspect ratio distortion, I do this all manaully. After all this is done, I finally end up here:

Scenario 3 - Final.png

 


So after outlining my current workflow, I am looking for any of the following:

1. A working JSX that will resize all selected objects to a bounding box of my input (I.E. 16x16, 32x32, 64x64 etc.) without breaking aspect ratio.
2. A working JSX that will scale up (or down) selected artwork to fit its parent artboard without breaking aspect ratio.
3. A working script that will center each individual icon (in one run of the script) within its parent artboard (to be performed after the resize)
4. Bonus points for a script that will roghly align each icon to a grid so I spend less time separating imported icons.
5. Any other tips or suggestions on how to streamline this workflow would be hugely appreciated!


Scripts I've tried:

 

Sorry that this post is extremely long, but I really want to find better solutions. My current workflow is unnecessarily tedious and I'm sure there are scripts or plugins that can help.

Thank you generously for any tips, scripts, guidance, or general help!

Jay

TOPICS
Scripting , Third party plugins , Tools

Views

542

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

Enthusiast , Jul 22, 2022 Jul 22, 2022

It's absolutely free. I don't think you can donate to me, because I live in a sanctioned country 🙂 
https://github.com/creold/illustrator-scripts/blob/master/jsx/FitSelectionToArtboards.jsx
FitSelectionToArtboards.gif

Votes

Translate

Translate
Adobe
Guide ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Are the icons symbols? 

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 ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Nope, just imported SVG files. A lot of times I need to convert various SVGs to a unified artboard size.

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
Enthusiast ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

I made a similar script at the request of a client. One by one, the object is taken from the selection and fit to the artboards. If the amount of artboards is less than the amount of objects, the script will terminate. The script still needs some work, so I haven't posted it on GitHub yet

FitSelectionToArtboards.gif

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 ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

@Sergey OsokinHoly moly! That is EXACTLY what I am trying to do. If there is any way you could share your script with me, I would be eternally grateful. I'll pay you for it if you're up for it.

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
Enthusiast ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

It's absolutely free. I don't think you can donate to me, because I live in a sanctioned country 🙂 
https://github.com/creold/illustrator-scripts/blob/master/jsx/FitSelectionToArtboards.jsx
FitSelectionToArtboards.gif

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 ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

Dude, you are a lifesaver. The script works flawlessly. This is going to save me some serious time.

I know beggars can't be choosers - but I'm going to attempt to break that rule: Is there any possible way in the universe you can make a more simplified version of the script that just operates on one item? Basically:

1. You have an icon / artwork in an artboard, but it's not centered or scaled correctly.

2. So you select that icon and run this hypothetical script.
3. The script should simply center the object in its parent artboard and resize it up proportionately.
4. If ran while the selected item was not in an artboard it should silently fail.
5. If more than one item is selected, it should silently fail.

Basically a "Lite" version of the script you posted above.

I might try to cobble together this script based on what you shared, but my JavaScript chops are ... let's say, not that good.

Sorry if it's a big ask. I'm already overjoyed with FitSelectionToArtboards

Thanks again,
Jay

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
Enthusiast ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

4. If ran while the selected item was not in an artboard it should silently fail.
Why check the artboard contains this object? Why would the user run the script if he sees that the object is not inside the artboard?


5. If more than one item is selected, it should silently fail.
Why would you exit the script if selection.length > 1? You can take only the top object (selection[0]) and align it, skipping the rest

These two conditions give the feeling that the script is "alive" and runs itself, not the user. 🙂

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 ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Your logic makes sense!

Why check the artboard contains this object? Why would the user run the script if he sees that the object is not inside the artboard?
Generally when coding, I try to cover all bases - and factor in the possibility that the user is a moron. 🙂 But my original idea is not necessary anyway because an object is always associated with an artboard. So I think I'm going to abandon that route.

Why would you exit the script if selection.length > 1? You can take only the top object (selection[0]) and align it, skipping the rest
The script that I need(ed) is designed to work with a single object, and preferrably with a keyboard shortcut. It just didn't make sense to me that someone would run a script designed to perform an action on a single object - with multiple selections. But you're right, I hadn't thought about the possibility of just processing the top object. That addition makes the script a bit smarter and/or foolproof.

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
Enthusiast ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

LATEST

The Lite version in silent mode aligns and fit topmost selected object to the active artboard if it is contained on it. If you edit CFG.isContains:false in the code, the object outside the active artboard will be placed in it. https://github.com/creold/illustrator-scripts/blob/master/jsx/FitSelectionToArtboards-Lite.jsx

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 ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

OK, I couldn't wait! 🙂

I gutted the GUI portion of your script, removed conditionals that were completely unecessary since I only want it to do one specific thing. (I.E. I don't need margins right now, so it's hard-coded to 0)

Here's my update:
https://gist.github.com/visusys/9154a6ed698ad15d72b3631a7a121905
Behold: FitSelectionToArtboards Lite™

 

It works well on my system. Just click on an icon, click on the script, and it does its magic.

I don't have any error checking besides what you included in the original script. I'd like to add a simple check to see if multiple items are selected and then just do nothing in that case. Shouldn't be too hard to add and I'll update the Gist when I do.

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
Enthusiast ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

You made a working Lite version. So you can remove half of the functions in my code to make it easier. Someday I will give an answer in a comment on Gist.

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 ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

@Sergey OsokinI was looking through your script that you posted and trying to analyze your functions. You have one function in particular that I'm not sure is correct:

 

// Get the defined units for the active document
function getUnits() {
  if (!documents.length) return '';
  switch (activeDocument.rulerUnits) {
    case RulerUnits.Pixels: return 'px';
    case RulerUnits.Points: return 'pt';
    case RulerUnits.Picas: return 'pc';
    case RulerUnits.Inches: return 'in';
    case RulerUnits.Millimeters: return 'mm';
    case RulerUnits.Centimeters: return 'cm';
    case RulerUnits.Unknown: // Parse new units only for the saved doc
      var xmp = activeDocument.XMPString;
      // Example: <stDim:unit>Yards</stDim:unit>
      if (/stDim:unit/i.test(xmp)) {
        var units = /<stDim:unit>(.*?)<\/stDim:unit>/g.exec(xmp)[1];
        if (units == 'Meters') return 'm';
        if (units == 'Feet') return 'ft';
        if (units == 'Yards') return 'yd';
      }
      break;
  }
  return 'px'; // Default
}

 

Specifically these lines:

switch (activeDocument.rulerUnits)
var xmp = activeDocument.XMPString;

Shouldn't it be:

switch (app.activeDocument.rulerUnits)
var xmp = app.activeDocument.XMPString;


I am just learning at the moment and trying to reverse engineer code, so I could be completely and utterly wrong. But I've never seen activeDocument being refrenced without first being prefixed by app.

Any way you can clarify or point me in the right direction?

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
Guide ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

"app" is analogous to a global object. It's properties can be accessed without being explicit. "Window" is a similar object. You can say Window.alert() or just alert().

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 ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Aha! Thank you for the clarification. Good to know moving forward.

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
Guide ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

This is a most basic script.  There is no error management. 

 

ezgif-4-a4df25cdd7.gif

 

// select items
var doc = app.activeDocument;
var selCol = doc.selection;
var ABs = doc.artboards;
for (var i = 0; i < selCol.length; i++) {
    var item = selCol[i];
    var ABR = doc.artboards[i].artboardRect;
    var ABWidth = ABR[2] - ABR[0];
    var ABHeight = ABR[3] - ABR[1];
    var itemMaxDim = Math.max(item.width, item.height);
    var ABMaxDim = Math.max(ABWidth, ABHeight);
    item.width = item.width * (ABMaxDim / itemMaxDim);
    item.height = item.height * (ABMaxDim / itemMaxDim);
    item.position = [
        (ABR[0] + (ABWidth / 2)) - item.width / 2,
        (ABR[1] + (ABHeight / 2)) + item.height / 2
    ];
}

 

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 ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

Hey, I really appreciate the code! I am going to test it out tonight. Sergey Osokin posted a pretty robust script that does the same thing, so I'm using that now. But I can always use more scripts, and reverse engineering them is a great exercise. Thanks so much for taking the time to create and share your code.

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