Skip to main content
Joachim Hiller
Known Participant
January 11, 2019
Answered

Draw custom Shape dpi problem

  • January 11, 2019
  • 2 replies
  • 673 views

Hallo,

i find a solution for draw a custom Shape

https://forums.adobe.com/message/9810176#9810176

function drawCustomShape(points, color) {

    try {

       

        var doc = app.activeDocument,

            countPoints = points.length,

            lineArray = [];

        for (var i = 0; i < countPoints; i++) {

            lineArray = new PathPointInfo;

            lineArray.kind = PointKind.CORNERPOINT;

            lineArray.anchor = [Number(points[0]), Number(points[1])];

            lineArray.leftDirection = lineArray.anchor;

            lineArray.rightDirection = lineArray.anchor;

        }

        var lineSubPathArray = new SubPathInfo();

        lineSubPathArray.closed = true;

        lineSubPathArray.operation = ShapeOperation.SHAPEADD;

        lineSubPathArray.entireSubPath = lineArray;

        var myPathItem = doc.pathItems.add("myPath", [lineSubPathArray]);

        //Werte für die Farbfläche bestimmen

        var desc1 = new ActionDescriptor();

        var ref1 = new ActionReference();

        ref1.putClass(stringIDToTypeID("contentLayer"));

        desc1.putReference(charIDToTypeID("null"), ref1);

        var desc2 = new ActionDescriptor();

        var desc3 = new ActionDescriptor();

        var desc4 = new ActionDescriptor();

        desc4.putDouble(charIDToTypeID("Rd  "), color.rgb.red); // R

        desc4.putDouble(charIDToTypeID("Grn "), color.rgb.green); // G

        desc4.putDouble(charIDToTypeID("Bl  "), color.rgb.blue); // B

        desc3.putObject(charIDToTypeID("Clr "), charIDToTypeID("RGBC"), desc4);

        desc2.putObject(charIDToTypeID("Type"), stringIDToTypeID("solidColorLayer"), desc3);

        desc1.putObject(charIDToTypeID("Usng"), stringIDToTypeID("contentLayer"), desc2);

        executeAction(charIDToTypeID("Mk  "), desc1, DialogModes.NO);

        //Pfad entfernen

        myPathItem.remove();

    } catch (e) {

        alert(e + "\n" + e.line);

    }

}

var color = = new SolidColor();

color.rgb.hexValue = '808080';

var points = [[1000,250], [1250,750],[750,750] ];

drawCustomShape (points, color);

This works perfectly if the document has 72dpi, but not at 300dpi.

Do I have to convert something?

The Shape is at 300 dpi outside the document and is too big

Thanks in advance for the help

Jo

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

What does it mean does not work?

Coordinates are given in points. Just when dpi = 72 pixels and points match.

If you want pixels, then use.

var doc = app.activeDocument, 

    countPoints = points.length, 

    lineArray = []; 

var mult = 72/doc.resolution;

for (var i = 0; i < countPoints; i++) { 

    lineArray = new PathPointInfo; 

    lineArray.kind = PointKind.CORNERPOINT; 

    lineArray.anchor = [points[0]*mult, points[1]*mult]; 

    lineArray.leftDirection = lineArray.anchor; 

    lineArray.rightDirection = lineArray.anchor; 

....

2 replies

Kukurykus
Legend
January 11, 2019

In 7th line add:

res = doc.resolution

and 12th line change to:

lineArray.anchor = [Number(points[0] / res * 72), Number(points[1] / res * 72)]

r-binCorrect answer
Legend
January 11, 2019

What does it mean does not work?

Coordinates are given in points. Just when dpi = 72 pixels and points match.

If you want pixels, then use.

var doc = app.activeDocument, 

    countPoints = points.length, 

    lineArray = []; 

var mult = 72/doc.resolution;

for (var i = 0; i < countPoints; i++) { 

    lineArray = new PathPointInfo; 

    lineArray.kind = PointKind.CORNERPOINT; 

    lineArray.anchor = [points[0]*mult, points[1]*mult]; 

    lineArray.leftDirection = lineArray.anchor; 

    lineArray.rightDirection = lineArray.anchor; 

....

Joachim Hiller
Known Participant
January 11, 2019

Thank you very much r-bin that was the mistake.