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

Illustrator script that compares object width to length

Community Beginner ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

1.9K

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

Community Expert , Mar 16, 2020 Mar 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/t
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

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

Fitting.png

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
Community Beginner ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

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.

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
Community Beginner ,
Apr 01, 2020 Apr 01, 2020

Copy link to clipboard

Copied

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

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
Community Expert ,
Apr 01, 2020 Apr 01, 2020

Copy link to clipboard

Copied

...if we only knew.

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
Community Expert ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

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

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
Community Beginner ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

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.Knipsel.PNG

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
Community Expert ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

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

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
Advocate ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

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.

 

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
Community Expert ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

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

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
Advocate ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

LATEST

Thanks! I've implemented a check and used the code. Works like a champ!

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