Skip to main content
Participant
March 16, 2020
Answered

Illustrator script that compares object width to length

  • March 16, 2020
  • 2 replies
  • 2737 views

Hi,

 

For our product catalog we make linedrawings of all our products. For this we use our 3D designs and export a certain perspective into a drawing. This object we then need to fit it into a 50x50mm square artboard, put linewidth on 1pt and export it to bmp. The last two steps I'm able to complete with Actions in Illustrator.

 

For the first step I need to scale the object down to 50mm in width OR height, depending on the shape.

This is why I need the script that compares the object width to object length and depending on the outcome activate either a script that scales length to 50mm and the width proportionally or vice versa.

 

Is this possible? Does this post belong here?

This topic has been closed for replies.
Correct answer CarlosCanto

I wrote a custom version for a customer, keeping items proportional, so I couldn't post it on my website. But that wouldn't work for you, unless you added artboards as image placeholders. 

 

do you do one item at a time? do you select an item and run your actions?

 

here's a script you can incorporate into your Action set.

 

Select ONE object before running

 

// resize to 50 mm
// carlos canto
// https://community.adobe.com/t5/illustrator/illustrator-script-that-compares-object-width-to-length/td-p/10984755?page=1

var idoc = app.activeDocument;
var sel = idoc.selection[0];

var max = Math.max(sel.width, sel.height);
var targetSize = 50*72/25.4;

var percent = targetSize/max*100;

sel.resize(percent, percent);

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
March 16, 2020

I wrote a custom version for a customer, keeping items proportional, so I couldn't post it on my website. But that wouldn't work for you, unless you added artboards as image placeholders. 

 

do you do one item at a time? do you select an item and run your actions?

 

here's a script you can incorporate into your Action set.

 

Select ONE object before running

 

// resize to 50 mm
// carlos canto
// https://community.adobe.com/t5/illustrator/illustrator-script-that-compares-object-width-to-length/td-p/10984755?page=1

var idoc = app.activeDocument;
var sel = idoc.selection[0];

var max = Math.max(sel.width, sel.height);
var targetSize = 50*72/25.4;

var percent = targetSize/max*100;

sel.resize(percent, percent);
schroef
Inspiring
July 4, 2022

Do you mind if i use this for CEP panel i helped a on. Ive helped mevCJ upgrade his logo exporter panel. I noticed when JPG is either to small or to big, the exporter will fail to export JPG files. I had done some testing and got some code working. But could not figure out how to use scale to do it proportional. This code works like a champ!

The initial panel he designed was great! Im a graphic designer myself and was missing some features which are workflow depended. I added some features so it gives cleaner exports.

 

CarlosCanto
Community Expert
Community Expert
July 5, 2022

Hi @schroef , sure no problem, ok to use.

Ton Frederiks
Community Expert
Community Expert
March 16, 2020

The Links panel has fitting options when links are replaced. Maybe this will be an option?

Participant
March 16, 2020

Hi Tom,

Thanks for your reply. This would be very helpful but unfortunatly Illustrator doesn't see it as a link since I need to embed it to adjust the line width.

 

I found this script online that scales objects to the artboard. Unfortunatly the developer has never made a version that proportionally scales object.

 

I hope that someone can still help me with this.

Participating Frequently
April 1, 2020

If only we knew who that scripting developer was...!