I would like to connect my cylindric masses with a bold horizontal line like displayed in the following picture:

[![shaft model mit masses J_i](https://i.stack.imgur.com/jNALA.png)](https://i.stack.imgur.com/jNALA.png)

The following code works fine for the first connection:

```
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,intersections}

\begin{document}
\begin{tikzpicture}

\tikzstyle{mass} = [draw, fill=gray!20, cylinder, shape aspect=1, minimum width=1.5cm, minimum height=1cm, shape border rotate=180];

\foreach \xpos/\name/\tag in {0/J1/J_1, 2/J2/J_2, 4/J3/J_3, 6/J4/\cdots, 8/J5/J_n}
    {
    \node[mass, name=\name] at (\xpos cm,0cm) {};
    \draw[shift=(\name.center)] node[] {$\tag$};
    }

\path[name path=line1] (J2.before top) -- (J2.after top);
\path[name path=line2] (J2.top) -- (J2.bottom);
\draw[name intersections={of=line1 and line2}, thick] (J1.east) -- (intersection-1);

\end{tikzpicture}

```

For the obvious reasons, I would like to make the connections using a `\foreach` loop. I tried the following:

```
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,intersections}

\begin{document}
\begin{tikzpicture}

\tikzstyle{mass} = [draw, fill=gray!20, cylinder, shape aspect=1, minimum width=1.5cm, minimum height=1cm, shape border rotate=180];

\foreach \xpos/\name/\tag in {0/J1/J_1, 2/J2/J_2, 4/J3/J_3, 6/J4/\cdots, 8/J5/J_n}
    {
    \node[mass, name=\name] at (\xpos cm,0cm) {};
    \draw[shift=(\name.center)] node[] {$\tag$};
    }

\foreach \name1/\name2 in {J1/J2, J2/J3, J3/J4, J4/J5}
    {
    \path[name path=line1] (\name2.before top) -- (\name2.after top);
    \path[name path=line2] (\name2.top) -- (\name2.bottom);
    \draw[name intersections={of=line1 and line2}, thick] (\name1.east) -- (intersection-1); 
    }

\end{tikzpicture}

```

Unfortunately, in the second example, the second `\foreach` loop does not work. LaTeX throws an `\inaccessible` error during compilation. It seems that I cannot access the node names in the second `\foreach` loop in the way I did?