Skip to main content
nathanwoulfe
Participant
September 11, 2015
Answered

place, trace, expand and stroke - stuck on stroke

  • September 11, 2015
  • 1 reply
  • 516 views

I'm trying to write a script to iterate the files in a folder - I need to place, trace, expand and stroke each.

So far, I have the code below working nicely - I can place, trace and expand but can't work out how to add the stroke?

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

            lay = doc.layers.add();    

            lay.name = fileList.name.slice(0, -4);  

            thisPlace = doc.placedItems.add();                           

            thisPlace.file = allFiles;                         

            thisImage = thisPlace.trace();                                                                  

            thisImage.tracing.tracingOptions.loadFromPreset( 'myPreset' );  

            var thisTracing = thisImage.tracing.expandTracing();

}

I've edited the script for brevity's sake - everything else is working, I just can't get the stroke. I think the issue I'm having is knowing what object to apply the stroke to.

Any advice would be brilliant.

This topic has been closed for replies.
Correct answer W_J_T

Not sure what exactly you are after but: tracingOptions has a strokes boolean you can use, otherwise you could iterate through the pathItems of each tracing item once expanded and apply a stroke directly with whatever attributes you desire. Hope something proves useful to your efforts.

1 reply

W_J_TCorrect answer
Inspiring
September 11, 2015

Not sure what exactly you are after but: tracingOptions has a strokes boolean you can use, otherwise you could iterate through the pathItems of each tracing item once expanded and apply a stroke directly with whatever attributes you desire. Hope something proves useful to your efforts.

nathanwoulfe
Participant
September 11, 2015

You sir, are a gentleman and a scholar - I hadn't seen the pathItems object within the tracing item.

var pathItems = thisTracing.pathItems;

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

  var ipath = pathItems

  ipath.stroked = true; 

  ipath.strokeWidth = strokeWidth[lay.name]

  } 

works perfectly, where strokeWidth is an object storing references to the layer names and a width value.

Thanks for your help, really appreciate it.

Inspiring
September 11, 2015

You're welcome glad it helped you sort things out for your desired outcome. Interesting use of the width reference. I would like to point out however to be careful declaring variables using reserved words from the AI DOM or JS in general, ie: pathItems, etc., it may cause internal conflict of the scripting engine and/or headaches for yourself overall at some point. ;-)