|
Written by Gerald M.
|
|
Thursday, 08 October 2009 20:50 |
|
Often during development or debugging of an application, a programmer will wish to print out messages or values of variables to help him determine what is going on in the program. These are also helpful in communicating with the program's eventual end user. In a traditional environment, this sort of thing would be sent to STDOUT and observed in a command window. However, when developing an application within another application as we do with plugins and scripting in MagicDraw, this becomes more difficult because you don't exactly know where STDOUT is going to end up.
Fortunately, MagicDraw provides us with a solution. Within the application, there is a message area which the application uses to communicate with the end user. We can access this message area for our purposes. Have a look at the following code:
#log.rb
require 'java' include_class 'com.nomagic.magicdraw.core.Application' $mdMsg = Application.getInstance().getGUILog() $mdMsg.log("Hello World")
In this example, we load Ruby's java support, include MagicDraw's Application class, and then assign a handle to the message area to a Ruby variable. In this case I use a global variable because I find I want to access this log throughout my program. With this done, I simply pass in my string to the object's log method and it magically appears in the message area:

Now you can communicate with your end user or debug your script without leaving the safety and comfort of the MagicDraw application. Enjoy! |
|
Last Updated on Saturday, 10 October 2009 00:38 |