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

Remove Fill on paths not quite working

Advisor ,
Mar 21, 2017 Mar 21, 2017

Why aren't all the paths that may have a fill on them, within the layer by name "Hairs_TopNose" not being iterated though and having, if exists their fill removed ?

var curDoc = app.activeDocument;

var lyr = curDoc.layers.getByName("Hairs_TopNose");

var pathss = lyr.hasSelectedArtwork;

var pth = lyr.pathItems.length;

var patth = lyr.pathItem;

if (pathss==1) {

    for(pth=0;pth<patth.filled=false;i++)

    }else{

        alert("Fill on Paths Removed");

        };

TOPICS
Scripting
2.0K
Translate
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

Guide , Mar 22, 2017 Mar 22, 2017

and in the if statement you have the wrong var as well.

while (i--) { 

if (patth.filled) { 

  patth.filled=false

use pth not patth.

pth is the array of path items

patth is the number of items in the array.

Translate
Adobe
Valorous Hero ,
Mar 21, 2017 Mar 21, 2017

Your for-loop, looks like it is missing.

Translate
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
Advisor ,
Mar 21, 2017 Mar 21, 2017

When you said missing; I realized I missed a curly brace, until adding it I got an error I didn't previous have, illegal use of the word else.

Translate
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
Participant ,
Mar 22, 2017 Mar 22, 2017

If I understood the problem correctly, then:

var layer = activeDocument.layers.getByName('Hairs_TopNose'),

    items = layer.pathItems,

    i = items.length,

    check = false;

while (i--) {

    if (items.filled) {

        items.filled = false;

        check = true;

    }

}

if (check) alert('Fill on Paths - Removed!');

    else alert('Fill on Paths - Not found!');

Translate
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
Advisor ,
Mar 22, 2017 Mar 22, 2017

@Alexander Ladygin, check is a variable, correct ?

What was wrong with the code approach I took; the loop is what I can see ?

Translate
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
Participant ,
Mar 22, 2017 Mar 22, 2017

Try putting the if statement inside of the for loop, this code assumes that none of the path items are grouped:

// get a reference to all the path items in the layer,

//   doesn't include any paths that are in groups or sublayers

var paths = layer.pathItems;

var curPath;

// loop through each index in the array of path items

for( var i = 0, ii = paths.length; i<ii; i++ ) {

    

     // get a reference to the current path

     curPath = paths;

    

     // check if it has a fill color

     if( curPath.filled == true ) {

                   

          // remove its fill color

          curPath.filled = false;

     }

}

If you are using CS6 or newer, the 'executeMenuCommand' might also be a good approach:

#target illustrator

function test() {

    

     // get references to the document and the layer

     var doc = app.activeDocument;

     var layer = doc.layers.getByName( "Hairs_TopNose" );

    

     // clear any current selections

     doc.selection = null;

    

     // select all the art on the layer and unlock and show it

     layer.hasSelectedArtwork = true;

     app.executeMenuCommand( "unlockAll" );

     app.executeMenuCommand( "showAll" );

    

     // reset the selection and clear any fill colors

     layer.hasSelectedArtwork = true;

     doc.defaultStrokeColor = new NoColor();

    

     // clear the selection

     doc.selection = null;

}

test();

Translate
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
Advisor ,
Mar 22, 2017 Mar 22, 2017

This is altered to what Alexander Ladygin posted, except there is an error on line 4; which is odd because it's identical to the same line in his code ?

var curDoc = app.activeDocument;
var lyr = curDoc.layers.getByName("Hairs_TopNose");
var pathss = lyr.hasSelectedArtwork;
var pth = layer.pathItems;
var patth = pth.length;
var verify = false;
while (i--) {
    if (patth.filled) {
        patth.filled=false;
        verify=true;
        }
};

if (verify) alert("Fill on paths removed");
else alert("Fill on paths not removed");

Translate
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
Participant ,
Mar 22, 2017 Mar 22, 2017

Change 'layer.pathItems' to 'lyr.pathItems', I hate when that happens!

Translate
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
Advisor ,
Mar 22, 2017 Mar 22, 2017

Thanks, although now i the variable in the while loop is undefined ?

Translate
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
Guide ,
Mar 22, 2017 Mar 22, 2017

change the line:

var patth = pth.length;

to

var i = pth.length;

Translate
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
Guide ,
Mar 22, 2017 Mar 22, 2017

and in the if statement you have the wrong var as well.

while (i--) { 

if (patth.filled) { 

  patth.filled=false

use pth not patth.

pth is the array of path items

patth is the number of items in the array.

Translate
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
Advisor ,
Mar 22, 2017 Mar 22, 2017

Qwertyfly...​You mean var i is now the number of items in the array and pth is the list of the path items

Qwertyfly...​Thank you and thank you to everyone who helped as well

Translate
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
Guide ,
Mar 22, 2017 Mar 22, 2017
LATEST

try this.

renamed the variables so it makes more sense.

var myDoc = app.activeDocument; 

var myLayer = myDoc.layers.getByName("Hairs_TopNose"); 

// the line here was not used

var myPaths = myLayer.pathItems; 

var myPathQty = myPaths.length; 

var verify = false;

var i = myPathQty;

while (i--) { 

    if (myPaths.filled) { 

        myPaths.filled=false; 

        verify=true; 

        } 

}; 

if (verify) alert("Fill on paths removed"); 

else alert("Fill on paths not removed");

Translate
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