Skip to main content
Known Participant
January 15, 2020
Answered

Stroke thickness scripting advice

  • January 15, 2020
  • 5 replies
  • 2508 views

I get a lot of files with tables in them, that are constructed with strokes that are less than 0.25mm thick, is there a way, to select all these thin lines, and then bump them up to 0.25mm?

This topic has been closed for replies.
Correct answer Laubender

Hi together,

I'd still prefer a fix on the PDF output.

 

Reasons:

1. An ExtendScript cannot inspect and change the contents of placed vector graphics.

2. It's next to impossible to catch cases where strokes are showing only partly because they are pasted inside other objects and therefore are clipped.

3. How about strokes on text like Underline, Rule Above, Rule Below etc.pp.?

 

All this can be treated by PDF preflight.

With Acrobat Pro, with PitStop or pdfToolbox etc.pp.

 

Below just a special case not mentioned above where one item is scaled and another one is not. Effective stroke weight vs nominal stroke weight. Both objects appear to have the same nominal stroke weight of 20 Pt. Effectively both stroke weights are very different.

Why? Because one of the objects was scaled:

How should we handle issues like that by scripting?

Solution: We could "Redefine Scaling as 100%" first and then hunt for nominal stroke weights.

 

// Added one line to Rob's code to redefine scaling:

var minstroke = .8;
var newstroke = 1;
var api = app.activeDocument.allPageItems;

for(var i=0; i < api.length; i++){ 
    
	try
	{
	// First redefine scaling as 100%:
	api[i].redefineScaling();
	
	// Then go for the stroke weights:
	if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke)
	{
		api[i].strokeWeight=newstroke;
	}

	}catch(e){};
		
};

// Now do tables as well using Manan's code:
// …

 

Regards,
Uwe Laubender

( ACP )

5 replies

Community Expert
January 23, 2020

Hi,

I would be very cautious using redefineScaling() in every situation. The appearance of an object could change if the scaling factor for width and height is different! See my sample below where the top object is the scaled one and the one below is the version where I did redefineScaling():

 

 

Regards,
Uwe Laubender

( ACP )

n0ugh7_zaAuthor
Known Participant
January 24, 2020

thanks, Uwe, I've got lots of warnings when the before the script is run, that it could be dangerous.

LaubenderCommunity ExpertCorrect answer
Community Expert
January 15, 2020

Hi together,

I'd still prefer a fix on the PDF output.

 

Reasons:

1. An ExtendScript cannot inspect and change the contents of placed vector graphics.

2. It's next to impossible to catch cases where strokes are showing only partly because they are pasted inside other objects and therefore are clipped.

3. How about strokes on text like Underline, Rule Above, Rule Below etc.pp.?

 

All this can be treated by PDF preflight.

With Acrobat Pro, with PitStop or pdfToolbox etc.pp.

 

Below just a special case not mentioned above where one item is scaled and another one is not. Effective stroke weight vs nominal stroke weight. Both objects appear to have the same nominal stroke weight of 20 Pt. Effectively both stroke weights are very different.

Why? Because one of the objects was scaled:

How should we handle issues like that by scripting?

Solution: We could "Redefine Scaling as 100%" first and then hunt for nominal stroke weights.

 

// Added one line to Rob's code to redefine scaling:

var minstroke = .8;
var newstroke = 1;
var api = app.activeDocument.allPageItems;

for(var i=0; i < api.length; i++){ 
    
	try
	{
	// First redefine scaling as 100%:
	api[i].redefineScaling();
	
	// Then go for the stroke weights:
	if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke)
	{
		api[i].strokeWeight=newstroke;
	}

	}catch(e){};
		
};

// Now do tables as well using Manan's code:
// …

 

Regards,
Uwe Laubender

( ACP )

n0ugh7_zaAuthor
Known Participant
January 23, 2020

Hi Uwe,

This works well, when i run it as a script by itself, but ,when I add it to my script and run it as a function it keeps giving me an "undefined" error.

 

 

//FIX STROKES// INCREASES STROKE WEIGHT OF STROKES BELOW 0.25MM    
var button8 = group3.add("button", undefined, undefined, {name: "button9"}); 
    button8.enabled = true; 
    button8.helpTip = "Finds strokes thinner than 0.25mm, and makes them 0.25mm."; 
    button8.text = "Fix Strokes"; 
    win.group1.group3.button8.addEventListener("click", function(){
    var minstroke = .24;
    var newstroke = .25;
    var api = app.activeDocument.allPageItems;
    for(var i=0; i < api.length; i++){try{api[i].redefineScaling(); 
    if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke) {api[i].strokeWeight=newstroke;}}catch(e){};};});

What am I doing wrong?

n0ugh7_zaAuthor
Known Participant
January 23, 2020

i figured it out, the name of the button was wrong

Community Expert
January 15, 2020

Hm, hm, hm…

Working with allPageItems is ok unless you are encounting groups where the individual items have different stroke weights.

Or until you encounter graphic objects that do know nothing about stroke weights.

 

And then it could be that page items are scaled and the effective stroke weight is different from the nominal one.

 

All in all I think it would be better to do corrections like that after exporting the pages to PDF.

There is the function Fix Hairlines under Print Production of Acrobat Pro. Also a couple of preflight single fix actions you could duplicate and edit to your needs:

 

 

Regards,
Uwe Laubender

( ACP )

rob day
Community Expert
Community Expert
January 15, 2020

Hi Uwe, I think you are right that a simple script would not catch everything.

 

With .allPageItems if I add a try statement the script works with groups—it gets all of the items inside of multiple groups, but skips the group. If I group 5 page items and get the length of .allpageitems, it returns 6 not 1. So this works with multiple groups and page items (but not tables).

 

 

 

 

var minstroke = .8
var newstroke = 1
var api = app.activeDocument.allPageItems;

for(var i=0; i < api.length; i++){ 
    
    try{
        if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke){
            api[i].strokeWeight=newstroke;
        }
    }catch(e){}  
}  

 

 

 

A mix of items with strokes, some less than .7pt

 

The result

 

The result

rob day
Community Expert
Community Expert
January 15, 2020

In AppleScript it would be something like this. The stroke weight by default is set in points, so .25mm = .709pts and here I’m getting every stroke weight that is less than .8pt and setting it to 1pt. If you are not using OSX it should be easy to translate to JS

 

 

 

tell application id "com.adobe.indesign"
	set api to all page items of active document
	repeat with x in api
		if stroke weight of x is greater than 0 and stroke weight of x is less than .8 then
			set stroke weight of x to 1
		end if
	end repeat
end tell

 

 

 

n0ugh7_zaAuthor
Known Participant
January 15, 2020

unfortunately, I need it to be platform-independent because we'll be running the script on macOS and Windows-based machines.

rob day
Community Expert
Community Expert
January 15, 2020

I think this JS will work for page items. You could combine it with Manan’s JS to get tables.

 

var minstroke = .8
var newstroke = 1
var api = app.activeDocument.allPageItems;

for(var i=0; i < api.length; i++){  
    if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke){
        api[i].strokeWeight=newstroke;
	}
}  

 

Community Expert
January 15, 2020

Try the following

function changeTableBorder(t)
{
	for(var i = 0 ; i < t.length; i++)
	{
		var tt = t[i].cells.everyItem().tables.everyItem().getElements()
		if(tt.length)
			changeTableBorder(tt)
		
		t[i].bottomBorderStrokeWeight = t[i].leftBorderStrokeWeight = t[i].rightBorderStrokeWeight = t[i].topBorderStrokeWeight = ".25 mm"
	}
}
var t = app.documents[0].stories.everyItem().tables.everyItem().getElements()
changeTableBorder(t)

 

-Manan

-Manan
n0ugh7_zaAuthor
Known Participant
January 15, 2020

Sorry my explanation wasn't good.

 

There are other elements in the designs that are also made up of very thin strokes, that would need to be thickened up.

 

I'm looking for something that can run through the entire active document, and select all strokes below 0.25mm, and then make them 0.25mm.

Community Expert
January 15, 2020

Rather than doing this, how about making changes to the styles applied on these objects. This would be a quick way to edit everything, make changes in object styles, table styles, cell styles etc and you should be good.

 

-Manan

-Manan