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

removing paths

Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

How can I select all paths with fill black 100% and remove them?

I tried the "script" below, but it doesn't give faults and the result stays the same (-> no remove of the items)

#target illustrator
var docRef=app.activeDocument;

for(i=0;i<docRef.pageItems.length; i++ ) {
    var pathRef = docRef.pageItems;
    if (pathRef.fillColor.black == 100) {
        pathRef.selected = true;
        pathRef.remove(i);
    };
};

I also tried: pathRef.remove(); but also here, the result is the same....

TOPICS
Scripting

Views

3.1K

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

Guru , Mar 02, 2012 Mar 02, 2012

Jesse, I had a look at that file and your white path items are 0% of a gray color… Easy enough to get rid of… The text frames are NOT being deleted because they do have content NOT empty… There are either 1 or two invisible characters in each Im not sure how to deal with this just yet ( need to check how to get the character values )… Making a rectangle and filling it black is easy stuff… Here I made one half the size of the doc… Not filled it just yet do you need 100% gray color or 0,0,0,100 CM

...

Votes

Translate

Translate
Adobe
Guru ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Jesse, first thing with removing items… Do this in reverse order otherwise when you reach the midpoint of the list i will be out of range… i is going up in value while the number of items is getting less…

pathRef.selected = true; // This line is not needed we do not select items in scripting…

pathRef.remove(i); // Should be…

pathRef.remove();

This worked here…

#target illustrator

var docRef = app.activeDocument;

for ( var i = docRef.pageItems.length-1; i > 0; i-- ) {

   

    var pathRef = docRef.pageItems;

   

    if ( pathRef.fillColor.black == 100 ) { pathRef.remove(); }

};

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
Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Mark,

Many thanks for the suggestions and explication.

I tried your version of the code, but Illustrator doesn't remove the defined path in Illustrator

The script:

#target illustrator

var docRef = app.activeDocument;

for (var i = docRef.pageItems.length-1; i > 0; i--) {

    var pathRef = docRef.pageItems;

   

    if (pathRef.fillColor.black==100){

        pathRef.remove();

    };

};

The path (rectangle with 100% black) stays in the document instead of removed.

Extendscript doesn't give errors or warnings.

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
Guru ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Jesse… try and swap the work black for gray I susspect that you are dealing with grayscale color…?

#target illustrator

var docRef = app.activeDocument;

for ( var i = docRef.pageItems.length-1; i > 0; i-- ) {

   

    var pathRef = docRef.pageItems;

   

    if ( pathRef.fillColor.gray == 100 ) { pathRef.remove(); }

};

As you had defined it I would remove any CMYK that contained 100K

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
Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Nothing deleted in Illustrator, below a screenshot (at the right you I have used grayscale instead of CMYK, RGB,...)

Capture.JPG

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
Guru ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

That is 2 items that are NOT equal in color values… Can you snap shot with the layers palette visible? Are they grouped BTW?

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
Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

No, they were not grouped, I selected them all.

Normally I have to delete all white rectangles with a white stroke in the Illustrator document, but I tried a simple black rectangle to remove (with many of your kindly helps!)

Capture.JPG

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
Guru ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Send a link to a sample file…

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
Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

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
Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

I replied on your mail.

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
Engaged ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Jesse:

Add (check) a few more levels of debugging in Edit > Preferences > Debugging and work your way back to where you are now - that should give you an idea of what's going on... I prefer to work in Visual Basic where I can see what's going on better -- FWIW -- (not to throw another curve), but the code below works in Visual Basic:

I tried Mark's codce in ES and it didn;t work for me; I'll look into it a little more if you don't find the answer.

========================

Imports AI = Illustrator

Module AdobeForum20120301

Public Sub RemoveBlackFilledBoxes()

Dim app As AI.Application = CreateObject("Illustrator.Application")

Dim aDoc = app.ActiveDocument

For Each pi In aDoc.PageItems

If pi.pageitemtype = 5 Then

Dim pathItem As AI.PathItem = pi

If pathItem.FillColor.Black = 100 Then

pathItem.Delete()

app.Redraw()

End If

End If

Next

End Sub

End Module

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
Engaged ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Just one change to Mark's code (as it was iterating one time less that it should have, I believe)...

        for ( var i = docRef.pageItems.length-1; i >= 0; i-- ) {

Other than that, I sure don't see why it doesn't work for me..

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
Guru ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Yup it was… missed that… oops

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
Engaged ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

heh -- well -- you being wrong doesn't happen very often! So I triple-checked, crossed my fingers and donned a new helmet before I hit the send button... you can never be TOO careful when you challange the Jedi Master!   LOL! Your contributions here, Mark, are immeasurable.

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
Participant ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Sorry guys, It doesn't work for me.

I use the code of "ThinkingThings" as below:

#target Illustrator
var docRef = app.activeDocument;

for (var i = docRef.pageItems.length-1; i >= 0; i-- ) {
    var pathRef = docRef.pageItems;
    if (pathRef.fillColor.black == 100){
        pathRef.remove();
        app.redraw();
     };
};

I checked my document color profile (yes, it is CMYK), I created a rectangle with black fill color (100%) on the canvas of the file, I ran the script, I also checked the ";" and the place of { and }, but it does nothing...

I thought javascript was quite simple. I have to learn a lot...

Other suggestions or remarks on the code?

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
Guru ,
Mar 02, 2012 Mar 02, 2012

Copy link to clipboard

Copied

Never got a link to a file… Did you send to the right muppet? That first one in the contributors is just a ghost in the machine…

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
Participant ,
Mar 02, 2012 Mar 02, 2012

Copy link to clipboard

Copied

Why does Adobe make it so complicated about sharing files, creating accounts, creating subaccounts, log in, additional log in,... Now, I hope that you can find the link Mark and other forum users! Next, I am forget how to upload a file again!

In Illustrator do "select all" and that rubbish must be removed by using a script. When I receive houndreds of ai-files and I must clean it up "by hand", then is that a very complicated case.

Many thanks everybody for helping mee.

https://acrobat.com/#d=Eez26yxk-L7I*M9Hw2pODA

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
Guru ,
Mar 02, 2012 Mar 02, 2012

Copy link to clipboard

Copied

OK, I have a sample of you file… Its just one layer containing path items of white fill and point text frames with no content… What is it that you need to do wth this…?

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
Participant ,
Mar 02, 2012 Mar 02, 2012

Copy link to clipboard

Copied

Create on the existing file a rectangle with black fill.

The script must delete the path items with white fill and it must delete the text frames with no content.

Result after the script is only that rectangle with black fill.

The script described here below is for deleting stray points, empty textframes,... if that would be helpful for you.

#target illustrator
var idoc = app.activeDocument;
var straypoints = [];

for (i=0; i<idoc.pathItems.length; i++) {
    var ipath = idoc.pathItems;
    if (ipath.pathPoints.length==1)
        straypoints.push(ipath);
}

for (j=0; j<idoc.textFrames.length; j++) {
    var itext = idoc.textFrames;
    if (itext.textRange.length==0)
        straypoints.push(itext);
}

for (k=0; k<straypoints.length; k++)
    straypoints.remove();

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
Guru ,
Mar 02, 2012 Mar 02, 2012

Copy link to clipboard

Copied

Jesse, I had a look at that file and your white path items are 0% of a gray color… Easy enough to get rid of… The text frames are NOT being deleted because they do have content NOT empty… There are either 1 or two invisible characters in each Im not sure how to deal with this just yet ( need to check how to get the character values )… Making a rectangle and filling it black is easy stuff… Here I made one half the size of the doc… Not filled it just yet do you need 100% gray color or 0,0,0,100 CMYK? From this you can see I reset/reuse variables… You only need i,j,k and so on when looping inside of loops… The lines that use $.writeln( someValue ); are how I write back to the console for debugging…

#target Illustrator

function tidyMyFile() {

    if ( app.documents.length == 0 ) { return; }

    var i, count, doc, rec, uil;

    uil = app.userInteractionLevel;

    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

    doc = app.activeDocument;

    count = doc.pathItems.length;

    $.writeln( count );

    for ( i = count-1; i >= 0; i-- ) {

        if ( doc.pathItems.fillColor.gray == 0 ) { doc.pathItems.remove(); }

    };

    count = doc.textFrames.length;

    $.writeln( count );

    for ( i = count-1; i >= 0; i-- ) {

        if ( doc.textFrames.contents == ' ' || doc.textFrames.contents == '  ' ) { doc.textFrames.remove(); }

    };

    rec = doc.pathItems.rectangle( 0, 0, doc.width/2, -doc.height/2 );

    //rec.fillColor = ;

    app.redraw();

    app.userInteractionLevel = uil;

};

tidyMyFile();

Edit the contents were \s or \s\s

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
Participant ,
Mar 04, 2012 Mar 04, 2012

Copy link to clipboard

Copied

LATEST

Many many thanks Mark! That was what I needed! I will repeat it again: many many thanks!!

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
Engaged ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Sorry for all the one-sided posts, guys...

but this works now (at least for me):

#target Illustrator

var docRef = app.activeDocument;

for ( var i = docRef.pageItems.length-1; i >= 0; i-- ) {

   

    var pathRef = docRef.pageItems;

   

    if ( pathRef.fillColor.black == 100 ) { pathRef.remove(); app.redraw(); }

};

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
Engaged ,
Mar 01, 2012 Mar 01, 2012

Copy link to clipboard

Copied

Jesse: Are you in CMYK color mode? Check:   File > Document Color Mode > CMYK Color

If you are in RGB then the fix is different and ES might be bombing out without giving youan error (see provious post)

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