Last Updated:

Creating Interface Specifications from Running Instances (Combining Java with the Rhapsody Tracer)

Andy Lapping Helper

Recently a friend of mine asked me if it was possible to grab a 'snapshot' of a running object in a Rhapsody animation so it could be turned into an instance specification. Which got me thinking about how we can interact with a Rhapsody animation from the outside world. Rhapsody has no API for its animator but in the past I've used Webify to do this - combining a Java applet for example, or using NodeRed. But then I landed on another solution. 

You may already know that Rhapsody has a Tracer. Originally added so we can interact with an executing model without manually driving it through the UI, instead using textual commands. Those commands can be entered into the Rhapsody command line or in a script, and the output can be redirected to 'standard out' or a text file.  

What you may not know is that those same commands may be entered through the API - there is a single API function called IRPApplication.enterAnimationCommand

Here is a sample which includes a sample model, a helper and the eclipse project that created it. The solution uses the API call above to instruct the tracer to output instance attribute data to an output file - it then reads and parses that file and uses the information to create a new instance specification. 

To try it:

  1. Extract the helper into Rhapsody/UserShare/Helpers
  2. Open the sample model 
  3. Generate Make and Run (or Full Build)
  4. Click Go
  5. Right-click the Class/Instance and select Create Instance Spec from Running Object
  6. In the UI Click Create

Note that you must manually specify the instance name. Rhapsody provides no access to running instance data through the API (selecting a running instance is exactly the same as selecting its Class as far as the API is concerned).