Skip to main content
Participant
June 15, 2022
Question

-- Javascript/illustrator [change rounded rectangle corner radius]

  • June 15, 2022
  • 3 replies
  • 1633 views

Can someone help me to change the radius of a pageItem with Javascript. I can change the width of a rounded rectangle but not the radius. If the width of an item gets smaller the radius is automatically adjusted what I don't want. So I want control over the radius.

 

selectedLayer.pageItems[0].width = 30;
 
selectedLayer.pageItem[0].radius = 10 doesn't work
 
Anyone?
This topic has been closed for replies.

3 replies

m1b
Community Expert
Community Expert
June 15, 2022

Hi @Rob186563084tse, sadly we don't have scripting access to the corner radius property of shapes. Only the pathPoints of path items. It could be done in scripting, mathematically, but it would be a chore. Another option might be to apply an Effect > Stylize > Round corners? If your rectangle has that effect, you can scale it (make sure you choose not to scale effects) without changing the corner radius. I realise that might not work in some cases, but just an idea.

- Mark

Participant
June 16, 2022

Perfect, that works. Thanks!!!

renél80416020
Inspiring
June 15, 2022

Bonjour,

Appliquer l'effet Convertir en Rectangle arrondi

 

 

m1b
Community Expert
Community Expert
June 16, 2022

Sorry @renél80416020, I didn't see your answer when I posted mine. Yes rounded rectangle might be a better effect to apply, depending on the situation. - Mark

renél80416020
Inspiring
June 16, 2022

Merci pour ta remarque bienveillante  M1b.

J'ajouterai que si la demande de Rob186563084tse est de modifier la largeur ou la hauteur d'un rectangle arrondi sans modifier le rayon, voici une ébauche de script.

Bien sur ici je connais la position du point p0.

Un document doit être ouvert.

 

 

var docRef = app.activeDocument;
var obj0 = docRef.pathItems.roundedRectangle(-200, 200, 100, 100, 20, 20, false);
var obj = obj0.duplicate(docRef,ElementPlacement.PLACEATEND);
var nbPt = obj.pathPoints.length;
//Pour un allongement coté gauche
dx = -60;
dy = 0;
       for (var i = 0; i < 4; i++) {
         p = obj.pathPoints[i];
            pointDep (p,dx,dy);
        }

//Pour un allongement coté droit
dx = 30;
dy = 0;
        for (var i = 4; i < nbPt; i++) {
         p = obj.pathPoints[i];
            pointDep (p,dx,dy);
        }
//Pour un allongement coté supérieur
dx = 0;
dy = 10;
        for (var i = 2; i < 6; i++) {
         p = obj.pathPoints[i];
            pointDep (p,dx,dy);
        }
//Pour un allongement coté inférieur
dx = 0;
dy = -10;
        for (var i = 0; i < 2; i++) {
         p = obj.pathPoints[i];
            pointDep (p,dx,dy);
        }
        for (var i = nbPt-2; i < nbPt; i++) {
         p = obj.pathPoints[i];
            pointDep (p,dx,dy);
        }
// -------
function pointDep (p,dx,dy) {
    var pa, pl, pr;
        pa = p.anchor;
        pl = p.leftDirection;
        pr = p.rightDirection;
        p.anchor = [pa[0]+dx,pa[1]+dy];
        p.leftDirection  = [pl[0]+dx,pl[1]+dy];
        p.rightDirection = [pr[0]+dx,pr[1]+dy];
}
// -------

 

 

René

femkeblanco
Legend
June 15, 2022

Is this what you mean by radius?

Participant
June 16, 2022

Yes