We study certain DT invariants arising from stable coherent sheaves in a nonsingular projective threefold supported on the members of a linear system of a fixed line bundle. When the canonical bundle of the threefold satisfies certain positivity conditions, we relate the DT invariants to Carlsson-Okounkov formulas for the twisted Eulers number of the punctual Hilbert schemes of nonsingular surfaces, and conclude they have a modular property.