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

Is there a script that will image trace a selection of raster objects?

Community Beginner ,
Sep 26, 2015 Sep 26, 2015

Copy link to clipboard

Copied

Hi there! Here's my problem:

I need to run Image Trace —with a specific preset— plus an Action on each object in a selection. So, basically I would like to run Image Trace (preset) + Action on each object in my active selection.

Is there already a scrip out there for this and if not how would I build one? I'm new to scripting, which means I basically have no idea what I'm doing. Can anyone help me?

TOPICS
Scripting

Views

4.8K

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

Guide , Oct 04, 2015 Oct 04, 2015

Sorry,

a poor line of code on my part was causing the issue.

Line 14 in to code checks for a Raster Item

I was just testing the object itself.

I should have been testing its typename.

replace that line with this:

if(sel.typename == 'RasterItem'){ 

that should fix the issue

Votes

Translate

Translate
Adobe
Guide ,
Sep 27, 2015 Sep 27, 2015

Copy link to clipboard

Copied

This should do what you are wanting.

but at a guess the action could be added to the script.

what does the action do?

function myTrace(){

    //-----User Set Variables-------

    var Tracing_Preset = 'High Fidelity Photo';

    var My_Action_Name = 'Rotate .5';

    var From_Set_Name = 'MyActions';

    //--------------------------------------

    if(app.tracingPresetsList.indexOf(Tracing_Preset)<0){

        alert('cannot find tracing preset that has been set in the script');

        return;

    }

    var doc = app.activeDocument;

    var sel = doc.selection;

    for(var i = 0; i<sel.length; i++){

        if(sel == '[RasterItem ]'){

            var pic = sel.trace();

            pic.tracing.tracingOptions.loadFromPreset(Tracing_Preset);

            pic.tracing.expandTracing().selected = true;

        }

    }

    // no test to confirm the action is present. make sure action name and set name are correct. they are case sensitive.

    app.doScript(My_Action_Name, From_Set_Name);

}

// add indexOf prototype to Array's

Array.prototype.indexOf = function(needle) {

    for(var i = 0; i < this.length; i++) {

        if(this === needle) {

            return i;

        }

    }

    return -1;

};

myTrace();

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
Community Beginner ,
Sep 30, 2015 Sep 30, 2015

Copy link to clipboard

Copied

Hi! Sorry it's taken me so long to reply; I don't have a lot of free time during the week. But I will give this a shot this weekend to see if it works. Thank you very much, by the way, for helping me out on this.  🙂

To answer your question; the action ungroups the trace and applies a graphic style and then groups them again. It sounds redundant but it does what I need it to do.

Thanks again and I will let you know if your script works this weekend.  🙂

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
Guide ,
Sep 30, 2015 Sep 30, 2015

Copy link to clipboard

Copied

you can keep the second part as an action and still run it from the script.

if you want to add the following piece of code to the very bottom of the code above.

then give it the action name and it parent set name.

// Set your action name and the set name that it belongs to here

var myAction = "put action name here between the quotes";

var mySet = "put set name here between the quotes";

//---------------------------------------------------------------------------------

try {

    app.doScript(myAction, mySet);

} catch(e) {

    alert("The " + myAction + "Action is not available in the " + mySet " Set.");

}

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
Community Expert ,
Oct 24, 2015 Oct 24, 2015

Copy link to clipboard

Copied

Hi Qwertyfly, I was trying to use your script from post #3 to play an action, however I receive the following error:

Error 25: Expected: ).

Line: 8

alert("The " + myAction + "Action is not available in the " + mySet " Set.");

I tried removing “extra” lines of code, however the action does not play. CS6 Mac.

Looking at the following thread, it may not be possible with JS, only AS and VBS:

JavaScript to Play Illustrator Action

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 ,
Oct 24, 2015 Oct 24, 2015

Copy link to clipboard

Copied

You have missed a '+' sign of concatenation in alert method after myset;


alert("The " + myAction + "Action is not available in the " + mySet +" Set.");

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
Community Expert ,
Oct 24, 2015 Oct 24, 2015

Copy link to clipboard

Copied

Thank you UpendraSengarr and ThinkingThings – all good now, glad to see that this also works via JavaScript too!

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
Guide ,
Oct 25, 2015 Oct 25, 2015

Copy link to clipboard

Copied

strange that I missed that.

I normally copy and paste all the code after testing it.

I must have changed the alert a bit and forgotten to test it.

Glad you got it working.

Thanks to those who responded nice and quickly.

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
Community Expert ,
Oct 25, 2015 Oct 25, 2015

Copy link to clipboard

Copied

Thanks Qwertyfly, one character can make all the difference, even more so when one does not know what to look for! :]

I was trying to take this one step further, by adding BridgeTalk code in order to make this accessible from Adobe Bridge, however I am not having any luck randomly copying and pasting code. Would be good to be able to select a bunch of AI files in Bridge and then run an script on them all using the Tools/Illustrator menu (yes, I know that there are batch actions and that actions can reference an inserted script).

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 ,
Oct 24, 2015 Oct 24, 2015

Copy link to clipboard

Copied

Try adding a “+” sign after mySet as follows:

alert("The " + myAction + "Action is not available in the " + mySet + " Set.");

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
Community Beginner ,
Oct 04, 2015 Oct 04, 2015

Copy link to clipboard

Copied

Hey Qwertyfly,

The tracing part of the script doesn't seem to be working correctly. The objects remain at their default state after I run the script. I don't receive any error messages either. The action seems to work though. 🙂  Is there any information I can give you to help figure out what is not working?

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
Guide ,
Oct 04, 2015 Oct 04, 2015

Copy link to clipboard

Copied

Not sure what you mean by default state.

are you saying it does not trace at all.

or does not expand?

what version of illustrator are you running?

it does only run on selected items.

if you want to run it on the whole document we can tweak it to do that.

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
Community Beginner ,
Oct 04, 2015 Oct 04, 2015

Copy link to clipboard

Copied

Yes, the objects are not tracing at all.

I'm running the latest version of Illustrator CC 2015.

I do want the script to run only on the selected objects.

The objects I'm working with are imported directly from Photoshop; as in I open the Photoshop doc with Illustrator. I don't know if that makes a difference or not.

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
Guide ,
Oct 04, 2015 Oct 04, 2015

Copy link to clipboard

Copied

Sorry,

a poor line of code on my part was causing the issue.

Line 14 in to code checks for a Raster Item

I was just testing the object itself.

I should have been testing its typename.

replace that line with this:

if(sel.typename == 'RasterItem'){ 

that should fix the issue

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
Community Beginner ,
Oct 06, 2015 Oct 06, 2015

Copy link to clipboard

Copied

That did the trick! Thank you so much! I'm an illustrator and although I try to remain technologically savvy I have my limits. Thank you again!  🙂

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
Guide ,
Oct 06, 2015 Oct 06, 2015

Copy link to clipboard

Copied

Glad I could help out

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
Community Beginner ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

LATEST

Hi guys! This script has suited me too. Almost. I need to insert select all, and i need to batch this all. I try to do it myself, but something wrong. Can anyone help 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