Main Menu
SSL SecureMode
Lost Password?
Register now!
ChangeVision Members Map
Forum Index   -   Topic Index
   How to use of Astah (Pro/SysML/GSN/Com)
     rapidly create operations/attributes part2

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
Posted on: 2012/10/15 15:46
Just popping in
Joined: 2012/9/4
Posts: 15
rapidly create operations/attributes part2
As a preface, I am using Astah to model Perl software built with the Moose object system. Perl has no programmatic-ally enforced encapsulation, and Moose attributes can automatically create getters and setters depending on setting read-only, read-write, or bare (none).

I notice that Astah has the ability to create getter/setter from an attribute, this seems neat, but I have the problem that it uses Java-esque naming conventions. Perl's naming conventions are completely different. Generally with moose I leave my getter/setter to have the same name as the attribute. Can I change the template Astah uses to create these names? Even better can I set it so that when I create an attribute it automatically creates an appropriately named getter?
Posted on: 2012/10/16 15:58
Joined: 2006/6/6
Posts: 969
Re: rapidly create operations/attributes part2
Hi, thank you for your additional post.

Unfortunately there is no way to customize to do so, but I'd suggest you to use "Script Plug-in" which is the easiest way to access Astah via scripting languages. For details and download, please visit Astah Script Plug-in page. We've created java script for you, so here's the step to use.

1. Install Astah Script Plug-in
2. In the structure tree (Top left pane of Astah) select Attributes you want to change the setter/getter names of
3. Go to [Tool] - [Script], copy and paste the java script below (Customize the scripts in red below) and run it



function run() {
     var attributes = getSelectedAttributesInProjectView();
     if (attributes.length === 0) {
         println('Please select attributes you want to add setter/getter in StructureTree');
     for (var i in attributes) {

function getSelectedAttributesInProjectView() {
     var attributes = [];
     var projectViewManager = astah.getViewManager().getProjectViewManager();
     var selectedEntities = projectViewManager.getSelectedEntities();
     for (var i in selectedEntities) {
         var entity = selectedEntities[i];
         if (entity instanceof IAttribute) {
             println('HIT: ' + entity.getName());
     return attributes;

function addSetterGetter(attribute) {
     createSetter(attribute.getOwner(), attribute);
     createGetter(attribute.getOwner(), attribute);

function createSetter(iClass, iAtt) {
     var bme = astah.getModelEditorFactory().getBasicModelEditor();
     var name =  convertToSetterName(iAtt.getName());
     println('createSetter: ' + name);
     var iOperation = bme.createOperation(iClass, name, 'void');
     bme.createParameter(iOperation, "parameter1", iAtt.getType());

function convertToSetterName(attName) {
     //do something
     return "set_"+ attName;

function createGetter(iClass, iAtt) {
     var bme = astah.getModelEditorFactory().getBasicModelEditor();
     bme.createOperation(iClass, convertToGetterName(iAtt.getName()), iAtt.getType().getName());

function convertToGetterName(attName) {
     //do something
     return "get_"+ attName;

Hope this helps. If you have any further questions, let us know.

Threaded | Newest First Previous Topic | Next Topic | Top