I've reused the code from my answer to this question Add both part and chapter titles to list of figures with formatting and line wrapping
and just added a condition if figure counter is greater than zero, a \caption has been used (most likely). Clearly, this requires a per chapter resetting of the figure counter, which is true in standard classes (and unless not changed with chngcntr or \@remfromreset)
Note that the chapters without figures or with figures but without caption, they aren't added to the LoF!
\documentclass{book}
\usepackage{xpatch}
\makeatletter
% initial definitions of the part info (name and number)
\def\thisparttitle{}\def\thispartnumber{}
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\newtoggle{noTabs}
\newtoggle{newpart}
\xpatchcmd{\@part}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\xdef\thisparttitle{#1}% Evaluate the parameter #1
\global\togglefalse{noFigs}%
\global\togglefalse{noTabs}%
\global\toggletrue{newpart}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\xpatchcmd{\@chapter}{%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
}{%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
\xdef\thischaptertitle{#1}% Evaluate the parameter #1
\global\togglefalse{noFigs}%
\global\togglefalse{noTabs}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\makeatother
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\AfterEndEnvironment{figure}{%
\nottoggle{noFigs}{%
\ifnumgreater{\value{figure}}{0}{%
\iftoggle{newpart}{%
\addtocontents{lof}{\protect\contentsline{part}{\thepart\hspace{1em}\thisparttitle}{}{part.\theHpart}}%
\global\togglefalse{newpart}%
}{}%
\addtocontents{lof}{\protect\contentsline{chapter}{\protect\numberline{\thechapter}\thischaptertitle}{}{chapter.\theHchapter}}%
\global\toggletrue{noFigs}
}{}%
}{}%
}
\AfterEndEnvironment{table}{%
\nottoggle{noTabs}{%
\ifnumgreater{\value{table}}{0}{%
\iftoggle{newpart}{%
\addtocontents{lot}{\protect\contentsline{part}{\thepart\hspace{1em}\thisparttitle}{}{part.\theHpart}}%
\global\togglefalse{newpart}%
}{}%
\addtocontents{lot}{\protect\contentsline{chapter}{\protect\numberline{\thechapter}\thischaptertitle}{}{chapter.\theHchapter}}%
\global\toggletrue{noTabs}%
}{}%
}{}
}%
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\part{The first}
\chapter{Introduction with no Figures}
\chapter{Test Chapter with Figures}
\begin{figure}
\caption{caption text Number one}
\end{figure}
\begin{figure}
\caption{caption text Number two}
\end{figure}
\chapter{A chapter with figure, but no caption}
\begin{figure}
% One without figure
\end{figure}
\chapter{Test Chapter with no Figures}
\part{The second}
\chapter{Look no figures here either}
\chapter{Another Test Chapter with Figures}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
\caption{caption text from chapter \thechapter}
\end{figure}
\begin{figure}
% No caption
\end{figure}
\chapter{Another in the same part}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\part{Without figs}
\chapter{A chapter with a table}
\begin{table}
\caption{Some table}
\end{table}
\end{document}
