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);
Participant
March 17, 2020

Hi CarlosCanto,

 

Thank you so much! The script does exactly what I want it to do.

Might need to make a different topic for this but in Illustrator CC 2020 when I record my action and load the script the recording does not add this step to the action.

 

Any ideas on how to fix this? 

 

EDIT: I found a way around it by using the "Insert Menu Item..." under the Actions tab.

CarlosCanto
Community Expert
Community Expert
March 17, 2020

that's correct, glad to hear you found "Insert Menu Item..."

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...!