Here we report a single-step direct writing technology for making three-dimensional (3D) macroporous photonic crystal patterns on a new type of pressure-responsive shape memory polymer (SMP). This approach integrates two disparate fields that do not typically intersect: the well-established templating nanofabrication and shape memory materials. Periodic arrays of polymer macropores templated from self-assembled colloidal crystals are squeezed into disordered arrays in an unusual shape memory "cold" programming process. The recovery of the original macroporous photonic crystal lattices can be triggered by direct writing at ambient conditions using both macroscopic and nanoscopic tools, like a pencil or a nanoindenter. Interestingly, this shape memory disorder-order transition is reversible and the photonic crystal patterns can be erased and regenerated hundreds of times, promising the making of reconfigurable/rewritable nanooptical devices. Quantitative insights into the shape memory recovery of collapsed macropores induced by the lateral shear stresses in direct writing are gained through fundamental investigations on important process parameters, including the tip material, the critical pressure and writing speed for triggering the recovery of the deformed macropores, and the minimal feature size that can be directly written on the SMP membranes. Besides straightforward applications in photonic crystal devices, these smart mechanochromic SMPs that are sensitive to various mechanical stresses could render important technological applications ranging from chromogenic stress and impact sensors to rewritable high-density optical data storage media.