Skip to content

Latest commit

 

History

History
 
 

scripts

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Scripts

The !script keyword provides a way to run scripts written in Groovy, Kotlin, Ruby, and JavaScript. This gives you access to the underlying Structurizr for Java workspace object via a variable named workspace, for when you need to do something not supported by the DSL. Here are some useful scripts.

Create the default views, without automatic layout

!script groovy {
    workspace.views.createDefaultViews()
    workspace.views.views.each { it.disableAutomaticLayout() }
}

Programmatically add elements to a view

workspace {

    model {
        group "Group 1" {
            a = softwareSystem "A" {
                tags "Tag 1"
            }
            b = softwareSystem "B" {
                tags "Tag 2"
            }
        }
        group "Group 2" {
            c = softwareSystem "C" {
                tags "Tag 1"
            }
            d = softwareSystem "D" {
                tags "Tag 2"
            }
        }
    }

    views {
        systemLandscape "key" {
            !script groovy {
                view = workspace.views.getViewWithKey("key");
                workspace.model.softwareSystems.findAll { it.group == "Group 1" && it.hasTag("Tag 1") }.each{ view.add(it); };
            }

            autolayout
        }
    }

}

Run Graphviz locally

!script groovy {
    new com.structurizr.graphviz.GraphvizAutomaticLayout().apply(workspace);
}

(this requires Graphviz to be installed locally)

Links