Path not selected when added

Contributor ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Hello guys, I'm trying to create a script to add and then select an ellipse to the document, but I don't understand why it was not selected. Any help is valid.
Here the script:

 

addPath();
function addPath(){
    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;
}

selectedPath()
function selectedPath(){
        var doc = app.activeDocument;
        for(var i=0; i<doc.pathItems.length; i++){  
        doc.pathItems[i].selected = doc.pathItems[i].stroked;  
    } 
}

 

 
TOPICS
Scripting

Views

132

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 07, 2021 Apr 07, 2021
I don't know why - but would you like to select (only) the newly created ellipse? addPath(); function addPath(){ 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; corte.selected = true; }

Likes

Translate

Translate
Participant ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

try following lines

 

addPath();
function addPath(){
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;
}

selectedPath()
function selectedPath(){
var doc = app.activeDocument;
for(var i=0; i<doc.pathItems.length; i++){

if(doc.pathItems.length>0){
doc.pathItems[i].selected =true;
}
}
}

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 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Your script does select the ellipse, albeit (I presume) in an unintended way. Also, your second function is constructed to select all paths. Is that what you intended?

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 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

I don't know why - but would you like to select (only) the newly created ellipse?

addPath();
function addPath(){
    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;
    corte.selected = true;
}

 

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 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

LATEST

Perfect @pixxxelschubser  it looks very simple. I'm new to illustrator script and I kind of improvised that script. Thank you all for your support.

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