Skip to main content
ptrstout
Participant
September 26, 2015
Answered

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

  • September 26, 2015
  • 2 replies
  • 5990 views

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?

This topic has been closed for replies.
Correct answer Qwertyfly___

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.


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

2 replies

Known Participant
August 9, 2018

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?

Qwertyfly___
Legend
September 28, 2015

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();

ptrstout
ptrstoutAuthor
Participant
September 30, 2015

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.  :-)

Qwertyfly___
Legend
September 30, 2015

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.");

}