![]() |
Telelogic Rhapsody (steve huntington) | ![]() |
Topic Title: Changing stereotypes using VBA Topic Summary: Created On: 5-Mar-2007 12:46 Status: Read Only |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
That helps the problem! Super.
Johannes |
|
![]() |
Telelogic Rhapsody
» Rhapsody Category » Rhapsody
»
Changing stereotypes using VBA
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.