This article describes within a formal approach how to generate code from a graphical description based on diagrams. The method is general enough not to consider a specific methodology nor a specific target programming language. The essence of the method consists of combining Object Oriented ideas to capture the generality of diagrams and Attributed Grammars to solve the context-sensitive feature. A case study is presented.