Home / Model Expert Homepage / Model Expert Help / Validation rules / Validating Diagrams
Import an MDG to create a Reference Model
Importing and exporting Reference Models
Editing RM Connector type properties
Stereotypes inheriting from other Element Types
Customizing Reference Model Properties
Customizing Reference Model Element Properties
Validating Diagrams
There is a setting on each diagram type in a Reference Model which says whether scripted rules should be run on examples of this diagram type.
This will run the rules as described in Writing Scripted Rules, on each of the elements in the diagram in turn.
But you can also write scripts to validate the whole diagram.
Scripts for Validating diagrams
These have a slightly different format from element-validating scripts.
Choosing scope for a script
Diagram scripts can run:
Scope | Comment to add to your script |
---|---|
For all diagrams in all reference models | ‘<refModel>All</refModel>
‘<diagram>All</diagram> |
For all diagrams in a specified reference model | ‘<refModel>(RefModel packge GUID)</refModel>
‘<diagram>All</diagram> |
For one diagram type in one reference model | ‘<refModel>(RefModel packge GUID)</refModel>
‘<diagram>(Diagram type guid)</diagram> |
The GUID to scope to a single Reference Model is the GUID of the package (in the package/project properties)
The GUID to scope to a specific diagram type is the GUID of the <<diagram>> element
Script contents
Unlike element scripts, diagram scripts are passed a single parameter DiagramID.
So your code should contain something like:
dim d as EA.Diagram
set d = Repository.GetDiagramByID(DiagramID.toString)
You can now create rules just as with element scripts. For example:
if d.Notes = “” then
outputHTML = outputHTML & “<violation note=’There are no diagram notes for this diagram.’ severity=’4′ />”
end if
Example diagram scripts
These are some diagram scripts. Please note, where there are GUIDs in the comments, you must replace these with GUIDs from your own reference models for them to work.
Script | Description |
---|---|
!INC Local Scripts.EAConstants–VBScript
‘ ‘ Script Name: Diagram_Details ‘ Author: Ian Mitchell ‘ Purpose: Checks the details of a single diagram from one of the test cases ‘ ‘Date: 28th October 2019 function Diagram_Details
‘************* Required so that eaDocX knows which ref model & diagram type this is used for ‘<refModel>All</refModel> ‘<diagram>All</diagram> ‘****************
dim d as EA.Diagram
‘Use this when testing this script ‘=================================== ‘replace the ‘find the diagram’ section below with this:
‘in case you want to output debug information to the script console ‘Repository.EnsureOutputVisible “Script”
”Add the GUID of an element you would like to test with ‘set d = Repository.GetDiagramByGUID(“{67139C78-E236-4754-8E29-5269BE2CD2DC}”)
‘=====================================
‘ Parameters which are passed to the script are: ‘ DiagramID – long – ID of the diagram to be validated ‘find the element set d = Repository.GetDiagramByID(DiagramID.toString)
‘now do the checks
dim outputHTML ‘ a string which will contain the results from the script outputHTML = “<results>”
if not d is nothing then
if d.Notes = “” then outputHTML = outputHTML & “<violation note=’There are no diagram notes for this diagram.’ severity=’4′ />” end if ‘add other checks here
end if
outputHTML = outputHTML & “</results>”
‘put the HTML string into the return Diagram_Details = outputHTML end function Diagram_Details |
Just checks that there are some diagram notes.
Scoped to work for all diagram types in all reference models |
!INC Local Scripts.EAConstants–VBScript
‘ ‘ Script Name: Requirements_Diagram ‘ Author: Ian Mitchell ‘ Purpose: Checks the details of a single diagram from one of the test cases ‘ ‘Date: 28th October 2019 ‘ function Requirements_Diagram
‘************* Required so that eaDocX knows which ref model & diagram type this is used for ‘<refModel>{6F629E4F-88B1-44ff-97C4-8FA1FF1655E9}</refModel> ‘<diagram>{BCA10D05-3DF8-4439-B2A3-2D579E056052}</diagram> ‘****************
dim d as EA.Diagram
‘Use this when testing this script ‘=================================== ‘replace the ‘find the diagram’ section below with this:
‘in case you want to output debug information to the script console ‘Repository.EnsureOutputVisible “Script”
”Add the GUID of an element you would like to test with ‘set d = Repository.GetDiagramByGUID(“{67139C78-E236-4754-8E29-5269BE2CD2DC}”)
‘=====================================
‘ Parameters which are passed to the script are: ‘ DiagramID – long – ID of the diagram to be validated ‘find the element set d = Repository.GetDiagramByID(DiagramID.toString)
‘now do the checks
dim outputHTML ‘ a string which will contain the results from the script outputHTML = “<results>”
if not d is nothing then
if d.diagramObjects.count > 50 then outputHTML = outputHTML & “<violation note=’There are too many elements in this diagram. Max is 50 and yo have ” & d.DiagramObjects.count & “! severity=’4′ />” end if
end if
outputHTML = outputHTML & “</results>”
‘put the HTML string into the return Requirements_Diagram = outputHTML end function Requirements_Diagram |
Does a complexity check, but only for one type of diagram in one reference model. |