Zurück zu Willert.de

API programming with python

how to access or perform things by using the Rhapsody API (not how to use the UI)

API programming with python

Postby Christian » August 6th, 2009, 2:00 pm

Hi there,

in a previous thread I just read that it's possible to program the Rhapsody API using python. I couldn't find anything on that topic in the docs or in the net. Can someone please point me to some documentation, tutorial or whatever might be useful on this topic?

I'm not that familiar with both: Java and VB; so python might be just what I was looking for.

Thanks,
Christian
Christian
 
Posts: 22
Joined: July 14th, 2009, 11:21 am
Location: Germany

Postby che » August 7th, 2009, 7:35 am

Hi Christian

I don't know if there is any doc on the net, but it's quite easy. (If your working in windows, I don't no how it is on Linux...)

All you need is a not too old python (2.6 or even 3.x) and the matching extension for Win32 (see http://sourceforge.net/projects/pywin32/)

As the Rhapsody API is COM, you will find several documentation on how to use COM from python in the net or even in the help coming with pywin32.
See http://oreilly.com/catalog/pythonwin32/chapter/ch12.html for a start.

I've attached a small example script to give you a basic idea on how to do it.

Well, have fun!
Christian
Attachments
RhapsodyAPIDemo.zip
Example for accessing the Rhapsody API using python.
Prints the name of the active project and tries to find a class named 'MyClass'. If the lookup succeeds, the classes property value of 'CG.Class.Concurrency' is printed
(460 Bytes) Downloaded 777 times
"I love deadlines. I like the whooshing
sound they make as they fly by." - Douglas Adams
che
 
Posts: 7
Joined: December 4th, 2007, 5:25 pm
Location: Zürich

Postby Christian » August 7th, 2009, 9:30 am

Hi Christian,

thanks for this little example; it worked perfectly.

I'm going to dig deeper into that topic in the near future. I'm not very familiar with COM, too, but at least I don't have to learn another language for the sole purpose of programming the Rhapsody API.

Thanks,
Christian
Christian
 
Posts: 22
Joined: July 14th, 2009, 11:21 am
Location: Germany

Postby Christian » August 14th, 2009, 12:27 pm

Hi Christian,

I just ran into a problem related to early-bound COM (I guess).

For example, when I retrieve a class-element via findNestedElementRecursive(), it returns an object of type IRPModelElement instead of IRPClass. Thus, I'm not able then to call any methods provided by IRPClass.

I suspect there is some kind of mechanism to cast an object to a specific type. -- But how does this work?

To the contrary, when I iterate over the elements returned by getNestedElements() they all have the correct (most specific) type.

Thanks,
Christian
Christian
 
Posts: 22
Joined: July 14th, 2009, 11:21 am
Location: Germany

Postby che » August 14th, 2009, 2:32 pm

Hi Christian

Oh yes. That's a problem with COM. I don't know exactly what the problem is, but COM is a bit strange anyway...


Well,
Code: Select all
win32com.client.Dispatch(rhpElement)

will help.

Have Fun
Christian
"I love deadlines. I like the whooshing
sound they make as they fly by." - Douglas Adams
che
 
Posts: 7
Joined: December 4th, 2007, 5:25 pm
Location: Zürich

Postby Christian » August 17th, 2009, 10:43 am

Hi Christian,

thanks a lot. It works. My code now looks somwhat like this:

Code: Select all
# When I have a class selected in Rhapsody
application = win32com.client.Dispatch("rhapsody.Application")
selected = application.getSelectedElement() # yields IRPModelElement

# force a cast
selected = win32com.client.Dispatch(selected) # yields IRPClass

# access an RPClass property
methods = selected.operations


Thanks,
Christian
Christian
 
Posts: 22
Joined: July 14th, 2009, 11:21 am
Location: Germany

Re: API programming with python

Postby ekeko » November 10th, 2010, 2:52 pm

Hi,
I am new in rhapsody and would also prefer to access the API via python. i just found this entry.

some question in general:
- it is also possible to create plug ins for rhapsody with python?
- rhapsody is cutting support for VBA development... would be affect this the access to rhapsody via COM?

thanks for any info.
ekeko
 
Posts: 6
Joined: October 15th, 2010, 5:44 pm
Location: Frankfurt, Germany

Re: API programming with python

Postby che » November 10th, 2010, 3:34 pm

Hi

The 'Rhapsody is cutting support for vba development'-thing is bothering me as well. But up till now, the COM-API is still part of the distribution... And I don't think, this will change quickly, as the Test Conductor uses the COM-API as well (AFAIK?) - Well if they do, Jython would be the answer.

The same is for PlugIns. To write them directly in python wouldn't work. But I think Jython should work here as well. I actually never tried to. But after writing my first Rhapsody Java-PlugIn two weeks ago, I really like to give it a try sometime.

Have Fun
Christian
"I love deadlines. I like the whooshing
sound they make as they fly by." - Douglas Adams
che
 
Posts: 7
Joined: December 4th, 2007, 5:25 pm
Location: Zürich


Return to Rhapsody API

Who is online

Users browsing this forum: No registered users and 1 guest

cron