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

Draw custom Shape dpi problem

Explorer ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

511

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

People's Champ , Jan 11, 2019 Jan 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.rig

...

Votes

Translate

Translate
Adobe
People's Champ ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

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; 

....

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
Explorer ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

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

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
LEGEND ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

LATEST

In 7th line add:

res = doc.resolution

and 12th line change to:

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

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