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.
!script groovy {
workspace.views.createDefaultViews()
workspace.views.views.each { it.disableAutomaticLayout() }
}
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
}
}
}
!script groovy {
new com.structurizr.graphviz.GraphvizAutomaticLayout().apply(workspace);
}
(this requires Graphviz to be installed locally)