Set all line styles in an Enterprise Architect diagram automatically

With this script you can change set all the lines styles on a diagram at once, to your preferred style per type of connector.

In Enterprise Architect you can choose from no less then 9 different line styles for the connectors.

Line Styles

Unfortunately you can only choose from the first three to be the default line style for new connectors. Additionally you can also specify the default for Generalization to be Tree Style, but that is it.

For me that is not enough. I have my own habits when making UML diagrams. For most connector types I use Orthogonal – Square, but not for dependencies, use case relations and note links. For those I like the Direct style. The last exception are the control flow, state flow and object flows, for which I use Orthogonal – Rounded.

LineStylesDiagram

With this script I can set all the line styles on a diagram to the styles that I like.  All I need to do is right click on a diagram and choose Scripts|Set Line Styles

Set Linestyles menu option

And the script will set all the line styles to the defaults set in the script. If you would like the line styles to be set to your preferences automatically without having to run the script you can use EA-Matic version of this script.

You can set your own preferences in this section of the script

<br />
'*********EDIT BETWEEN HERE*************<br />
' set here the menu name<br />
menuDefaultLines = &quot;&amp;Set default linestyles&quot;</p>
<p>' set here the default style to be used<br />
defaultStyle = lsOrthogonalSquareTree</p>
<p>' set there the style to be used for each type of connector<br />
function determineStyle(connector)<br />
    dim connectorType<br />
    connectorType = connector.Type<br />
    select case connectorType<br />
        case &quot;ControlFlow&quot;, &quot;StateFlow&quot;,&quot;ObjectFlow&quot;,&quot;InformationFlow&quot;<br />
            determineStyle = lsOrthogonalRoundedTree<br />
        case &quot;Generalization&quot;, &quot;Realization&quot;, &quot;Realisation&quot;<br />
            determineStyle = lsTreeVerticalTree<br />
        case &quot;UseCase&quot;, &quot;Dependency&quot;,&quot;NoteLink&quot;<br />
            determineStyle = lsDirectMode<br />
        case else<br />
            determineStyle = defaultStyle<br />
    end select<br />
end function<br />
'************AND HERE****************<br />

Free download

Video

This script has been previously featured in the webinar Introduction to Scripting with Enterprise Architect presented by yours truly.

The script

<br />
option explicit</p>
<p>!INC Local Scripts.EAConstants-VBScript</p>
<p>' Script Name: DefaultLineStyles<br />
' Author: Geert Bellekens<br />
' Purpose: Allows to change the linestyles to their default<br />
' Date: 27/04/2015<br />
'<br />
dim lsDirectMode, lsAutoRouteMode, lsCustomMode, lsTreeVerticalTree, lsTreeHorizontalTree, _<br />
lsLateralHorizontalTree, lsLateralVerticalTree, lsOrthogonalSquareTree, lsOrthogonalRoundedTree</p>
<p>lsDirectMode = &quot;1&quot;<br />
lsAutoRouteMode = &quot;2&quot;<br />
lsCustomMode = &quot;3&quot;<br />
lsTreeVerticalTree = &quot;V&quot;<br />
lsTreeHorizontalTree = &quot;H&quot;<br />
lsLateralHorizontalTree = &quot;LH&quot;<br />
lsLateralVerticalTree = &quot;LC&quot;<br />
lsOrthogonalSquareTree = &quot;OS&quot;<br />
lsOrthogonalRoundedTree = &quot;OR&quot;</p>
<p>dim defaultStyle<br />
dim menuDefaultLines</p>
<p>'*********EDIT BETWEEN HERE*************</p>
<p>' set here the default style to be used<br />
defaultStyle = lsOrthogonalSquareTree</p>
<p>' set there the style to be used for each type of connector<br />
function determineStyle(connector)<br />
	dim connectorType<br />
	connectorType = connector.Type<br />
	select case connectorType<br />
		case &quot;StateFlow&quot;,&quot;ObjectFlow&quot;,&quot;InformationFlow&quot;<br />
			determineStyle = lsOrthogonalRoundedTree<br />
		case &quot;Generalization&quot;, &quot;Realization&quot;, &quot;Realisation&quot;<br />
			determineStyle = lsTreeVerticalTree<br />
		case &quot;UseCase&quot;, &quot;Dependency&quot;,&quot;NoteLink&quot;<br />
			determineStyle = lsDirectMode<br />
		case else<br />
			determineStyle = defaultStyle<br />
	end select<br />
end function<br />
'************AND HERE****************</p>
<p>sub main<br />
		dim diagram<br />
		dim diagramLink<br />
		dim connector<br />
		dim dirty<br />
		dirty = false<br />
		set diagram = Repository.GetCurrentDiagram<br />
		'save the diagram first<br />
		Repository.SaveDiagram diagram.DiagramID<br />
		'then loop all diagramLinks<br />
		if not diagram is nothing then<br />
			for each diagramLink in diagram.DiagramLinks<br />
				set connector = Repository.GetConnectorByID(diagramLink.ConnectorID)<br />
				if not connector is nothing then<br />
					'set the connectorstyle<br />
					setConnectorStyle diagramLink, determineStyle(connector)<br />
					'save the diagramlink<br />
					diagramLink.Update<br />
					dirty = true<br />
				end if<br />
			next<br />
			'reload the diagram if we changed something<br />
			if dirty then<br />
				'reload the diagram to show the link style<br />
				Repository.ReloadDiagram diagram.DiagramID<br />
			end if<br />
		end if<br />
end sub</p>
<p>main</p>
<p>'gets the diagram link object<br />
function getdiagramLinkForConnector(connector, diagram)<br />
	dim diagramLink<br />
	set getdiagramLinkForConnector = nothing<br />
	for each diagramLink in diagram.DiagramLinks<br />
		if diagramLink.ConnectorID = connector.ConnectorID then<br />
			set getdiagramLinkForConnector = diagramLink<br />
			exit for<br />
		end if<br />
	next<br />
end function</p>
<p>'actually sets the connector style<br />
function setConnectorStyle(diagramLink, connectorStyle)<br />
	'split the style into its parts<br />
	dim styleparts<br />
	dim styleString<br />
	styleString = diagramLink.Style<br />
	styleparts = Split(styleString,&quot;;&quot;)<br />
	dim stylePart<br />
	dim mode<br />
	dim modeIndex<br />
	modeIndex = -1<br />
	dim tree<br />
	dim treeIndex<br />
	treeIndex = -1<br />
	mode = &quot;&quot;<br />
	tree = &quot;&quot;<br />
	dim i<br />
	'find if Mode and Tree are already defined<br />
	for i = 0 to Ubound(styleparts) -1<br />
		stylePart = styleparts(i)<br />
		if Instr(stylepart,&quot;Mode=&quot;) &gt; 0 then<br />
			modeIndex = i<br />
		elseif Instr(stylepart,&quot;TREE=&quot;) &gt; 0 then<br />
			treeIndex = i<br />
		end if<br />
	next<br />
	'these connectorstyles use mode=3 and the tree<br />
	if  connectorStyle = lsTreeVerticalTree or _<br />
		connectorStyle = lsTreeHorizontalTree or _<br />
		connectorStyle = lsLateralHorizontalTree or _<br />
		connectorStyle = lsLateralVerticalTree or _<br />
		connectorStyle = lsOrthogonalSquareTree or _<br />
		connectorStyle = lsOrthogonalRoundedTree then<br />
		mode = &quot;3&quot;<br />
		tree = connectorStyle<br />
	else<br />
		mode = connectorStyle<br />
	end if<br />
	'set the mode value<br />
	if modeIndex &gt;= 0 then<br />
		styleparts(modeIndex) = &quot;Mode=&quot; &amp; mode<br />
		diagramLink.Style = join(styleparts,&quot;;&quot;)<br />
	else<br />
		diagramLink.Style = &quot;Mode=&quot; &amp; mode&amp; &quot;;&quot;&amp; diagramLink.Style<br />
	end if<br />
	'set the tree value<br />
	if treeIndex &gt;= 0 then<br />
		if len(tree) &gt; 0 then<br />
			styleparts(treeIndex) = &quot;TREE=&quot; &amp; tree<br />
			diagramLink.Style = join(styleparts,&quot;;&quot;)<br />
		else<br />
			'remove tree part<br />
			diagramLink.Style = replace(diagramLink.Style,styleparts(treeIndex)&amp;&quot;;&quot; , &quot;&quot;)<br />
		end if<br />
	else<br />
		diagramLink.Style = diagramLink.Style &amp; &quot;TREE=&quot; &amp; tree &amp; &quot;;&quot;<br />
	end if<br />
end function</p>
<p>function getConnectorStyle(diagramLink)<br />
	'split the style<br />
	dim styleparts<br />
	styleparts = Split(diagramLink.Style,&quot;;&quot;)<br />
	dim stylePart<br />
	dim mode<br />
	dim tree<br />
	mode = &quot;&quot;<br />
	tree = &quot;&quot;<br />
	for each stylepart in styleparts<br />
		if Instr(stylepart,&quot;Mode=&quot;) &gt; 0 then<br />
			mode = right(stylepart, 1)<br />
		elseif Instr(stylepart,&quot;TREE=&quot;) &gt; 0 then<br />
			tree = replace(stylepart, &quot;TREE=&quot;, &quot;&quot;)<br />
		end if<br />
	next<br />
	if tree &lt;&gt; &quot;&quot; then<br />
		getConnectorStyle = tree<br />
	else<br />
		getConnectorStyle = mode<br />
	end if<br />
end function<br />

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.