Not quite sure why you had that problem. Did you copy the macro code to the script editor and set the language to ‘IJ1 Macro’ before trying to run it?
Below I have annotated the code to make it clear what happens in each line. I also noted that in my rush yesterday, I overlooked to set the dimensions of the temporary image correctly (it was fixed to 512x512), which would cause some problems for images of different dimensions. This is now fixed in the updated code below.
You could put the whole code into an action tool to give you a button on the menu bar to run the code.
Glad it is working for you.
image=getImageID(); //get image ID
getDimensions(width, height, channels, slices, frames); //get size of current image
newImage("Lines", "8-bit black", width, height, 1); //create a blank image with same dimensions
roiManager("Deselect"); //make sure that nothing is selected in ROI manager
roiManager("Draw"); //draw white lines for ROIs on new blank image
run("Analyze Particles...", " show=Masks display include"); //use Analyze Particles to create mask of the lines with the area enclosed by lines filled
run("Invert LUT"); //invert LUT to show lines as white on black background
run("Options...", "iterations=1 count=1 black do=Open"); //use binary open to remove overhanging ends of lines
run("Analyze Particles...", " show=Nothing include add"); //use Analyze Particles to create new ROI of area enclosed by lines
close("Lines"); //close temporary 'Lines' image
close("Mask of Lines"); //close temporary 'Mask of Lines' image
//return focus to original image