Mark,
That was an interesting exercise. :-)
The following script will do almost everything you want. I wasn't sure what
you meant by "Associate the activity with the operation". There isn't
anything in an activity that will associate it with an operation. In a
transition you can show a send target, send event, and send arguments... so
maybe that is what you were talking about?
Anyway, hopefully this gets you a long way there.
IMO, the Rose API is pretty cool in that you can do a lot with it, but some
times it is not very intuative how you go about doing it. So, in the
following script there are a few places where I had to cast stuff, because
it wasn't obvious how to get a SwimLane from a SwimLaneView, etc.
For this to work you have to make sure and have the swimlane selected in
the diagram. That can be a bit tricky. Also, when the activity is created it
is just thrown into the corner of the swimlane, so you'll have to move it by
hand... or modify the script to put it at a better location.
It has been my experience that getting started is sometimes the hardest
thing. After that, adding modifications is usually not to bad.
Have fun!
James
Sub Main
' Get the currently selected diagram
Dim diag As Diagram
Set diag = RoseApp.CurrentModel.GetSelectedDiagrams.GetAt(1)
If diag Is Nothing Then
msgbox "No diagram selected"
Exit Sub
End If
' Make sure it is a state diagram
Dim adiag As StateDiagram
If diag.CanTypeCast(adiag) Then
Set adiag = diag.TypeCast(adiag)
' and that the state diagram is really an activity diagram
If Not adiag.IsActivityDiagram Then
msgbox "State diagram selected, not activity diagram"
Exit Sub
End If
Else
msgbox "Activity diagram not selected"
Exit Sub
End If
' get the selected swim lane view
Dim slv As SwimLaneView
Set slv = adiag.GetSelectedSwimLaneViews.GetAt(1)
' and make sure one was selected
If slv Is Nothing Then
msgbox "No swimlane selected"
Exit Sub
End If
' Not sure how to get the swim lane from the swim lane view
' directly. So, get the item and cast it to a swim lane
Dim sl As SwimLane
Dim tmp As RoseItem
Set tmp = slv.Item
If tmp.CanTypeCast(sl) Then
Set sl = tmp.TypeCast(sl)
End If
' from the swim lane, get the class
Dim class As Class
Set class = sl.GetClass
' now as the user for the new operation name
Dim opName As String
opName = AskBox("Operation name?")
' create the operation in the class, giving it a blank type
' could ask the user for the return type
Dim op As Operation
Set op = class.AddOperation(opName,"")
' and add in the stereotype
op.Stereotype = "activity"
' Get the state machine from the diagram
Dim sm As StateMachine
Set sm = adiag.Parent
' And add an activity with the same name as the operation
Dim act As Activity
Set act = sm.AddActivity(opName)
' And then add it to the diagram
Dim av As ActivityView
Set av = adiag.AddActivityView(act)
End Sub
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> [EMAIL PROTECTED]
> Sent: Wednesday, January 24, 2001 6:34 AM
> To: [EMAIL PROTECTED]
> Subject: (ROSE) Automatic Operation Creation
>
>
>
> Hi,
>
> I need a little help in getting started with scripting. I am
> trying to put
> together a few routines to make life easier in my group who
> will be using
> Process Workbench to map out their business processes.
>
> Precondition : an open Activity diagram in the logical view
> with swimlanes
> that have a class associated.
>
> Script to :
> Create an activity in the swimlane
> Create an operation in the class associated with the swimlane.
> Stereotype the operation to "activity".
> Associate the activity in the diagram with the newly
> created operation
> in the class.
>
> If anyone can point me in a direction as to what to even look
> for to do
> this would be very happy.
>
> Thanks
>
> Mark
>
> **************************************************************
> **********
> * Rose Forum is a public venue for ideas and discussions.
> * For technical support, visit http://www.rational.com/support
> *
> * Admin.Subscription Requests: [EMAIL PROTECTED]
> * Archive of messages:
> http://www.rational.com/products/rose/usergroups/rose_forum.jtmpl
> * Other Requests: [EMAIL PROTECTED]
> *
> * To unsubscribe from the list, please send email
> *
> * To: [EMAIL PROTECTED]
> * Subject:<BLANK>
> * Body: unsubscribe rose_forum
> *
> **************************************************************
> ***********
>
************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Admin.Subscription Requests: [EMAIL PROTECTED]
* Archive of messages:
http://www.rational.com/products/rose/usergroups/rose_forum.jtmpl
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*
* To: [EMAIL PROTECTED]
* Subject:<BLANK>
* Body: unsubscribe rose_forum
*
*************************************************************************