You have to use enginnering judgement on this. If the 3D structure is regular, that is with identical 2D frames, with equal spacing between them, bracing is evenly distributed (or doesn't exist), the loads are uniform at any level etc, then a first approach would be to assign to the 2D frame, the gravity loads, at either side of the frame (up to the half spacing distance). Doing so, you assume that no framing exists in the perpendicular direction, but normally this is not against safety.
For a more robust method, you have to distribute the uniform gravity loads of the 3D straucture to the nearest beams, and then collect for each beam the mass that is assigned to it. Normally no mass is assigned to column elements and bracing, other than self weight.
Also pay attention which loads contribute to the mass. Normally the dead loads and a part of the live load is included for seismic analysis, but that depends on the seismic code.