Skip to main content
mimozemská hůl
Inspiring
May 24, 2021
Answered

How to make curvature on shapes with a script?

  • May 24, 2021
  • 1 reply
  • 688 views

In relation to the post on GitHub by Mike Hale and Vladimir Carrer I want to be able to add a curvature to the specific line, or to be more precize with an example, on a rectangle I just want to make curve on one of the sides, that also have to apply to every polygon.

 

In the loop:

for (i = 0; i < y; i++) {
	lineArray[i] = new PathPointInfo;
	lineArray[i].kind = PointKind.CORNERPOINT;
	lineArray[i].anchor = arguments[i];
	lineArray[i].leftDirection = lineArray[i].anchor;
	lineArray[i].rightDirection = lineArray[i].anchor;
}

 I know that lineArray[i].leftDirection = lineArray[i].anchor; and lineArray[i].rightDirection = lineArray[i].anchor; are responsible for creation of the curves. How could I do that in the function DrawShape()?

 

Thank you,

Damian

This topic has been closed for replies.
Correct answer r-bin

Well, for example, like this 🙂

function DrawShape() {
    
    var doc = app.activeDocument;
    var y = arguments.length;
    var i = 0;
    
    var lineArray = [];
    for (i = 0; i < y; i++) {
        lineArray[i] = new PathPointInfo;

        //lineArray[i].kind = PointKind.CORNERPOINT;
        //lineArray[i].anchor = arguments[i];
        //lineArray[i].leftDirection = lineArray[i].anchor;
        //lineArray[i].rightDirection = lineArray[i].anchor;

        lineArray[i].kind = PointKind.SMOOTHPOINT;
        lineArray[i].anchor = [arguments[i][0], arguments[i][1]];
        lineArray[i].leftDirection = [arguments[i][2]!=undefined?arguments[i][2]:arguments[i][0], arguments[i][3]!=undefined?arguments[i][3]:arguments[i][1]];
        lineArray[i].rightDirection = [arguments[i][4]!=undefined?arguments[i][4]:arguments[i][0], arguments[i][5]!=undefined?arguments[i][5]:arguments[i][1]];
    }

    var lineSubPathArray = new SubPathInfo();
    lineSubPathArray.closed = true;
    lineSubPathArray.operation = ShapeOperation.SHAPEADD;
    lineSubPathArray.entireSubPath = lineArray;
    var myPathItem = doc.pathItems.add("myPath", [lineSubPathArray]);
    

    var desc88 = new ActionDescriptor();
    var ref60 = new ActionReference();
    ref60.putClass(stringIDToTypeID("contentLayer"));
    desc88.putReference(charIDToTypeID("null"), ref60);
    var desc89 = new ActionDescriptor();
    var desc90 = new ActionDescriptor();
    var desc91 = new ActionDescriptor();
    desc91.putDouble(charIDToTypeID("Rd  "), 0.000000); // R
    desc91.putDouble(charIDToTypeID("Grn "), 0.000000); // G
    desc91.putDouble(charIDToTypeID("Bl  "), 0.000000); // B
    var id481 = charIDToTypeID("RGBC");
    desc90.putObject(charIDToTypeID("Clr "), id481, desc91);
    desc89.putObject(charIDToTypeID("Type"), stringIDToTypeID("solidColorLayer"), desc90);
    desc88.putObject(charIDToTypeID("Usng"), stringIDToTypeID("contentLayer"), desc89);
    executeAction(charIDToTypeID("Mk  "), desc88, DialogModes.NO);
    
    myPathItem.remove();
}

                     
DrawShape([100, 100, 50,150, 150,50], [100, 200], [200, 200], [200, 100]);

 

1 reply

r-binCorrect answer
Legend
May 25, 2021

Well, for example, like this 🙂

function DrawShape() {
    
    var doc = app.activeDocument;
    var y = arguments.length;
    var i = 0;
    
    var lineArray = [];
    for (i = 0; i < y; i++) {
        lineArray[i] = new PathPointInfo;

        //lineArray[i].kind = PointKind.CORNERPOINT;
        //lineArray[i].anchor = arguments[i];
        //lineArray[i].leftDirection = lineArray[i].anchor;
        //lineArray[i].rightDirection = lineArray[i].anchor;

        lineArray[i].kind = PointKind.SMOOTHPOINT;
        lineArray[i].anchor = [arguments[i][0], arguments[i][1]];
        lineArray[i].leftDirection = [arguments[i][2]!=undefined?arguments[i][2]:arguments[i][0], arguments[i][3]!=undefined?arguments[i][3]:arguments[i][1]];
        lineArray[i].rightDirection = [arguments[i][4]!=undefined?arguments[i][4]:arguments[i][0], arguments[i][5]!=undefined?arguments[i][5]:arguments[i][1]];
    }

    var lineSubPathArray = new SubPathInfo();
    lineSubPathArray.closed = true;
    lineSubPathArray.operation = ShapeOperation.SHAPEADD;
    lineSubPathArray.entireSubPath = lineArray;
    var myPathItem = doc.pathItems.add("myPath", [lineSubPathArray]);
    

    var desc88 = new ActionDescriptor();
    var ref60 = new ActionReference();
    ref60.putClass(stringIDToTypeID("contentLayer"));
    desc88.putReference(charIDToTypeID("null"), ref60);
    var desc89 = new ActionDescriptor();
    var desc90 = new ActionDescriptor();
    var desc91 = new ActionDescriptor();
    desc91.putDouble(charIDToTypeID("Rd  "), 0.000000); // R
    desc91.putDouble(charIDToTypeID("Grn "), 0.000000); // G
    desc91.putDouble(charIDToTypeID("Bl  "), 0.000000); // B
    var id481 = charIDToTypeID("RGBC");
    desc90.putObject(charIDToTypeID("Clr "), id481, desc91);
    desc89.putObject(charIDToTypeID("Type"), stringIDToTypeID("solidColorLayer"), desc90);
    desc88.putObject(charIDToTypeID("Usng"), stringIDToTypeID("contentLayer"), desc89);
    executeAction(charIDToTypeID("Mk  "), desc88, DialogModes.NO);
    
    myPathItem.remove();
}

                     
DrawShape([100, 100, 50,150, 150,50], [100, 200], [200, 200], [200, 100]);

 

mimozemská hůl
Inspiring
May 25, 2021

Yes, this would definitely do the job. Thank you r-bin.