Doubts about pathItems position and color sample

Contributor ,
Apr 11, 2021 Apr 11, 2021

Copy link to clipboard

Copied

Hello everyone!
1: How to add a "pathItems" with the value "0" in top and left if the document has an image? It only works for me only on a new empty layer.

Capturar2.PNGCapturar.PNG

 

 

 

 

criarPath()
function criarPath(){
    var doc = app.activeDocument;
    var artLayer = doc.layers[0];
    var corte = artLayer.pathItems.ellipse(0, 0, doc.width, doc.height, false);
    var noColor = new NoColor();
    corte.fillColor = noColor;
}

 

2: How do I add a color swatch by the name "mycolor" to a stroke.

TOPICS
Scripting

Views

280

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

correct answers 1 Correct Answer

Adobe Community Professional , Apr 13, 2021 Apr 13, 2021
Hi, You can try following snippet criarPath() function criarPath(){ var doc = app.activeDocument; app.executeMenuCommand('Fit Artboard to selected Art'); var artLayer = doc.layers[0]; var _item = doc.pageItems[0]; // assuming single image. var x = _item.top; var y = _item.left; var corte = artLayer.pathItems.ellipse(x, y, doc.width, doc.height, false); var noColor = new NoColor(); corte.fillColor = noColor; var _strokeColor = doc.swatches.getByName('mycol...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 11, 2021 Apr 11, 2021

Copy link to clipboard

Copied

Hi,

To add strokeColor with name "mycolor", please try following snippet

criarPath()
function criarPath(){
    var doc = app.activeDocument;
    var artLayer = doc.layers[0];
    var corte = artLayer.pathItems.ellipse(0, 0, doc.width, doc.height, false);
    var noColor = new NoColor();
    corte.fillColor = noColor;
    var _strokeColor = doc.swatches.getByName('mycolor');
    corte.stroked = true;
    corte.strokeColor = _strokeColor.color;
}

Also, I tried when layer is not empty but it works well. Could you please share your ai file?

 

Best regards

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
Engaged ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

As far as the position of the ellipse goes, I'm not sure why it isn't appearing in the top left of artboard. It has nothing to do with the layer, but probably the artboard. Can you check that (a) you have the correct artboard active, and (b) that the Ruler shows 0, 0 at the top left of the artboard. If the ruler has been manually moved, it will change where point 0, 0 is. It is possible to get the coordinates of the artboard itself, so please let me know if that's what you need.

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
Contributor ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

@Charu Rajput , @m1b 

Thanks for the support! Sorry for the delay. I made the short video here showing the strange behavior.

Screen vídeo:
https://drive.google.com/file/d/1jluLSTa-TcwL28pxzDP2bywv7wVUKYR4/view
File.ai used in the example
https://drive.google.com/file/d/1Pmq2l0pCgVTf8w1KNysJbgf2cIpm6b0g/view

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
Enthusiast ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Opening the png file is setting your origin (0, 0) to the lower left.  Instead, create a new document (file > new) and place the image (file > place).  Your origin will be the upper left.  Alternatively, if you must open the png file, change line 5 in your script to

var corte = artLayer.pathItems.ellipse(doc.height, 0, doc.width, doc.height, false);

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
Adobe Community Professional ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi,

There is no issue in your script.

The problem is that when you are giving 0, 0 while creatinh ellipse it is taking it in points. So just try to change the units from the rulers from cm to points and after that select artbaords, to change X and Y to 0, 0. Please refer the video attached. I ahve used your ai file attached but in your video you are opening a png file.

 

https://drive.google.com/file/d/1kVVamXke8V2el6GNOpB_D7cyCcXnSBFS/view?usp=sharing

 

 

Best regards

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
Contributor ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Result!

https://drive.google.com/file/d/119A4nmuts9l_1nBjH2yrIK2CAyWdsCfu/view
Guys, thank you all for your attention, I made all the attempts suggested by my friends, but I was not successful.
It would be like this:
1: Open an image file
2: Resize the Artboard with the same proportions as the
image file:
3: Add a "pathItems.ellipse" or "pathItems.rectangle" with a specific color with the same proportions as Artboard.
However, this would only be possible in a correct way by editing the x, y positions on the drawing board:
x = width / 2
y = height / 2
But all in an automated way with a script and I don't know if that would be possible. It would be possible?

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
Adobe Community Professional ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi,

You have choose center reference point for the artboard when setting 0,0 for the X and Y coordinates. You should choose top left reference point.

 

Screenshot 2021-04-13 at 11.12.11 AM.png

 

Screenshot 2021-04-13 at 11.12.20 AM.png

 

 

Best regards

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
Contributor ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Thanks @Charu Rajput , it worked correctly, I confess I did not obey the position of the registration point! Would these modifications in relation to your second image be possible through a script?

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Hi,

You can try following snippet

criarPath()
function criarPath(){
    var doc = app.activeDocument;
    app.executeMenuCommand('Fit Artboard to selected Art');
    var artLayer = doc.layers[0];
    var _item = doc.pageItems[0]; // assuming single image.
    var x = _item.top;
    var y  = _item.left;
    var corte = artLayer.pathItems.ellipse(x, y, doc.width, doc.height, false);
    var noColor = new NoColor();
    corte.fillColor = noColor;
    var _strokeColor = doc.swatches.getByName('mycolor');
    corte.stroked = true;
    corte.strokeColor = _strokeColor.color;
}

 

Open image file(png file) and just run this script

 

 

Best regards

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
Contributor ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

Perfect @Charu Rajput ! You are a real genius and very kind, when I grow up I want to be just like you. Thank you for everything.

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