Round corner radius from JS script?

New Here ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

Dear AI community

 

I'm struggling with automating a batch job which involves rounding all corners (including sharp ones, low  angle) in a PathItem.

 

I need to replicate from the script what you can do manually by selecting all anchor points and either dragging the round corner handler or just setting the corner radius under object Properties pane -> Corners field. 

 

I spent a reasonable amount of time digging AI scripting guide and seems can't find anything related to rounding PathItem.pathPoints elements. Can't find any equivalent API to setting the corner radius via UI Properties->Corners field. 

 

Also another issue is the corner radius handle & property will only show when the corner angle is bigger than certain threshold. Not sure why. Other vetcor editors I tried e.g. Inkscape or Affinity Designer don't have this limitation, you can round literraly any corner and it works rather well. Is there any way to force round corner regadless of angle? Changing the geometry slightly just to get over the corner angle threshold to get access to the radius property is not going to work for me. This is an automated batch job with a lot of geometry to process.

 

Any advice please? 

 

What I tried so far:

 

Tried the built in Round Corner filter you can apply to any object via effects property. Unfortunatelly it is far not the same as rounding corners directly via anchor Radius property in editor quality wise. The Round Corners filter will mess up corners where the sides are not stright lines but curved beziers. Changing radius property for the same corner directly in editor doesn't do that and works as expected.

 

I've managet to google up this rather advanced Round Corners AI script by WELZ-gh. It is a serious amount of code but unfortunately it doesn't quite work correctly. Multiple similar corners will get different inconsitent amount of rounding and also the rounding itself for many corners looks way too sharp. 

https://gist.github.com/WELZ-gh/fcbf311cf504a001577d8d424336e592

TOPICS
Scripting

Views

155

Likes

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 ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

Bonjour,

Peut-être de ce coté là ?

https://community.adobe.com/t5/illustrator-discussions/need-help-rounded-corners/m-p/11182904

Si le lien est correct...

René

Likes

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
New Here ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

 

Thanks René.

 

Been there, seen that. Unless I'm missing something I don't think there is a universal ready to use solution in that thread. Unfortunately I'm not a maths ninja to replicate what the available via AI UI built in corner rounding function does in the script. This would too much for me to handle 😞

 

So I'm hoping may be there is a way to simply invoke UI from script to do the same? i.e. iterate through PathItem points. Select one at a time. Then somehow call into UI to do the corenr rounding bit? Any other options perhaps?

 

Thanks

Likes

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 ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

J'aimerais bien avoir un exemple de ce que vous souhaitez pour mieux comprendre.

Mon script fait cela, mais je peux le modifier...

arrondi angle.PNG

René

Likes

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
New Here ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

Just had another look through the thread you are pointing to. I seems can't find the script you are refrerring to to give it a try. Is it free or is it a paid plugin of sorts? Can you please share a direct link to it?

 

Basically, as stated in the OP, all I want is a method to dynamically round all 'corner' type points in a given Path object with a defined radius. This will be used by an automated script on arbitrary 'closed path' geometry which will be then exported to SVG for further use in extrenal software.

 

The corner smoothing quality needs to be not worse than the built in corner rounding tool accessible via AI UI. 

 

The built in AI corner function works with botrh straight line corners (both path segments of the corner are straight lines which is what you have in the example on your screenshot) and with curved corners (one or both path segments are curved beziers).

 

Also the built in AI corner function uses proportional radius for each corner depending on the corner angle when you apply it to multiple points at once. E.g. when you select all points in the path and drag the corner tool handle it will scale the radius for each corner based on its angle rather than blindly apply the same radius to all corners. Which looks rather similar to what you have in yours screenshot.

 

Frankly I'm totally happy with the built in AI corner tool. All I need is just a way to invoke it from the AI script to automate the whole process. Unfortunatelly it doesn't look straight forward 😞

Likes

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 ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

Rebonjour,

Merci pour votre réponse,

Mon script est payant, je vais donc cessé de vous importuner...

Dans l'exemple précédant, la liste de commande

lister.PNG

signifie rayon de 20 pour les sommets 0 et 6

et 8 pour les sommets 1, 2, 3, 5

 

Un autre exemple (tous les sommets arrondis au même rayon 20pt):

La ligne de commande est ici [20,[50]]

il suffit que la valeur 50 soit > au nombre de sommets 10

arrondi angle.PNG


Pour ce que vous demander (l'application de l'effet arrondi) je ne connais pas le nom de l'effet ni les paramètres à utiliser.

Il faut:

xmlstring = '<LiveEffect name="Adobe ??? Effects"><??????

sel[a].applyEffect(xmlstring); // appliqué à la sélection

D'autres que moi pourront certainement vous aider...

Cordialement René

 

Likes

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 ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

Maintenant avec ce petit script ??

 

// JavaScript Document for Illustrator
// apply Adobe Round Corners Effect to selected object
// radius = 20;
// https://translate.google.com/translate?sl=auto&tl=en&u=https://ten-artai.com/2015/12/318/

var idoc = app.activeDocument;
var sel = idoc.selection;

xmlstring2 = '<LiveEffect name="Adobe Round Corners"><Dict data="R radius 20 "/></LiveEffect>';
    for (var j = 0; j < sel.length; j++) {
      sel[j].applyEffect(xmlstring2);
    }

 

arrondi angle.PNG

 René

Likes

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
New Here ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

LATEST

Thanks Rene

 

Thank you! Unfortunately this is not going to fly. Like I said in OP I already tried the Round Corner filter effect. It will not work with anything other than corners straight line segments. It will fail miserably on curved path segments. Unlike live dragging the corner handle or changing Corners property in UI which works correct.

 

I think Round Corners filter is an ancient AI plugin which hasn't been updated for thousand years. It is not the same effect you get when live editing the corner radius from UI.  In this example below in both cases a 5px radius has been applied to the same path: 

 

Screenshot 2022-02-05 at 00.15.05.png

 

 

 

 

Likes

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