The number of configurations W(N,z;r,v(r),alpha-i;M,beta-i,x(i)) of a polymer in a field of fixed obstacles is obtained. The cubic lattice of N sites has a coordination number z and is of d = z/2 dimensions. The obstacles are modeled as rigid rods or rigid but bent polymers of length r and of volume fraction upsilon-r. A fraction alpha-i of the obstacle bonds are oriented in orientation i. The flexible polymer which we place into the field of rigid obstacles is of length M, has beta-i of its bonds lying in orientation i, and has an end-to-end-length given by x(i). The formula for W results in expectation values only a few percent different from the exact expressions for the known special cases. The beta-i are not fixed numbers but rather occur with a probability given by W. With the maximum term method the dimensions of the polymer are calculated. The polymer is elongated in the direction of alignment of the obstacles. The volume of the polymer is found to increase with volume fraction of obstacles for isotropically ordered obstacles, but it decreases for high concentrations of obstacles if the obstacles are strongly aligned. The scaling law exponent upsilon describing molecular weight dependence of linear polymer dimension is 0.6 for each of the three dimensions but deviates from this value for large elongation. Seven possible applications of the formula are discussed.