Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic Rhapsody (steve huntington)
Decrease font size
Increase font size
Topic Title: Changing stereotypes using VBA
Topic Summary:
Created On: 5-Mar-2007 12:46
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 5-Mar-2007 12:46
User is offline View Users Profile Print this message


Mats Lundin

Posts: 3
Joined: 21-Feb-2007

I am trying to create a VBA macro which makes changes in the stereotypes of an interface. The Interface is just a RPClass stereotyped as "Interface". I have added a custom Stereotype (named "info") to the Interface but now I would like to change the interface so that it is instead stereotyped as another custom Stereotype ("request"). Both these stereotypes are stored in my "Profiles" directory and I can get hold of both of them.

The first problem is that the method "removeStereotype" only yields a "Run-time error '438': Object doesn't support this property or method".

The second problem is that the method "addStereotype" only yields a "Run-time error '-2147221498 (80040006): Method 'addStereotype' of object 'IRPClass' failed".

My code would be something like (unimportant rows skipped):

[FONT=Courier New]
Dim i as RPClass
i = getSelectedElement()
Dim s as RPStereotype
For Each s In i.stereotypes
If Not s.name = "Interface" Then ' We would not like to remove this
i.removeStereotype(s)
End If
Next s
s = i.addStereotype("request", "Stereotype")[/FONT]


What am I doing wrong? How should I use the ".addStereotype()" and ".removeStereotype()" methods?

//Johannes
Report this to a Moderator Report this to a Moderator
 8-Mar-2007 13:50
User is offline View Users Profile Print this message


Simon Morrish

Posts: 127
Joined: 17-May-2005

Hi Johannes

You were nearly there! Try this:

[CODE]Dim i As RPClass
Set i = getSelectedElement()
Dim s As RPStereotype
For Each s In i.stereotypes
If Not s.name = "Interface" Then ' We would not like to remove this
i.removeStereotype s
End If
Next s
Set s = i.addStereotype("request", i.metaClass)[/CODE]

Explanation:

You need to use "Set" when allocating an object to a variable, and you don't need to use parentheses when passing arguments to a subroutine (unless you use "Call"). Often, the inclusion of parentheses of around a single argument to a subroutine will make no difference, but in the case of removeStereotype it does. I haven't considered why exactly, but I suspect (s) might return the default property of s, not s itself. (Anyone?)

The second argument of addStereotype seems to serve no purpose. Passing an empty string appears to work equally well. :confused: Perhaps it's a backwards-compatibility thing...

Let me know if that helps, or if you have any further troubles!

best regards,
Simon

-------------------------
Simon Morrish
simon.morrish@eu.panasonic.com
http://panasonic.co.uk
Panasonic ideas for life
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 06:57
User is offline View Users Profile Print this message


Mats Lundin

Posts: 3
Joined: 21-Feb-2007

That helps the problem! Super.

Johannes
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic Rhapsody forum.
There are currently 1 users logged in.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.