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

Stroke thickness scripting advice

Explorer ,
Jan 14, 2020 Jan 14, 2020

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?

TOPICS
Print , Scripting
2.7K
Translate
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 3 Correct answers

Community Expert , Jan 14, 2020 Jan 14, 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

Translate
Community Expert , Jan 15, 2020 Jan 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
...
Translate
Community Expert , Jan 15, 2020 Jan 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

...
Translate
Community Expert ,
Jan 14, 2020 Jan 14, 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

Translate
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
Explorer ,
Jan 14, 2020 Jan 14, 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.

Translate
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 ,
Jan 14, 2020 Jan 14, 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

Translate
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
Explorer ,
Jan 15, 2020 Jan 15, 2020

The problem is that I won't be the author of the files, so I can't be sure how they'll be setup. that's why I'm looking for a broad spectrum solution.

Translate
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 ,
Jan 15, 2020 Jan 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

 

 

 

Translate
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
Explorer ,
Jan 15, 2020 Jan 15, 2020

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

Translate
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 ,
Jan 15, 2020 Jan 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;
	}
}  

 

Translate
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
Explorer ,
Jan 15, 2020 Jan 15, 2020

hmmm, for some reason that's not working for me. No error message, but also no results.

Translate
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 ,
Jan 15, 2020 Jan 15, 2020

Are you sure there is a page item with a stroke that is less than .8 pts? I’m setting the minimum and desired stroke in the two variables at the top. The weight is in points not mm.

Translate
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 ,
Jan 15, 2020 Jan 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:

 

MinimumLineWidth-Preflight-AcrobatPro-2.PNG

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Explorer ,
Jan 15, 2020 Jan 15, 2020

Hi Uwe,

In 99% of cases, you're right. But these are products being uploaded to a custom W2P solution and handling the correction of the files that was doesn't fit the workflow too well. In an ideal world, we'd want to fix all the issues with a file inside of InDesign when our designers are sorting out other issues such as bleed, margins, etc... We want to automate as much as is possible in terms of file preparation as we can. Using InDesign to do this instead of another piece of software like Acrobat or PitStop suits us better.

Translate
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 ,
Jan 15, 2020 Jan 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

Screen Shot 8.png

 

The result

 

The resultScreen Shot 9.png

Translate
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 ,
Jan 15, 2020 Jan 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.

EffectiveStrokeWeight-vs-NominalStrokeWeight-1.PNG

Why? Because one of the objects was scaled:

EffectiveStrokeWeight-vs-NominalStrokeWeight-2.PNG

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 )

Translate
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
Explorer ,
Jan 23, 2020 Jan 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.

 

error_with_stroke_thickness.PNG

 

//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?

Translate
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
Explorer ,
Jan 23, 2020 Jan 23, 2020

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

Translate
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 ,
Jan 23, 2020 Jan 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():

 

RedefineScaling-ChangesAppearanceOfObject.PNG

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Explorer ,
Jan 23, 2020 Jan 23, 2020
LATEST

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

Translate
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