What you want isn't any problem, if all headings are in \normalsize
and the vertical spaces before and after headings are integer multiples of \baselineskip
:
\documentclass[parskip=never]{scrbook}% never stretch the paragraph skips
\usepackage{blindtext}
\usepackage{atbegshi,picture,xcolor}
% baseline grid
\newcommand{\printbaselines}{%
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\color{red}%
\put(\dimexpr 1in+\ifodd\value{page}\oddsidemargin\else\evensidemargin\fi,
-\dimexpr 1in+\topmargin+\headheight+\headsep+\topskip)%
{%
\vtop to\dimexpr\vsize+\baselineskip{
\hrule
\leaders\vbox to\baselineskip{\hrule width\hsize\vfill}\vfill
}%
}%
}%
}%
}%
\printbaselines
\setkomafont{chapter}{\normalsize}
\setkomafont{section}{\normalsize}
\RedeclareSectionCommand[beforeskip=2\baselineskip,afterskip=1\baselineskip,afterindent=false]{chapter}
\RedeclareSectionCommand[beforeskip=2\baselineskip,afterskip=\baselineskip,runin=false,afterindent=false]{section}
\begin{document}
\chapter{First}
\section{Lorem I}
\Blindtext[1]
\section{Lorem II}
\Blindtext[1]
\section{Lorem III}
\Blindtext[2]
\section{Lorm IV}
\Blindtext[1]
\end{document}

But if other font sizes of the headings should be allowed, extra effort is needed to make the height of each heading an integer multiple of the normal \baselineskip
again. In this case you have to put each heading into a box, measure the height and depth of this box, change the height and depth if not a multiple of the normal \baselineskip
and then print the changed box. This can be done by a redefinition of \chapterlinesformat
and \sectionlinesformat
, e.g.,
\documentclass[parskip=never]{scrbook}
\usepackage{blindtext}
\usepackage{atbegshi,picture,xcolor}
% baseline grid
\newcommand{\printbaselines}{%
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\color{red}%
\put(\dimexpr 1in+\ifodd\value{page}\oddsidemargin\else\evensidemargin\fi,
-\dimexpr 1in+\topmargin+\headheight+\headsep+\topskip)%
{%
\vtop to\dimexpr\vsize+\baselineskip{
\hrule
\leaders\vbox to\baselineskip{\hrule width\hsize\vfill}\vfill
}%
}%
}%
}%
}%
\printbaselines
\newlength{\gridbaselineskip}
\newlength{\gridstrutheight}
\newlength{\gridstrutdepth}
\AtBeginDocument{%
\setlength{\gridbaselineskip}{\baselineskip}
\setlength{\gridstrutheight}{\ht\strutbox}
\setlength{\gridstrutdepth}{\dp\strutbox}
\RedeclareSectionCommand[beforeskip=2\gridbaselineskip,afterskip=1\gridbaselineskip,afterindent=false]{chapter}
\RedeclareSectionCommand[beforeskip=2\gridbaselineskip,afterskip=1\gridbaselineskip,runin=false,afterindent=false]{section}
}
\newcommand*{\usegridbox}[1]{%
% independent from the real height and depth use the height an depth of one grid-line
\ht#1\gridstrutheight
\dp#1\gridstrutdepth
\normalsize\usebox#1\par
}
\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
\sbox\@tempboxa{\@hangfrom{#2}{#3}}%
\usegridbox\@tempboxa
}
\renewcommand*{\sectionlinesformat}[4]{%
\sbox\@tempboxa{\@hangfrom{\hskip#2#3}{#4}}%
\usegridbox\@tempboxa
}
\makeatother
\begin{document}
\chapter{First}
\section{Lorem I}
\Blindtext[1]
\section{Lorem II}
\Blindtext[1]
\section{Lorem III}
\Blindtext[2]
\section{Lorm IV}
\Blindtext[1]
\end{document}

Note, here I've used a very simple change of the box size: setting the height and depth of the heading always to the height and depth of one grid line. If you have headings with multiple lines, you have to use a more intelligent approach with balancing the needed extra space before and after the heading. And then you also have to think about grid setting of the multiple lines of the heading. With the shown simple solution the one line of heading always is grid aligned.