Yes, I have. Several times.
My advice: Skip any of the coastal cities accessible by ferry. You get a "bordertown" experience there (think: Juarez or Tijuana, Mexico). Casablanca has little that's appealing to a visitor, it's just an ordinary city, and other than being the capital (so some visitors have to pass through there on international flights), it's not worth a stop IMHO. The better stuff is beyond.
Fly past all that. Go straight to Marrakech and/or Fes - that's the good stuff, they're different, and both are worth seeing. The good news is that flights to Marrakech and Fes from many cities in western Europe are dirt cheap. The only "trick" is that the cheap flights may not go every day (typically every 2 or 3 days) so be flexible when searching. And don't be afraid to get creative with your itinerary. It's not hard to go further, too, over the High Atlas mountains and to the edge of the great sand seas of the Sahara.
Good news: there are dirt-cheap flights to/from not just Spain, but Paris, too, so it's possible to travel between Paris and Spain (or vice versa) by using Morocco as a "bridge" of sorts. On one previous trip, I did exactly that: It was primarily a trip to Spain, but my flight home was from Paris. We flew from Madrid to Marrakech, spent about 5 days in Morocco, flew out from Fes to Paris. Within Morocco, we took the train from Marrakech to Fes.
Morocco is a big country with lots to see and do; don't short-change it (and yourself) by trying to squeeze it all into just a day or two there.