eso-pic provides \AddToShipoutPictureBG to add content to the background at every page and \AddToShipoutPictureBG* to add it only to the current page. \ClearShipoutPicture clears all the content. But there is no \ClearShipoutPicture* to clear the content only for the current page.
I would like to show some content in every page but chapter pages. Using \AddToShipoutPictureBG{} when the chapter is created doesn't work, since the previous content is not cleared, it is just added. If I use \ClearShipoutPicture I need to know when the page is changed to add the content again. How should I do this?
I also tried background, but \NoBgThispage is not working. I could use
\backgroundsetup{contents={ \begin{tikzpicture} ... \end{tikzpicture} ,angle=0 }} instead of \AddToShipoutPictureBG{...} and \backgroundsetup{contents={}} instead of \ClearShipoutPicture. The results is pretty much the same.
MWE:
\documentclass[a4paper,twoside,openright]{report} \usepackage{lipsum} \usepackage{filecontents} \begin{filecontents}{ch1.tex} \lipsum[1-3]\section{First section ch1}\lipsum[4-10] \end{filecontents} \begin{filecontents}{ch2.tex} \lipsum[11-14]\section{First section ch2}\lipsum[15-25] \end{filecontents} \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} \usepackage{xifthen} \usepackage{totcount} \usepackage{eso-pic} \usepackage{tikz,bm} \usetikzlibrary{shapes,arrows} \usetikzlibrary{calc,positioning} \regtotcounter{sidecnt} \newcounter{sidecnt} \colorlet{sidecolor}{red!75} \colorlet{sidelabelcolor}{blue} \def\vsidemargin{3.5cm} \AddToShipoutPictureBG{% \begin{tikzpicture}[overlay] \pgfmathsetmacro{\pheight}{(\paperheight-2*\vsidemargin)/28.453} \pgfmathsetmacro{\myt}{-(\vsidemargin/28.453)-(\thesidecnt-1)/\totvalue{sidecnt}*\pheight} \pgfmathsetmacro{\myb}{-(\vsidemargin/28.453)-\thesidecnt/\totvalue{sidecnt}*\pheight} \ifthenelse{\isodd{\value{page}}}{\def\corner{east}\def\sign{-}}{\def\corner{west}\def\sign{+}} \fill[sidecolor] ($(current page.north \corner)+(0,\myt)$) rectangle ($(current page.north \corner)+(\sign0.75,\myb)$); \node[font=\normalfont\sffamily\bfseries] at ($(current page.north \corner)+(\sign0.375,\myt-0.5)$) {\color{sidelabelcolor}\thechapter}; \end{tikzpicture} } \newcommand\importchapter[2]{ \chapter{#1} \stepcounter{sidecnt} %\ClearShipoutPicture* alike \input{#2} } \begin{document} \importchapter{First chapter}{ch1.tex} \importchapter{Second chapter}{ch2.tex} \end{document} I don't want the background to be shown in pages 1 and 5.

eso-picand then thought it would be better to open a new question. The difference between that question and this is that I'm actually using\inputto get a new chapter, and I don't want to modify its content. I provided a MWE and added some details.