SlideShare a Scribd company logo
Introduction to Rational Rose 98i Module 11: RoseScript
Objectives:  RoseScript You will be able to: Understand RoseScript concepts Use RoseScript to: Obtain information from a Rose model Add information to a Rose model Update a Rose model Integrate with third-party products
What is RoseScript? RoseScript is a full-featured Basic scripting language It is a customized version of Summit Basic Script
Uses of RoseScript Get information out of a model Extract all or a portion to export  Generate custom reports Perform checks on the model Enforce project/enterprise semantic check Print to a log window Create information to model Add and/or update model components  Create and/or update interaction diagrams and/or class diagrams Integrate with third-party tools
How are Scripts Executed? Interactive Executed via the Start button on the Scripting Window toolbar Compiled Saved as a file (.ebx) that may be executed Rose menu may be updated to include any compiled script
How are RoseScript Classes Used? Each RoseScript class has a defined interface Properties and methods that are used to access information in the Rose model Example Application class property Visible Controls whether the Rose application is visible on the screen Application class method OpenModel Opens a Rose model
RoseApp RoseApp is a global application object All RoseScript programs have access to this object Example RoseApp.CurrentModel is the currently open model in Rose It is an instance of the Model class RoseApp.Height is the height of the main window RoseApp.CurrentModel.Save will save the current open model
RoseScripts and Color Scripts appear in color Keywords are in  blue Comments are in  green Code is in  red Everything else is black
Some “Basic” Terms Add a comment  ‘This is a comment Declare a subroutine Sub Name (arglist)  Terminate a subroutine End Sub or Exit Sub Declare the main subroutine  Main() Declare a local variable along with its type Dim variable As type
Some “Basic” Terms Print data to an output device Print Repeat a block of statements for each element in a collection or array For Each member in group [statements] [Exit For] [statements] Next [member]
Some “Basic” Terms Repeat a block of BasicScript statements while a condition is True or until a condition is True Do {While | Until} condition statements Loop OR Do statements Loop {While | Until} condition OR Do statements Loop
The Scripting Toolbar Cut Add Watch End Start Paste Procedure Step Calls Toggle Breakpoint Break Undo Copy Single Step
The Script Editor
Debugging Problems are highlighted in gray
Sample Script Sub   PrintPackage ( theModel   As   Model )  Dim   thePackage   As   Category Dim   PackageID   As Integer Dim   allPackages  As  CategoryCollection Set   allPackages   =   theModel.GetAllCategories() For   PackageID   =   1   To   allPackages.Count Set   thePackage   =   allPackages.GetAt  ( PackageID ) Print   thePackage.Name Next   PackageID End Sub Sub   Main Viewport.open PrintPackage RoseApp.CurrentModel End Sub
The Viewport The Viewport window shows output of BasicScripts run from Rose Viewport uses Print script output to the Viewport Print debug output to the Viewport
Viewport Methods Viewport.Clear  Clear the open Viewport window Viewport.Close  Close an open Viewport window Viewport.Open  Opens a new Viewport window or switches the focus to the existing Viewport window
Scripting and Reports Problem:  How do you print out all of the names of all classes in the model?
Print Package and Class Names Script 'The Main statement defines the subroutine where execution begins   Sub  Main  'Open the Viewport window Viewport.open 'Pass the current open model to the  DumpModel  subroutine  DumpModel RoseApp.CurrentModel 'End the subroutine End Sub
Print Package and Class Names Script 'DumpModel subroutine expects a model as an argument  Sub  DumpModel ( theModel  As  Model ) 'Declare local variables AllPackages, thePackage and PackageID Dim  AllPackages  As  CategoryCollection   Dim  thePackage  As  Category Dim  PackageID  As Integer 'Set the package collection to all the packages in the model Set  AllPackages   =   theModel.GetAllCategories ()
Print Package and Class Names Script 'Loop through the packages For  PackageID   =   1  to  AllPackages.Count 'Set the package  Set  thePackage   =   AllPackages.GetAt ( PackageID ) 'Call the DumpPackage subroutine DumpPackage thePackage 'Get the next package Next  PackageID 'End the subroutine End Sub
Print Package and Class Names Script 'DumpPackage subroutine expects a package as an argument   Sub  DumpPackage ( thePackage  As  Category ) 'Declare local variables -- theClass and ClassID  Dim  theClass  As  Class Dim  ClassID  As  Integer 'Prints the name of the package to the Viewport Print  "Package";   thePackage.Name 'Prints the number of classes in the package to the  Viewport Print  "There are ";   thePackage.Classes.Count ; "   classes"
Print Package and Class Names Script 'Loop through the classes in the package For  ClassID  =   1   To  thePackage.Classes.Count 'Set the next class Set  theClass  =  thePackage.Classes.GetAt ( ClassID ) 'Print the name of the class to the Viewport Print  theClass.Name 'Set the next class Next  ClassID 'Print a blank line to the Viewport Print   " " 'End the subroutine End Sub
Scripting and Business Problem Solutions Problem:  How can class names be changed?  Enforce naming conventions Resolve name clashes  Annotate classes to show distribution strategy A script can be written to change the names of all classes in the model to enforce naming conventions
Creating the Script Starting point Browse existing scripts as opposed to creating a new one from scratch Getting help Rose Extensibility How to Start Scripting from Rose Rose Scripting Online Reference Basic Script Reference
Script Steps Declare the prefix to be added to the class name Get the classes from the Model Object Iterate through ClassCollection  Check to see that the prefix is not currently part of the class name If prefix is not present Assign name = prefix + name
Needed Script Functions  Const Name [As type or type] = expression A statement that declares a constant for use within the current script Const prefix$ As String = “Rose98” Set prefix$ to the string “Rose98” Left$ (string, length) A function that returns a string that contains the leftmost NumChars characters contained in the input string Left$(string,1)  Return the leftmost character in string
The Prefix Script '  Definition of the prefix Const   Prefix$   = "Rose98" Sub   Main ' Declare local variables Dim   theClasses   As   ClassCollection Dim  theClass  As  Class ' Set the class collection to all the classes in the  model Set   theClasses   =   RoseApp.CurrentModel.GetAllClasses ()
The Prefix Script ' Loop through the classes For  ClsID  = 1   To  theClasses.Count ' Get the next class Set  theClass  =  theClasses.GetAt (ClsID) ' Get the first n characters of the class where  n is equal to the number of characters in the prefix ClassPrefix$  =  Left$  ( theClass.Name,  Len   ( Prefix$ ))
The Prefix Script ' If the prefix has not been used, add the prefix to the name of the class   If  ClassPrefix$  <>  Prefix$  Then Viewport.Open Print   &quot;Renaming &quot;;theClass.Name;&quot; to &quot;; theClass.Name = Prefix$  +  theClass.Name Print theClass.Name End If ' Get the next class Next  ClsID ' Create a message box with the message = done! MsgBox  &quot;Done!&quot; End Sub
Scripting and Model Updates Problem:  How can packages and classes be added to a model A script can be written to add new packages and classes to the model Steps Create the new package Create the class contained in the new package Add the class to the package
'  This is the main subroutine Sub Main ' Call the CreatePackage subroutine CreatePackage RoseApp.CurrentModel.RootCategory ' Create a message box with the message = done! MsgBox  &quot;Done!&quot; End Sub   Script to Add a Package With One Class
Script to Add a Package With One Class '  This subroutine will create a new package Sub  CreatePackage  ( ParentCategory  As  Category ) ' Declare local variables Dim  thePackage  As  Category ' Prompt the user to enter the name of the new package PackageName$  =  AskBox$  (&quot;Enter the name for a new  package.&quot;, &quot;My New Package&quot;, &quot;Create A Package&quot;) ' Add the package to the logical view package Set  thePackage  =  ParentCategory.AddCategory  ( PackageName$ ) ' Call the CreateAClass subroutine CreateAClass   thePackage   End Sub
Script to Add a Package With One Class '  This subroutine will create a new class Sub  CreateAClass  ( ParentCategory  As  Category ) ' Declare local variables Dim  theClass  As  Class ' Prompt the user to enter the name of the new class ClassName$  =  AskBox$  (&quot;Enter the name for a new class.&quot;_ , &quot;My New Class&quot;, &quot;Create A Class&quot;) ' Add the class to the new package Set  theClass  =  ParentCategory.AddClass  ( ClassName$ ) End Sub
Exercise Open the Registration model Run some of the scripts provided with Rose 98 i Modify the Add a Package With One Class script to create a package with a user defined number of classes Hint:  Use an AskBox to determine the number of classes and the name of the classes

More Related Content

PDF
Code Smells and Its type (With Example)
PPTX
Clean Code
PDF
JavaScript Refactoring
PPTX
Java script basic
PPT
Javascript
PDF
Object Oriented PHP - PART-1
PPT
ODP
Object Oriented Programming With PHP 5 #2
Code Smells and Its type (With Example)
Clean Code
JavaScript Refactoring
Java script basic
Javascript
Object Oriented PHP - PART-1
Object Oriented Programming With PHP 5 #2

What's hot (20)

PDF
Living With Legacy Code
PPTX
Lesson 4 constant
ODP
Clean code and refactoring
PDF
Effective PHP. Part 6
PDF
Perl_Part5
PPTX
Web programming
PDF
Javascript - Tutorial
PPTX
FYBSC IT Web Programming Unit IV PHP and MySQL
PPTX
Java script
PPTX
Java script
PPTX
Java script
DOCX
Java script basics
PDF
8 introduction to_java_script
PPTX
Introduction to java script
PDF
Effective PHP. Part 4
PDF
Introduction to web programming with JavaScript
PDF
Decaf language specification
PDF
Functions in PHP
PPT
Debugging and Error handling
PDF
Building Testable PHP Applications
Living With Legacy Code
Lesson 4 constant
Clean code and refactoring
Effective PHP. Part 6
Perl_Part5
Web programming
Javascript - Tutorial
FYBSC IT Web Programming Unit IV PHP and MySQL
Java script
Java script
Java script
Java script basics
8 introduction to_java_script
Introduction to java script
Effective PHP. Part 4
Introduction to web programming with JavaScript
Decaf language specification
Functions in PHP
Debugging and Error handling
Building Testable PHP Applications
Ad

Viewers also liked (6)

PPTX
Clear case
PDF
PPT
12report
PPT
Clear case
PPTX
ClearCase 8.0
PPT
ClearCase Basics
Clear case
12report
Clear case
ClearCase 8.0
ClearCase Basics
Ad

Similar to 11script (20)

PDF
The Ring programming language version 1.2 book - Part 22 of 84
PDF
Speed geeking-lotusscript
PPT
Intorudction into VBScript
PPT
Classes and objects object oriented programming
PDF
Getting started with CATIA V5 Macros
PPT
rose
PDF
The Ring programming language version 1.8 book - Part 38 of 202
PDF
The Ring programming language version 1.9 book - Part 41 of 210
PDF
Programming Design Guidelines
PDF
The Ring programming language version 1.4 book - Part 9 of 30
PPT
Visual Basic 6.0
PPTX
Vba Class Level 3
PDF
Store Beyond Glorp
PDF
The Ring programming language version 1.5.2 book - Part 32 of 181
PDF
The Ring programming language version 1.5.1 book - Part 29 of 180
PDF
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
PDF
EA User Group London 2018 - Extending EA with custom scripts to cater for spe...
PPT
VB Codes
The Ring programming language version 1.2 book - Part 22 of 84
Speed geeking-lotusscript
Intorudction into VBScript
Classes and objects object oriented programming
Getting started with CATIA V5 Macros
rose
The Ring programming language version 1.8 book - Part 38 of 202
The Ring programming language version 1.9 book - Part 41 of 210
Programming Design Guidelines
The Ring programming language version 1.4 book - Part 9 of 30
Visual Basic 6.0
Vba Class Level 3
Store Beyond Glorp
The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.1 book - Part 29 of 180
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
EA User Group London 2018 - Extending EA with custom scripts to cater for spe...
VB Codes

More from Nguyen Tran (20)

PDF
PPT
10team
PPT
09componentdeployment
PPT
08activity
PPT
07state
PPT
06collaboration
PPT
05sequence
PPT
04class
PPT
03usecase
PPT
02intro
PPT
01about
PPT
Business process excution language
PPT
Vs doc man
PPT
PPT
Sql packager
PPTX
Snag it
PPTX
Record mydesktop
PPT
Rational suite&rational rose enterprise
PPTX
Umodel 2009
PPT
Rational composer method
10team
09componentdeployment
08activity
07state
06collaboration
05sequence
04class
03usecase
02intro
01about
Business process excution language
Vs doc man
Sql packager
Snag it
Record mydesktop
Rational suite&rational rose enterprise
Umodel 2009
Rational composer method

11script

  • 1. Introduction to Rational Rose 98i Module 11: RoseScript
  • 2. Objectives: RoseScript You will be able to: Understand RoseScript concepts Use RoseScript to: Obtain information from a Rose model Add information to a Rose model Update a Rose model Integrate with third-party products
  • 3. What is RoseScript? RoseScript is a full-featured Basic scripting language It is a customized version of Summit Basic Script
  • 4. Uses of RoseScript Get information out of a model Extract all or a portion to export Generate custom reports Perform checks on the model Enforce project/enterprise semantic check Print to a log window Create information to model Add and/or update model components Create and/or update interaction diagrams and/or class diagrams Integrate with third-party tools
  • 5. How are Scripts Executed? Interactive Executed via the Start button on the Scripting Window toolbar Compiled Saved as a file (.ebx) that may be executed Rose menu may be updated to include any compiled script
  • 6. How are RoseScript Classes Used? Each RoseScript class has a defined interface Properties and methods that are used to access information in the Rose model Example Application class property Visible Controls whether the Rose application is visible on the screen Application class method OpenModel Opens a Rose model
  • 7. RoseApp RoseApp is a global application object All RoseScript programs have access to this object Example RoseApp.CurrentModel is the currently open model in Rose It is an instance of the Model class RoseApp.Height is the height of the main window RoseApp.CurrentModel.Save will save the current open model
  • 8. RoseScripts and Color Scripts appear in color Keywords are in blue Comments are in green Code is in red Everything else is black
  • 9. Some “Basic” Terms Add a comment ‘This is a comment Declare a subroutine Sub Name (arglist) Terminate a subroutine End Sub or Exit Sub Declare the main subroutine Main() Declare a local variable along with its type Dim variable As type
  • 10. Some “Basic” Terms Print data to an output device Print Repeat a block of statements for each element in a collection or array For Each member in group [statements] [Exit For] [statements] Next [member]
  • 11. Some “Basic” Terms Repeat a block of BasicScript statements while a condition is True or until a condition is True Do {While | Until} condition statements Loop OR Do statements Loop {While | Until} condition OR Do statements Loop
  • 12. The Scripting Toolbar Cut Add Watch End Start Paste Procedure Step Calls Toggle Breakpoint Break Undo Copy Single Step
  • 14. Debugging Problems are highlighted in gray
  • 15. Sample Script Sub PrintPackage ( theModel As Model ) Dim thePackage As Category Dim PackageID As Integer Dim allPackages As CategoryCollection Set allPackages = theModel.GetAllCategories() For PackageID = 1 To allPackages.Count Set thePackage = allPackages.GetAt ( PackageID ) Print thePackage.Name Next PackageID End Sub Sub Main Viewport.open PrintPackage RoseApp.CurrentModel End Sub
  • 16. The Viewport The Viewport window shows output of BasicScripts run from Rose Viewport uses Print script output to the Viewport Print debug output to the Viewport
  • 17. Viewport Methods Viewport.Clear Clear the open Viewport window Viewport.Close Close an open Viewport window Viewport.Open Opens a new Viewport window or switches the focus to the existing Viewport window
  • 18. Scripting and Reports Problem: How do you print out all of the names of all classes in the model?
  • 19. Print Package and Class Names Script 'The Main statement defines the subroutine where execution begins Sub Main 'Open the Viewport window Viewport.open 'Pass the current open model to the DumpModel subroutine DumpModel RoseApp.CurrentModel 'End the subroutine End Sub
  • 20. Print Package and Class Names Script 'DumpModel subroutine expects a model as an argument Sub DumpModel ( theModel As Model ) 'Declare local variables AllPackages, thePackage and PackageID Dim AllPackages As CategoryCollection Dim thePackage As Category Dim PackageID As Integer 'Set the package collection to all the packages in the model Set AllPackages = theModel.GetAllCategories ()
  • 21. Print Package and Class Names Script 'Loop through the packages For PackageID = 1 to AllPackages.Count 'Set the package Set thePackage = AllPackages.GetAt ( PackageID ) 'Call the DumpPackage subroutine DumpPackage thePackage 'Get the next package Next PackageID 'End the subroutine End Sub
  • 22. Print Package and Class Names Script 'DumpPackage subroutine expects a package as an argument Sub DumpPackage ( thePackage As Category ) 'Declare local variables -- theClass and ClassID Dim theClass As Class Dim ClassID As Integer 'Prints the name of the package to the Viewport Print &quot;Package&quot;; thePackage.Name 'Prints the number of classes in the package to the Viewport Print &quot;There are &quot;; thePackage.Classes.Count ; &quot; classes&quot;
  • 23. Print Package and Class Names Script 'Loop through the classes in the package For ClassID = 1 To thePackage.Classes.Count 'Set the next class Set theClass = thePackage.Classes.GetAt ( ClassID ) 'Print the name of the class to the Viewport Print theClass.Name 'Set the next class Next ClassID 'Print a blank line to the Viewport Print &quot; &quot; 'End the subroutine End Sub
  • 24. Scripting and Business Problem Solutions Problem: How can class names be changed? Enforce naming conventions Resolve name clashes Annotate classes to show distribution strategy A script can be written to change the names of all classes in the model to enforce naming conventions
  • 25. Creating the Script Starting point Browse existing scripts as opposed to creating a new one from scratch Getting help Rose Extensibility How to Start Scripting from Rose Rose Scripting Online Reference Basic Script Reference
  • 26. Script Steps Declare the prefix to be added to the class name Get the classes from the Model Object Iterate through ClassCollection Check to see that the prefix is not currently part of the class name If prefix is not present Assign name = prefix + name
  • 27. Needed Script Functions Const Name [As type or type] = expression A statement that declares a constant for use within the current script Const prefix$ As String = “Rose98” Set prefix$ to the string “Rose98” Left$ (string, length) A function that returns a string that contains the leftmost NumChars characters contained in the input string Left$(string,1) Return the leftmost character in string
  • 28. The Prefix Script ' Definition of the prefix Const Prefix$ = &quot;Rose98&quot; Sub Main ' Declare local variables Dim theClasses As ClassCollection Dim theClass As Class ' Set the class collection to all the classes in the model Set theClasses = RoseApp.CurrentModel.GetAllClasses ()
  • 29. The Prefix Script ' Loop through the classes For ClsID = 1 To theClasses.Count ' Get the next class Set theClass = theClasses.GetAt (ClsID) ' Get the first n characters of the class where n is equal to the number of characters in the prefix ClassPrefix$ = Left$ ( theClass.Name, Len ( Prefix$ ))
  • 30. The Prefix Script ' If the prefix has not been used, add the prefix to the name of the class If ClassPrefix$ <> Prefix$ Then Viewport.Open Print &quot;Renaming &quot;;theClass.Name;&quot; to &quot;; theClass.Name = Prefix$ + theClass.Name Print theClass.Name End If ' Get the next class Next ClsID ' Create a message box with the message = done! MsgBox &quot;Done!&quot; End Sub
  • 31. Scripting and Model Updates Problem: How can packages and classes be added to a model A script can be written to add new packages and classes to the model Steps Create the new package Create the class contained in the new package Add the class to the package
  • 32. ' This is the main subroutine Sub Main ' Call the CreatePackage subroutine CreatePackage RoseApp.CurrentModel.RootCategory ' Create a message box with the message = done! MsgBox &quot;Done!&quot; End Sub Script to Add a Package With One Class
  • 33. Script to Add a Package With One Class ' This subroutine will create a new package Sub CreatePackage ( ParentCategory As Category ) ' Declare local variables Dim thePackage As Category ' Prompt the user to enter the name of the new package PackageName$ = AskBox$ (&quot;Enter the name for a new package.&quot;, &quot;My New Package&quot;, &quot;Create A Package&quot;) ' Add the package to the logical view package Set thePackage = ParentCategory.AddCategory ( PackageName$ ) ' Call the CreateAClass subroutine CreateAClass thePackage End Sub
  • 34. Script to Add a Package With One Class ' This subroutine will create a new class Sub CreateAClass ( ParentCategory As Category ) ' Declare local variables Dim theClass As Class ' Prompt the user to enter the name of the new class ClassName$ = AskBox$ (&quot;Enter the name for a new class.&quot;_ , &quot;My New Class&quot;, &quot;Create A Class&quot;) ' Add the class to the new package Set theClass = ParentCategory.AddClass ( ClassName$ ) End Sub
  • 35. Exercise Open the Registration model Run some of the scripts provided with Rose 98 i Modify the Add a Package With One Class script to create a package with a user defined number of classes Hint: Use an AskBox to determine the number of classes and the name of the classes

Editor's Notes

  • #4: To open an existing script Select the Tools:Open Script menu command. Click to select the name of the script. Click the Open button. To create a new script Select the Tools:New Script menu command.
  • #6: To run a script interactively Create a new script or open an existing script. Click the Start button (green triangle). To save a script in compiled form Create a new script or open an existing script. Select the Debugger:Compile menu command. Enter the name of the compiled script. Click the Save button.
  • #10: Main() is the first procedure to execute no matter where it is located in the script.
  • #20: This script may be found on your Course Exercise Models disk. It is called “Print Packages and Class Names.ebs”.
  • #25: A script can be written to change the names of all classes in the model to enforce naming conventions.
  • #29: This script may be found on your Course Exercise Models disk. It is called “Prefix.ebs”.
  • #33: This script may be found on your Course Exercise Models disk. It is called “Add Package with One Class.ebs”.
  • #36: The solution script may be found on your Course Exercise Models disk. It is called “Add Package with Multiple Classes.ebs”.