It is currently Wed Feb 08, 2012 5:18 pm

All times are UTC



Welcome
Welcome to RHAPSODY4YOU

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, respond to polls, upload and download content, and access many other special features. Registration is fast, simple, and absolutely free, so please, register to join our community today.





 Page 1 of 1 [ 8 posts ] 
Author Message
 Post subject: API programming with python
PostPosted: Thu Aug 06, 2009 12:00 pm 

Joined: Tue Jul 14, 2009 9:21 am
Posts: 22
Location: Germany
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


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Aug 07, 2009 5:35 am 

Joined: Tue Dec 04, 2007 3:25 pm
Posts: 7
Location: Zürich
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:
File comment: 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

RhapsodyAPIDemo.zip [460 Bytes]
Downloaded 71 times

_________________
"I love deadlines. I like the whooshing
sound they make as they fly by." - Douglas Adams
Offline
 Profile  
 
 Post subject:
PostPosted: Fri Aug 07, 2009 7:30 am 

Joined: Tue Jul 14, 2009 9:21 am
Posts: 22
Location: Germany
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


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Aug 14, 2009 10:27 am 

Joined: Tue Jul 14, 2009 9:21 am
Posts: 22
Location: Germany
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


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Aug 14, 2009 12:32 pm 

Joined: Tue Dec 04, 2007 3:25 pm
Posts: 7
Location: Zürich
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,
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
Offline
 Profile  
 
 Post subject:
PostPosted: Mon Aug 17, 2009 8:43 am 

Joined: Tue Jul 14, 2009 9:21 am
Posts: 22
Location: Germany
Hi Christian,

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

# 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


Offline
 Profile  
 
 Post subject: Re: API programming with python
PostPosted: Wed Nov 10, 2010 12:52 pm 

Joined: Fri Oct 15, 2010 3:44 pm
Posts: 6
Location: Frankfurt, Germany
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.


Offline
 Profile  
 
 Post subject: Re: API programming with python
PostPosted: Wed Nov 10, 2010 1:34 pm 

Joined: Tue Dec 04, 2007 3:25 pm
Posts: 7
Location: Zürich
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
Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:


suspicion-preferred